-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Runtimes][CMake] Refactor FindSwiftCore to put focus on targets... #82035
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
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 that this is going in the right direction.
${SwiftCore_INCLUDE_DIR_HINTS}) | ||
find_library(SwiftCore_LIBRARY | ||
NAMES | ||
"libswiftCore.tbd" |
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 we want to keep searching for a static archive separate from searching for a shared object. CMake will happily annotate the imported swiftCore
incorrectly down below on lines 123 - 127, but I don't think the user will be as happy.
"${Swift_SDKROOT}/usr/lib/swift/linux") | ||
list(APPEND SwiftCore_LIBRARY_HINTS | ||
"${Swift_SDKROOT}/usr/lib/swift/linux") | ||
list(APPEND SwiftCore_NAMES libswiftCore.so) |
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 that folding the cases with generator expressions would be reasonable.
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 would need to double check if I can use generator expressions in this context -- my understanding is that we can employ those when setting properties on targets
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 cobbled up a small example that uses a generator expression to provide the file name to find_library
, but that does lead to the library not being found.
Do you have any link to documentation or forums that shows how to use generator expressions in this context? From a quick search, the official CMake Documentation only mentions they can be used in target properties and file(GENERATE)
Example CMake and configuration/generation output
cmake_minimum_required(VERSION 3.29)
project(Foo LANGUAGES Swift)
find_path(SwiftCore_INCLUDE_DIR
"Swift.swiftmodule"
NO_CMAKE_FIND_ROOT_PATH
HINTS
"${CMAKE_OSX_SYSROOT}/usr/lib/swift")
find_library(SwiftCore_LIBRARY
NAMES
$<<PLATFORM_ID:Darwin>,libswiftCore.tbd,libswiftCore.so>
NO_CMAKE_FIND_ROOT_PATH
HINTS
"${CMAKE_OSX_SYSROOT}/usr/lib/swift")
MESSAGE(STATUS "Library path for SwiftCore: ${SwiftCore_LIBRARY}")
add_library(swiftCore SHARED IMPORTED GLOBAL)
set_target_properties(swiftCore PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${SwiftCore_INCLUDE_DIR}")
set_target_properties(swiftCore PROPERTIES
IMPORTED_IMPLIB "${SwiftCore_LIBRARY}")
add_library(Foo foo.swift)
target_link_libraries(Foo PRIVATE swiftCore)
...
-- Library path for SwiftCore: SwiftCore_LIBRARY-NOTFOUND
-- Configuring done (0.8s)
-- Generating done (0.0s)
-- Build files have been written to: .../generator_expressions_with_find_library_sandbox/build_dynamic
ninja: Entering directory `build_dynamic'
ninja: error: 'SwiftCore_LIBRARY-NOTFOUND', needed by 'libFoo.dylib', missing and no known rule to make it
"${Swift_SDKROOT}/usr/lib/swift" | ||
"$ENV{SDKROOT}/usr/lib/swift/${SwiftCore_PLATFORM_SUBDIR}/${SwiftCore_ARCH_SUBDIR}" | ||
"$ENV{SDKROOT}/usr/lib/swift") | ||
list(APPEND SwiftCore_NAMES libswiftCore.lib) |
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 is the static library name, swiftCore.lib
is the import library. Please add the static case as well.
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.
Amended in 89b7929 -- please note I did not touch the search paths, as I don't remember seeing any swift_static
in my Swift installation for Windows.
@swift-ci please test Windows |
INTERFACE_INCLUDE_DIRECTORIES "${SwiftCore_INCLUDE_DIR}") | ||
find_package_handle_standard_args(SwiftCore DEFAULT_MSG | ||
SwiftCore_IMPLIB SwiftCore_INCLUDE_DIR) | ||
#list(APPEND SwiftCore_NAMES libswiftCore.tbd) |
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.
Left this commented while I was experimenting with generator expressions
#list(APPEND SwiftCore_NAMES libswiftCore.tbd) | |
list(APPEND SwiftCore_NAMES libswiftCore.tbd) |
89b7929
to
13db77a
Compare
...instead of platforms. Notable changes/flags: * Append to variables controlling paths and names, to allow for user configuration * add `SwiftCore_USE_STATIC_LIBS` to generate static archives * use PlatformInfo variables to get the platform and arch subfolders (where appropriate) * add include guards to ensure PlatformInfo and FindSwiftCore are included once in a project * search for the appropriate static or import library under Windows Addresses rdar://152838903
13db77a
to
4efbe16
Compare
@swift-ci please test |
@swift-ci please build toolchain |
macOS failed is unrelated to this change and happening in other PRs
Similar situation for Windows
|
@swift-ci please test Windows |
@swift-ci please build toolchain Windows |
@swift-ci please test macOS |
@swift-ci please test Windows |
@swift-ci please test macOS |
@swift-ci please test Windows |
Merging to unblock the addition of Distributed to the new runtime builds -- I will address any additional feedback in subsequent PR that change |
Notable changes/flags:
configuration
SwiftCore_USE_STATIC_LIBS
to generate static archives(where appropriate)
included once in a project
Addresses rdar://152838903