-
Notifications
You must be signed in to change notification settings - Fork 80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[CMake] Explicitly link Testing to Foundation #693
Conversation
Sources/Testing/CMakeLists.txt
Outdated
@@ -96,6 +96,8 @@ add_library(Testing | |||
Traits/Trait.swift) | |||
target_link_libraries(Testing PRIVATE | |||
_TestingInternals) | |||
target_link_libraries(Testing PUBLIC |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this fail if for some reason we can't find Foundation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it should fail with linker errors.
8072ea4
to
8aa2643
Compare
CMakeLists.txt
Outdated
@@ -15,6 +15,11 @@ endif() | |||
project(SwiftTesting | |||
LANGUAGES CXX Swift) | |||
|
|||
if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin) | |
if(NOT APPLE) |
Sources/Testing/CMakeLists.txt
Outdated
@@ -96,6 +96,11 @@ add_library(Testing | |||
Traits/Trait.swift) | |||
target_link_libraries(Testing PRIVATE | |||
_TestingInternals) | |||
if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin) | |
if(NOT APPLE) |
CMakeLists.txt
Outdated
@@ -15,6 +15,11 @@ endif() | |||
project(SwiftTesting | |||
LANGUAGES CXX Swift) | |||
|
|||
if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin) | |||
find_package(dispatch) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we go this route instead of using the build-directory configurations, we'll need to include a Finddispatch.cmake
and FindFoundation.cmake
in our modules directory and move these down below the list(APPEND CMAKE_MODUKE_PATH ...
on line 25.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think find_package()
tries Module mode first then falls backs to Config mode IIUC.
When the basic signature is used, the command searches in Module mode first. If the package is not found, the search falls back to Config mode.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, but I think we still would want the Find<PackageName>.cmake
modules or I don't really see much point in not just using the CONFIG
form.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's just use CONFIG
then.
8aa2643
to
79a443a
Compare
Sources/Testing/CMakeLists.txt
Outdated
@@ -96,6 +96,11 @@ add_library(Testing | |||
Traits/Trait.swift) | |||
target_link_libraries(Testing PRIVATE | |||
_TestingInternals) | |||
if(NOT APPLE) | |||
target_link_libraries(Testing PUBLIC | |||
dispatch |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we optionalize this dispatch
link as WASI doesn't support libdispatch? You can ensure the change doesn't break WASI build by @swift-ci test WebAssembly
in cross repo testing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What would be the condition? if(NOT WASI)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be if(NOT CMAKE_SYSTEM_NAME STREQUAL WASI)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Since WASI
is equivalent to CMAKE_SYSTEM_NAME STREQUAL WASI
, I went with WASI
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WASI
is available only in the bleeding edge CMakes (https://gitlab.kitware.com/cmake/cmake/-/merge_requests/9659), so can we stick on CMAKE_SYSTEM_NAME STREQUAL WASI
for now?
WASI doesn't support `libdispatch`
fa43fb6
to
c2f8ccc
Compare
@@ -96,6 +96,14 @@ add_library(Testing | |||
Traits/Trait.swift) | |||
target_link_libraries(Testing PRIVATE | |||
_TestingInternals) | |||
if(NOT APPLE) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Curious why we need the if(NOT APPLE)
guard for these target_link_libraries
? I get why it's needed for find_package
, but don't we want to link Foundation even on Darwin?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In Darwin, Foundation is a framework, so -lFoundation
doesn't work.
Yes it links Foundation, but that's done via auto-linking. I.e. import Foundation
automatically sets required linker flags.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had one question but LGTM regardless
Cherry-pick #693 into `release/6.0` * **Explanation**: Previously in CMake builds, when `Foundation` was not in the regular search directory (e.g. resource directory or SDK search paths) `#if canImport(Foundation)` used to fail, and the functionalities are not included. This patch provides a way to provide `Foundation_DIR` for `find_packgage(Foundation CONFIG)`, so that clients can correctly link Testing to Foundation * **Scope**: CMake builds * **Risk**: Low. No actual code changes. * **Testing**: Passes current test suite Also manually tested the build toolchain * **Issues**: N/A * **Reviewer**: @stmontgomery
Cherry-pick #693 into `release/6.0.2` * **Explanation**: Previously in CMake builds, when `Foundation` was not in the regular search directory (e.g. resource directory or SDK search paths) `#if canImport(Foundation)` used to fail, and the functionalities are not included. This patch provides a way to provide `Foundation_DIR` for `find_packgage(Foundation CONFIG)`, so that clients can correctly link Testing to Foundation * **Scope**: CMake builds * **Risk**: Low. No actual code changes. * **Testing**: Passes current test suite Also manually tested the build toolchain * **Issues**: N/A * **Reviewer**: @stmontgomery --------- Co-authored-by: Jonathan Grynspan <jgrynspan@apple.com>
Explicitly link to
Foundation
in CMake buildsIf
Foundation_DIR
is passed,find_package
finds theFoundation
target andtarget_link_libraries
adds required-I
and-l
/-L
. If not,find_package
fails andtarget_link_libraries
just assumes it's a system library name and just adds-lFoundation
.