Skip to content

CMake: Find Dispatch module #79455

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

Conversation

etcwilde
Copy link
Member

Adding a Finddispatch.cmake module to find libdispatch, both on Apple platforms and from corelibs-libdispatch.
This gets concurrency building on Apple platforms, picking up Dispatch from the SDK.
When building for Windows and Linux, this module imports the library from the pre-existing SDK, making it possible to build Swift Concurrency without having to build dispatch if an existing copy is available.
If desired, one can set dispatch_DIR to point at the directory containing dispatchConfig.cmake in order to pull in a new build, or set CMAKE_FIND_PACKAGE_PREFER_CONFIG to ignore the module entirely and search for an installed config file.

When building for Apple-platforms, the module will only look for the libdispatch from the SDK.
When building for Linux, the module considers two variables:

  • swift_SDKROOT:FILEPATH: Path to the installed Swift SDK. The SDK and toolchain are currently shipped as one package, so this is likely just pointing at the root of the downloaded tarball.
  • dispatch_STATIC:BOOLEAN: Hint the module to find the static archive for libdispatch instead of the dynamic library.

@etcwilde
Copy link
Member Author

@compnerd, can I have you check that the filepaths work on Windows? I wasn't sure quite how to interpret the location from the xml files of the installer.

@etcwilde etcwilde force-pushed the ewilde/stdlib-rebuild-macos-concurrency branch from f7d953b to df64a1c Compare February 24, 2025 23:29
dispatch_LIBRARY dispatch_INCLUDE_DIR)
elseif(WIN32)
# Issue: https://github.com/swiftlang/swift/issues/79591
message(FATAL_ERROR "79591: Finddispatch.cmake module not implemented for Windows yet")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@compnerd, I'm not sure how to implement this. I can't quite make sense of where the SDK dll's live to create the imported target library. I created #79591 to track fixing this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I think that should do it. Only have the implib and headers on Windows, sort of like the Apple SDKs.

@etcwilde
Copy link
Member Author

@swift-ci please smoke test

Implementing an initial `Finddispatch.cmake` module to find Dispatch
from the system SDK on Apple platforms. Still should implement a basic
mechanism for finding it on Windows and Linux. Note that those platforms
will likely use the dispatch config mechanism most frequently, but this
should still work as a fallback.

This mechanism is the only one that works for Apple platforms though as
those use libdispatch from the SDK rather than building it with
corelibs-libdispatch.

When building for Linux and Windows, it is possible to build a custom
corelibs-libdispatch runtime with `dispatch_DIR` and avoid this module.
This module makes it possible to use a pre-built corelibs-libdispatch
when one is available without needing to build it. The module uses
the `Swift_SDKROOT` filepath as a hint on where to look for the runtime
libraries and the `dispatch_STATIC` boolean to specify whether it should
find the dynamic library or the static archive.
We need to define the defaulted setting so that it pulls in the default
value. Otherwise we hit a configuration failure in
`Concurrency/CMakeLists.txt` when it includes the config file specific
to the global executor because `SwiftCore_CONCURRENCY_GLOBAL_EXECUTOR`
is an empty string.
Enabling building the concurrency runtimes for build-testing purposes.
The dispatch global executor depends on finding dispatch. If dispatch is
not found, it will fail to build. Mark it as required to get a
configuration failure early.
@etcwilde etcwilde force-pushed the ewilde/stdlib-rebuild-macos-concurrency branch from df64a1c to a0682cb Compare February 25, 2025 00:31
@etcwilde
Copy link
Member Author

@swift-ci please smoke test

@etcwilde
Copy link
Member Author

@swift-ci please smoke test Linux

@etcwilde etcwilde merged commit 2ea75b0 into swiftlang:main Feb 25, 2025
3 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