Skip to content

[Build] Disable Swift static linking on macOS #2162

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

Merged
merged 1 commit into from
Jun 12, 2019
Merged
Show file tree
Hide file tree
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
33 changes: 24 additions & 9 deletions Sources/Build/BuildPlan.swift
Original file line number Diff line number Diff line change
Expand Up @@ -664,12 +664,16 @@ public final class ProductBuildDescription {
return tempsPath.appending(component: "Objects.LinkFileList")
}

/// Diagnostics Engine for emitting diagnostics.
let diagnostics: DiagnosticsEngine

/// Create a build description for a product.
init(product: ResolvedProduct, buildParameters: BuildParameters, fs: FileSystem) {
init(product: ResolvedProduct, buildParameters: BuildParameters, fs: FileSystem, diagnostics: DiagnosticsEngine) {
assert(product.type != .library(.automatic), "Automatic type libraries should not be described.")
self.product = product
self.buildParameters = buildParameters
self.fs = fs
self.diagnostics = diagnostics
}

/// Strips the arguments which should *never* be passed to Swift compiler
Expand Down Expand Up @@ -724,12 +728,12 @@ public final class ProductBuildDescription {
case .library(.dynamic):
args += ["-emit-library"]
case .executable:
// Link the Swift stdlib statically if requested.
if containsSwiftTargets,
buildParameters.shouldLinkStaticSwiftStdlib {
// FIXME: This does not work for linux yet (SR-648).
if !buildParameters.triple.isLinux() {
args += ["-static-stdlib"]
// Link the Swift stdlib statically, if requested.
//
// FIXME: This does not work for linux yet (SR-648).
if buildParameters.shouldLinkStaticSwiftStdlib {
if buildParameters.triple.isDarwin() {
diagnostics.emit(data: SwiftBackDeployLibrariesNote())
}
}
args += ["-emit-executable"]
Expand Down Expand Up @@ -861,7 +865,7 @@ public class BuildPlan {
/// The filesystem to operate on.
let fileSystem: FileSystem

/// Diagnostics Engine to emit diagnostics
/// Diagnostics Engine for emitting diagnostics.
let diagnostics: DiagnosticsEngine

/// Create a build plan with build parameters and a package graph.
Expand Down Expand Up @@ -938,7 +942,8 @@ public class BuildPlan {
for product in graph.allProducts where product.type != .library(.automatic) {
productMap[product] = ProductBuildDescription(
product: product, buildParameters: buildParameters,
fs: fileSystem
fs: fileSystem,
diagnostics: diagnostics
)
}

Expand Down Expand Up @@ -1218,3 +1223,13 @@ struct ProductRequiresHigherPlatformVersion: DiagnosticData {
self.platform = platform
}
}

struct SwiftBackDeployLibrariesNote: DiagnosticData {
static let id = DiagnosticID(
type: SwiftBackDeployLibrariesNote.self,
name: "org.swift.diags.\(SwiftBackDeployLibrariesNote.self)",
defaultBehavior: .warning,
description: {
$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/"
})
}
10 changes: 9 additions & 1 deletion Tests/BuildTests/BuildPlanTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ final class BuildPlanTests: XCTestCase {
let linkArguments = [
"/fake/path/to/swiftc", "-g", "-L", "/path/to/build/debug",
"-o", "/path/to/build/debug/exe", "-module-name", "exe",
"-static-stdlib", "-emit-executable",
"-emit-executable",
"@/path/to/build/debug/exe.product/Objects.LinkFileList",
"-Xlinker", "-rpath", "-Xlinker", "/fake/path/lib/swift/macosx",
]
Expand All @@ -126,6 +126,14 @@ final class BuildPlanTests: XCTestCase {
#endif

XCTAssertEqual(try result.buildProduct(for: "exe").linkArguments(), linkArguments)

#if os(macOS)
DiagnosticsEngineTester(diagnostics) { result in
result.check(diagnostic: .contains("can be downloaded"), behavior: .warning)
}
#else
XCTAssertNoDiagnostics(diagnostics)
#endif
}

func testBasicExtPackages() throws {
Expand Down