Skip to content

The --static-swift-stdlib should apply to dylibs #7501

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
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions Sources/Build/BuildDescription/ProductBuildDescription.swift
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,18 @@ package final class ProductBuildDescription: SPMBuildCore.ProductBuildDescriptio
args += ["-Xlinker", "-no_warn_duplicate_libraries"]
}

func linkSwiftStdlibStaticallyIfRequested() {
// TODO: unify this logic with SwiftTargetBuildDescription.stdlibArguments
if self.buildParameters.linkingParameters.shouldLinkStaticSwiftStdlib {
if triple.isDarwin() {
self.observabilityScope.emit(.swiftBackDeployError)
} else if triple.isSupportingStaticStdlib {
args += ["-static-stdlib"]
isLinkingStaticStdlib = true
}
}
}

switch derivedProductType {
case .macro:
throw InternalError("macro not supported") // should never be reached
Expand All @@ -206,23 +218,15 @@ package final class ProductBuildDescription: SPMBuildCore.ProductBuildDescriptio
}
args += self.deadStripArguments
case .library(.dynamic):
linkSwiftStdlibStaticallyIfRequested()
args += ["-emit-library"]
if triple.isDarwin() {
let relativePath = try "@rpath/\(buildParameters.binaryRelativePath(for: self.product).pathString)"
args += ["-Xlinker", "-install_name", "-Xlinker", relativePath]
}
args += self.deadStripArguments
case .executable, .snippet:
// Link the Swift stdlib statically, if requested.
// TODO: unify this logic with SwiftTargetBuildDescription.stdlibArguments
if self.buildParameters.linkingParameters.shouldLinkStaticSwiftStdlib {
if triple.isDarwin() {
self.observabilityScope.emit(.swiftBackDeployError)
} else if triple.isSupportingStaticStdlib {
args += ["-static-stdlib"]
isLinkingStaticStdlib = true
}
}
linkSwiftStdlibStaticallyIfRequested()
args += ["-emit-executable"]
args += self.deadStripArguments

Expand Down