Skip to content

Commit 560a2c0

Browse files
authored
Merge pull request #2163 from aciidb0mb3r/static-stdlib-warning-5.1
[Build] Disable Swift static linking on macOS
2 parents 5fc925c + 6f18aeb commit 560a2c0

File tree

2 files changed

+32
-8
lines changed

2 files changed

+32
-8
lines changed

Sources/Build/BuildPlan.swift

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -660,12 +660,16 @@ public final class ProductBuildDescription {
660660
return tempsPath.appending(component: "Objects.LinkFileList")
661661
}
662662

663+
/// Diagnostics Engine for emitting diagnostics.
664+
let diagnostics: DiagnosticsEngine
665+
663666
/// Create a build description for a product.
664-
init(product: ResolvedProduct, buildParameters: BuildParameters, fs: FileSystem) {
667+
init(product: ResolvedProduct, buildParameters: BuildParameters, fs: FileSystem, diagnostics: DiagnosticsEngine) {
665668
assert(product.type != .library(.automatic), "Automatic type libraries should not be described.")
666669
self.product = product
667670
self.buildParameters = buildParameters
668671
self.fs = fs
672+
self.diagnostics = diagnostics
669673
}
670674

671675
/// Strips the arguments which should *never* be passed to Swift compiler
@@ -718,11 +722,12 @@ public final class ProductBuildDescription {
718722
case .library(.dynamic):
719723
args += ["-emit-library"]
720724
case .executable:
721-
// Link the Swift stdlib statically if requested.
725+
// Link the Swift stdlib statically, if requested.
726+
//
727+
// FIXME: This does not work for linux yet (SR-648).
722728
if buildParameters.shouldLinkStaticSwiftStdlib {
723-
// FIXME: This does not work for linux yet (SR-648).
724-
if !buildParameters.triple.isLinux() {
725-
args += ["-static-stdlib"]
729+
if buildParameters.triple.isDarwin() {
730+
diagnostics.emit(data: SwiftBackDeployLibrariesNote())
726731
}
727732
}
728733
args += ["-emit-executable"]
@@ -846,7 +851,7 @@ public class BuildPlan {
846851
/// The filesystem to operate on.
847852
let fileSystem: FileSystem
848853

849-
/// Diagnostics Engine to emit diagnostics
854+
/// Diagnostics Engine for emitting diagnostics.
850855
let diagnostics: DiagnosticsEngine
851856

852857
/// Create a build plan with build parameters and a package graph.
@@ -923,7 +928,8 @@ public class BuildPlan {
923928
for product in graph.allProducts where product.type != .library(.automatic) {
924929
productMap[product] = ProductBuildDescription(
925930
product: product, buildParameters: buildParameters,
926-
fs: fileSystem
931+
fs: fileSystem,
932+
diagnostics: diagnostics
927933
)
928934
}
929935

@@ -1203,3 +1209,13 @@ struct ProductRequiresHigherPlatformVersion: DiagnosticData {
12031209
self.platform = platform
12041210
}
12051211
}
1212+
1213+
struct SwiftBackDeployLibrariesNote: DiagnosticData {
1214+
static let id = DiagnosticID(
1215+
type: SwiftBackDeployLibrariesNote.self,
1216+
name: "org.swift.diags.\(SwiftBackDeployLibrariesNote.self)",
1217+
defaultBehavior: .warning,
1218+
description: {
1219+
$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/"
1220+
})
1221+
}

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)