Skip to content

Allow building products as dynamic libraries via environment variable - #132

Open
colemancda wants to merge 1 commit into
apple:mainfrom
colemancda:dynamic-library-support
Open

Allow building products as dynamic libraries via environment variable#132
colemancda wants to merge 1 commit into
apple:mainfrom
colemancda:dynamic-library-support

Conversation

@colemancda

Copy link
Copy Markdown

Motivation:

Distributions that ship Swift modules as shared libraries in a common location (for example the Swift resource directory on embedded Linux images, where multiple executables import the same prebuilt module) need the HTTPTypes / HTTPTypesFoundation products built as dynamic libraries so a stable .so can be installed and linked against. With SwiftPM's default automatic linkage the products are built statically, and there is currently no way to request dynamic linkage without patching Package.swift.

Modifications:

Add an opt-in SWIFT_HTTP_TYPES_DYNAMIC_LIBRARY environment variable, read via Context.environment, that switches both library products to explicit .dynamic linkage. Without the variable the products keep automatic linkage, so default behavior for existing consumers is completely unchanged.

Result:

SWIFT_HTTP_TYPES_DYNAMIC_LIBRARY=1 swift build produces libHTTPTypes.so / libHTTPTypesFoundation.so (verified with swift package dump-package, which reports dynamic with the variable set and automatic without), letting downstream distributions build and install shared libraries without carrying a manifest patch.

Add an opt-in SWIFT_HTTP_TYPES_DYNAMIC_LIBRARY environment variable that
switches the HTTPTypes and HTTPTypesFoundation products to explicit
dynamic linkage. Distributions that ship Swift modules as shared
libraries in a common location (e.g. the Swift resource directory on
embedded Linux images) need a dynamic product to install a stable .so;
SwiftPM's default automatic linkage otherwise builds them statically.

The default behavior is unchanged: without the environment variable the
products keep automatic linkage.
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.

1 participant