Skip to content

[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

Merged
merged 1 commit into from
Jun 26, 2025

Conversation

edymtt
Copy link
Contributor

@edymtt edymtt commented Jun 5, 2025

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

Copy link
Member

@compnerd compnerd left a 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"
Copy link
Member

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)
Copy link
Member

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.

Copy link
Contributor Author

@edymtt edymtt Jun 10, 2025

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

Copy link
Contributor Author

@edymtt edymtt Jun 11, 2025

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)
Copy link
Member

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.

Copy link
Contributor Author

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.

@edymtt
Copy link
Contributor Author

edymtt commented Jun 11, 2025

@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)
Copy link
Contributor Author

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

Suggested change
#list(APPEND SwiftCore_NAMES libswiftCore.tbd)
list(APPEND SwiftCore_NAMES libswiftCore.tbd)

@edymtt edymtt force-pushed the edymtt/refactor-findswiftcore branch from 89b7929 to 13db77a Compare June 17, 2025 20:35
...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
@edymtt edymtt force-pushed the edymtt/refactor-findswiftcore branch from 13db77a to 4efbe16 Compare June 17, 2025 22:40
@edymtt
Copy link
Contributor Author

edymtt commented Jun 17, 2025

@swift-ci please test

@edymtt
Copy link
Contributor Author

edymtt commented Jun 17, 2025

@swift-ci please build toolchain

@edymtt
Copy link
Contributor Author

edymtt commented Jun 18, 2025

macOS failed is unrelated to this change and happening in other PRs

20:53:19  ********************
20:53:19  Failed Tests (1):
20:53:19    Swift(iphonesimulator-x86_64) :: Sema/enum_raw_representable_object_literals.swift

Similar situation for Windows

× Test debugDescription() recorded an issue at PredicateTests.swift:361:9: Expectation failed: (predicate.description → "capture1 (Swift.Int): 3
× Test debugDescription() recorded an issue at PredicateTests.swift:376:9: Expectation failed: (debugDescription → "FoundationEssentials.Predicate<Pack{FoundationEssentialsTests.(unknown context at $7ff6d3ccd978).PredicateTests.Object ...

@edymtt
Copy link
Contributor Author

edymtt commented Jun 18, 2025

@swift-ci please test Windows

@edymtt
Copy link
Contributor Author

edymtt commented Jun 18, 2025

@swift-ci please build toolchain Windows

@edymtt
Copy link
Contributor Author

edymtt commented Jun 23, 2025

@swift-ci please test macOS

@edymtt
Copy link
Contributor Author

edymtt commented Jun 23, 2025

@swift-ci please test Windows

@edymtt
Copy link
Contributor Author

edymtt commented Jun 23, 2025

@swift-ci please test macOS

@edymtt
Copy link
Contributor Author

edymtt commented Jun 23, 2025

@swift-ci please test Windows

@edymtt edymtt marked this pull request as ready for review June 23, 2025 14:02
@edymtt
Copy link
Contributor Author

edymtt commented Jun 26, 2025

Merging to unblock the addition of Distributed to the new runtime builds -- I will address any additional feedback in subsequent PR that change FindSwiftCore.cmake (very likely #81982)

@edymtt edymtt merged commit 4686897 into swiftlang:main Jun 26, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants