Add swift_binary(linkshared = True) for shared libraries - #1820
Merged
Conversation
Links the target as a shared library / loadable module (lib<name>.so, .dylib on Apple) instead of an executable, like cc_binary's linkshared: no main entry point, and the renamed-entry-point machinery is disabled (gated on the new swift.no_entry_point_rename feature or linkshared). Useful for dlopen / System.loadLibrary consumers such as Android JNI libraries (export functions with @_cdecl). examples/xplatform/shared_library builds a dynamic library this way.
AttilaTheFun
requested review from
aaronsky,
adincebic,
brentleyjones,
keith,
luispadron and
mattrobmattrob
as code owners
June 23, 2026 17:38
This was referenced Jun 23, 2026
keith
approved these changes
Jun 23, 2026
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
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.
First of two foundation PRs that split #1809 into reviewable pieces. The Swift
SDK cross-compilation work then stacks on top:
This PR is independent and testable on its own.
What this adds
swift_binary(linkshared = True): links the target as a shared library /loadable module (
lib<name>.so,.dylibon Apple) instead of an executable,like
cc_binary'slinkshared. The binary has nomain, and therenamed-entry-point machinery is disabled (gated on
linksharedor the newswift.no_entry_point_renametoolchain feature). This is useful fordlopen/System.loadLibraryconsumers such as Android JNI libraries (export functionswith
@_cdecl).examples/xplatform/shared_librarybuilds a dynamic library this way; it'sexercised by the macOS
//examples/...wildcard and the Windows CI task.