Skip to content

Commit 0849e9d

Browse files
authored
Disallow static linking core libraries in swift test (#7087)
This is currently not supported and we should show a proper error message in this case. Resolves rdar://117908112.
1 parent 786c513 commit 0849e9d

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

Sources/Commands/SwiftBuildTool.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ struct BuildToolOptions: ParsableArguments {
8585
/// Specific product to build.
8686
@Option(help: "Build the specified product")
8787
var product: String?
88+
89+
/// If should link the Swift stdlib statically.
90+
@Flag(name: .customLong("static-swift-stdlib"), inversion: .prefixedNo, help: "Link Swift stdlib statically")
91+
public var shouldLinkStaticSwiftStdlib: Bool = false
8892
}
8993

9094
/// swift-build tool namespace
@@ -127,6 +131,7 @@ public struct SwiftBuildTool: SwiftCommand {
127131
}
128132
let buildSystem = try swiftTool.createBuildSystem(
129133
explicitProduct: options.product,
134+
shouldLinkStaticSwiftStdlib: options.shouldLinkStaticSwiftStdlib,
130135
// command result output goes on stdout
131136
// ie "swift build" should output to stdout
132137
customOutputStream: TSCBasic.stdoutStream

Sources/CoreCommands/Options.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -529,10 +529,6 @@ public struct LinkerOptions: ParsableArguments {
529529
)
530530
public var linkerDeadStrip: Bool = true
531531

532-
/// If should link the Swift stdlib statically.
533-
@Flag(name: .customLong("static-swift-stdlib"), inversion: .prefixedNo, help: "Link Swift stdlib statically")
534-
public var shouldLinkStaticSwiftStdlib: Bool = false
535-
536532
/// Disables adding $ORIGIN/@loader_path to the rpath, useful when deploying
537533
@Flag(name: .customLong("disable-local-rpath"), help: "Disable adding $ORIGIN/@loader_path to the rpath by default")
538534
public var shouldDisableLocalRpath: Bool = false

Sources/CoreCommands/SwiftTool.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,7 @@ public final class SwiftTool {
641641
explicitBuildSystem: BuildSystemProvider.Kind? = .none,
642642
explicitProduct: String? = .none,
643643
cacheBuildManifest: Bool = true,
644+
shouldLinkStaticSwiftStdlib: Bool = false,
644645
customBuildParameters: BuildParameters? = .none,
645646
customPackageGraphLoader: (() throws -> PackageGraph)? = .none,
646647
customOutputStream: OutputByteStream? = .none,
@@ -651,6 +652,9 @@ public final class SwiftTool {
651652
fatalError("build system provider not initialized")
652653
}
653654

655+
var buildParameters = try customBuildParameters ?? self.buildParameters()
656+
buildParameters.linkingParameters.shouldLinkStaticSwiftStdlib = shouldLinkStaticSwiftStdlib
657+
654658
let buildSystem = try buildSystemProvider.createBuildSystem(
655659
kind: explicitBuildSystem ?? options.build.buildSystem,
656660
explicitProduct: explicitProduct,
@@ -718,8 +722,7 @@ public final class SwiftTool {
718722
linkingParameters: .init(
719723
linkerDeadStrip: options.linker.linkerDeadStrip,
720724
linkTimeOptimizationMode: options.build.linkTimeOptimizationMode?.buildParameter,
721-
shouldDisableLocalRpath: options.linker.shouldDisableLocalRpath,
722-
shouldLinkStaticSwiftStdlib: options.linker.shouldLinkStaticSwiftStdlib
725+
shouldDisableLocalRpath: options.linker.shouldDisableLocalRpath
723726
),
724727
outputParameters: .init(
725728
isVerbose: self.logLevel <= .info

0 commit comments

Comments
 (0)