-
Notifications
You must be signed in to change notification settings - Fork 469
dispatch: split DISPATCH_EXPORT
and prepare for static linking
#872
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
Open
compnerd
wants to merge
2
commits into
swiftlang:main
Choose a base branch
from
compnerd:static
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+24
−16
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@swift-ci please test |
@swift-ci please test |
This extracts a new `DISPATCH_EXTERN` macro from the existing definition of `DISPATCH_EXPORT`. This follows the standard style of many of Darwin's frameworks. Extracting and re-using this macro allows us to make the definition of `DISPATCH_EXPORT` more concise.
@swift-ci please test |
@swift-ci please test Windows platform |
etcwilde
reviewed
May 14, 2025
@swift-ci please test |
1 similar comment
@swift-ci please test |
When building with CMake, `dispatch_EXPORT` is automatically defined when building a shared library. We should additionally rely on `dispatch_STATIC` to indicate that we are building a static library. When building statically, we should ensure that the ABI of dispatch does not participate in dynamic linking as otherwise any consuming library would vend the dispatch ABI. Particularly for Linux, this would be problematic as the symbol resolution is ill-defined and can end up with multiple incompatible definitions. Co-authored-by: Evan Wilde <etceterawilde@gmail.com>
@swift-ci please test |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This change accomplishes two items:
DISPATCH_EXTERN
macro to decorate withextern
orextern "C"
based on the compilation mode (C vs C++).dispatch_STATIC
) that allows building with libdispatch for static linking. The default remains dynamic linking.The motivation for
DISPATCH_EXTERN
is primarily being able to concisely defineDISPATCH_EXPORT
. This follows the naming scheme that most other Apple frameworks use (e.g. UIKit, Foundation, etc).The change to introduce support for static linking is motivated by Windows. With the gradual roll out of static linking of the runtime, it would be convenient to be able to statically link dispatch into a fully sealed Swift program. Doing so requires building libdispatch without the
__declspec(dllexport)
and__declspec(dllimport)
attributes on Windows. Similarly, it would be unfortunate to have dispatch's ABI be subsumed by a client library and have it participate in dynamic linking.The user is responsible for defining
dispatch_STATIC
when using a static copy of libdispatch. This allows the default to remain dynamic linking (which is the preferred style on Darwin and Windows).