Skip to content

Commit 756eeaa

Browse files
authored
Merge pull request #2162 from aciidb0mb3r/static-stdlib-warning
[Build] Disable Swift static linking on macOS
2 parents 78d4dc6 + a9e3d4d commit 756eeaa

File tree

2 files changed

+33
-10
lines changed

2 files changed

+33
-10
lines changed

Sources/Build/BuildPlan.swift

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -664,12 +664,16 @@ public final class ProductBuildDescription {
664664
return tempsPath.appending(component: "Objects.LinkFileList")
665665
}
666666

667+
/// Diagnostics Engine for emitting diagnostics.
668+
let diagnostics: DiagnosticsEngine
669+
667670
/// Create a build description for a product.
668-
init(product: ResolvedProduct, buildParameters: BuildParameters, fs: FileSystem) {
671+
init(product: ResolvedProduct, buildParameters: BuildParameters, fs: FileSystem, diagnostics: DiagnosticsEngine) {
669672
assert(product.type != .library(.automatic), "Automatic type libraries should not be described.")
670673
self.product = product
671674
self.buildParameters = buildParameters
672675
self.fs = fs
676+
self.diagnostics = diagnostics
673677
}
674678

675679
/// Strips the arguments which should *never* be passed to Swift compiler
@@ -724,12 +728,12 @@ public final class ProductBuildDescription {
724728
case .library(.dynamic):
725729
args += ["-emit-library"]
726730
case .executable:
727-
// Link the Swift stdlib statically if requested.
728-
if containsSwiftTargets,
729-
buildParameters.shouldLinkStaticSwiftStdlib {
730-
// FIXME: This does not work for linux yet (SR-648).
731-
if !buildParameters.triple.isLinux() {
732-
args += ["-static-stdlib"]
731+
// Link the Swift stdlib statically, if requested.
732+
//
733+
// FIXME: This does not work for linux yet (SR-648).
734+
if buildParameters.shouldLinkStaticSwiftStdlib {
735+
if buildParameters.triple.isDarwin() {
736+
diagnostics.emit(data: SwiftBackDeployLibrariesNote())
733737
}
734738
}
735739
args += ["-emit-executable"]
@@ -861,7 +865,7 @@ public class BuildPlan {
861865
/// The filesystem to operate on.
862866
let fileSystem: FileSystem
863867

864-
/// Diagnostics Engine to emit diagnostics
868+
/// Diagnostics Engine for emitting diagnostics.
865869
let diagnostics: DiagnosticsEngine
866870

867871
/// Create a build plan with build parameters and a package graph.
@@ -938,7 +942,8 @@ public class BuildPlan {
938942
for product in graph.allProducts where product.type != .library(.automatic) {
939943
productMap[product] = ProductBuildDescription(
940944
product: product, buildParameters: buildParameters,
941-
fs: fileSystem
945+
fs: fileSystem,
946+
diagnostics: diagnostics
942947
)
943948
}
944949

@@ -1218,3 +1223,13 @@ struct ProductRequiresHigherPlatformVersion: DiagnosticData {
12181223
self.platform = platform
12191224
}
12201225
}
1226+
1227+
struct SwiftBackDeployLibrariesNote: DiagnosticData {
1228+
static let id = DiagnosticID(
1229+
type: SwiftBackDeployLibrariesNote.self,
1230+
name: "org.swift.diags.\(SwiftBackDeployLibrariesNote.self)",
1231+
defaultBehavior: .warning,
1232+
description: {
1233+
$0 <<< "Swift compiler no longer supports statically linking the Swift libraries. They're included in the OS by default starting with macOS Mojave 10.14.4 beta 3. For macOS Mojave 10.14.3 and earlier, there's an optional Swift library package that can be downloaded from \"More Downloads\" for Apple Developers at https://developer.apple.com/download/more/"
1234+
})
1235+
}

Tests/BuildTests/BuildPlanTests.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ final class BuildPlanTests: XCTestCase {
111111
let linkArguments = [
112112
"/fake/path/to/swiftc", "-g", "-L", "/path/to/build/debug",
113113
"-o", "/path/to/build/debug/exe", "-module-name", "exe",
114-
"-static-stdlib", "-emit-executable",
114+
"-emit-executable",
115115
"@/path/to/build/debug/exe.product/Objects.LinkFileList",
116116
"-Xlinker", "-rpath", "-Xlinker", "/fake/path/lib/swift/macosx",
117117
]
@@ -126,6 +126,14 @@ final class BuildPlanTests: XCTestCase {
126126
#endif
127127

128128
XCTAssertEqual(try result.buildProduct(for: "exe").linkArguments(), linkArguments)
129+
130+
#if os(macOS)
131+
DiagnosticsEngineTester(diagnostics) { result in
132+
result.check(diagnostic: .contains("can be downloaded"), behavior: .warning)
133+
}
134+
#else
135+
XCTAssertNoDiagnostics(diagnostics)
136+
#endif
129137
}
130138

131139
func testBasicExtPackages() throws {

0 commit comments

Comments
 (0)