-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[cmake] add FindSwiftCore module for supplemental libraries #81215
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
Conversation
085630a
to
6b5befc
Compare
@swift-ci please smoke test |
``SDKROOT`` | ||
Set the path to the Swift SDK Root. | ||
This only affects MacOS builds. |
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.
This description seems stale now -- this seems to be now an environment variable sensed when building on Windows
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.
The SDKROOT
env var gets set up by the Windows toolchain installation. It's less of a hint and more meant as a fallback to avoid requiring the variable be set when building for Windows. If it's important, it should likely be set via the Swift_SDKROOT
variable directly.
find_package_handle_standard_args(SwiftCore DEFAULT_MSG | ||
SwiftCore_LIBRARY SwiftCore_INCLUDE_DIR) | ||
elseif(WIN32) | ||
set(SwiftCore_INCLUDE_DIR "${Swift_SDKROOT}/usr/lib/swift_static/linux-static/Swift.swiftmodule" CACHE STRING "") |
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.
This seems like a left over from iterating on the code -- if I interpret this comment correctly, the line below should be enough
set(SwiftCore_INCLUDE_DIR "${Swift_SDKROOT}/usr/lib/swift_static/linux-static/Swift.swiftmodule" CACHE STRING "") |
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.
Yeah, let's use find_path
to search for the appropriate Swift.swiftmoule
. We should prefer to search via Swift_SDKROOT
, but then can fall back on $ENV{SDKROOT}
. If we're building for Windows, we shouldn't be trying to find the swiftmodule from the linux-static SDK.
``SDKROOT`` | ||
Set the path to the Swift SDK Root. | ||
This only affects MacOS builds. |
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.
The SDKROOT
env var gets set up by the Windows toolchain installation. It's less of a hint and more meant as a fallback to avoid requiring the variable be set when building for Windows. If it's important, it should likely be set via the Swift_SDKROOT
variable directly.
Set the path to the Swift SDK Root. | ||
This only affects MacOS builds. | ||
|
||
``swift_SDKROOT`` |
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.
The variable below uses a capital S on "Swift".
``swift_SDKROOT`` | |
``Swift_SDKROOT`` |
|
||
``SwiftCore_LIBRARIES`` OR ``SwiftCore_IMPLIB`` | ||
the libraries to be linked | ||
|
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.
SwiftCore_INCLUDE_DIR
is also set.
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.
This can also be a property on the imported library target.
find_package_handle_standard_args(SwiftCore DEFAULT_MSG | ||
SwiftCore_LIBRARY SwiftCore_INCLUDE_DIR) | ||
elseif(WIN32) | ||
set(SwiftCore_INCLUDE_DIR "${Swift_SDKROOT}/usr/lib/swift_static/linux-static/Swift.swiftmodule" CACHE STRING "") |
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.
Yeah, let's use find_path
to search for the appropriate Swift.swiftmoule
. We should prefer to search via Swift_SDKROOT
, but then can fall back on $ENV{SDKROOT}
. If we're building for Windows, we shouldn't be trying to find the swiftmodule from the linux-static SDK.
Addresses rdar://150396923
6b5befc
to
c874044
Compare
@swift-ci please smoke test |
``SwiftCore_FOUND`` | ||
true if core was found | ||
|
||
``SwiftCore_LIBRARIES`` OR ``SwiftCore_IMPLIB`` |
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 don't think that we should be doing these variables. Instead we should create a SwiftCore
target that is an imported library (static or shared). On Windows, we can associate an IMPORTED_IMPLIB
property on the shared library target. This description does seem to match what we are doing below.
|
||
``SwiftCore_LIBRARIES`` OR ``SwiftCore_IMPLIB`` | ||
the libraries to be linked | ||
|
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.
This can also be a property on the imported library target.
find_package_handle_standard_args(SwiftCore DEFAULT_MSG | ||
SwiftCore_IMPLIB SwiftCore_INCLUDE_DIR) | ||
elseif(LINUX) | ||
if(SwiftCore_STATIC) |
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 detect static or dynamic by any chance?
@swift-ci please smoke test |
Hint Variables | ||
^^^^^^^^^^^^^^ | ||
|
||
``SDKROOT`` |
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.
Optional: we may want to state this is not a CMake variable
``SDKROOT`` | |
``SDKROOT`` (environment variable) |
"${CMAKE_OSX_SYSROOT}/usr/lib/swift") | ||
add_library(SwiftCore SHARED IMPORTED GLOBAL) | ||
set_target_properties(SwiftCore PROPERTIES | ||
IMPORTED_IMPLIB "${SwiftCore_IMPLIB}") |
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 believe this target needs to have the path to the swiftmodules as well like its siblings:
IMPORTED_IMPLIB "${SwiftCore_IMPLIB}") | |
IMPORTED_IMPLIB "${SwiftCore_IMPLIB}" | |
INTERFACE_INCLUDE_DIRECTORIES "${SwiftCore_INCLUDE_DIR}") |
@swift-ci please smoke test |
Add FindSwiftCore to Supplemental cmake modules so we can link against libswiftCore in a given end users SDK if `SwiftCore_DIR ` is not provided
Addresses rdar://150300769 Add Synchronization library to new build system Land #81215 first
NAMES "libswiftCore.tbd" | ||
HINTS | ||
"${CMAKE_OSX_SYSROOT}/usr/lib/swift") | ||
add_library(SwiftCore SHARED IMPORTED GLOBAL) |
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.
When experimenting at desk I noticed that the case of the target does not match with the one we use in the build system
swift/Runtimes/Core/core/CMakeLists.txt
Lines 29 to 31 in 6534b9b
add_library(swiftCore | |
Algorithm.swift | |
ArrayBody.swift |
swift/Runtimes/Supplemental/Synchronization/CMakeLists.txt
Lines 97 to 99 in 6534b9b
target_link_libraries(swiftSynchronization PRIVATE | |
swiftCore | |
$<$<PLATFORM_ID:Darwin>:swiftDarwin>) |
meaning we are relying on search paths known to the compiler to find this library, instead of CMake providing the explicit path to the tbd/so/lib file
add_library(SwiftCore SHARED IMPORTED GLOBAL) | |
add_library(swiftCore SHARED IMPORTED GLOBAL) |
…wiftlang#81215)" This reverts commit 758ae18.
Add FindSwiftCore to Supplemental cmake modules so we can link against libswiftCore in a given end users SDK if
SwiftCore_DIR
is not provided