Skip to content

Commit a5960b8

Browse files
committed
[native] Add toolchain span back deployment rpaths when required (swiftlang#9164)
SwiftPM's native build system does not have the concept of embedding the compatibility libraries for distribution, so add rpaths to the span back deploy library in the toolchain when targeting macOS < 26. Ensure we always insert /usr/lib/swift ahead of the added rpaths to prefer the OS content when available. this mirrors the handling of the concurrency compat lib Closes swiftlang#9163
1 parent 0b6969e commit a5960b8

File tree

2 files changed

+32
-6
lines changed

2 files changed

+32
-6
lines changed

Sources/Build/BuildDescription/ProductBuildDescription.swift

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,19 +318,34 @@ public final class ProductBuildDescription: SPMBuildCore.ProductBuildDescription
318318
throw InternalError("unexpectedly asked to generate linker arguments for a plugin product")
319319
}
320320

321-
// When deploying to macOS prior to macOS 12, add an rpath to the
322-
// back-deployed concurrency libraries.
323321
if useStdlibRpath, triple.isMacOSX {
324322
let macOSSupportedPlatform = self.package.getSupportedPlatform(for: .macOS, usingXCTest: product.isLinkingXCTest)
325323

326324
if macOSSupportedPlatform.version.major < 12 {
325+
// When deploying to macOS prior to macOS 12, add an rpath to the
326+
// back-deployed concurrency libraries.
327327
let backDeployedStdlib = try buildParameters.toolchain.macosSwiftStdlib
328328
.parentDirectory
329329
.parentDirectory
330330
.appending("swift-5.5")
331331
.appending("macosx")
332332
args += ["-Xlinker", "-rpath", "-Xlinker", backDeployedStdlib.pathString]
333333
}
334+
335+
if macOSSupportedPlatform.version.major < 26 {
336+
// When deploying to macOS prior to macOS 26, add an rpath to the
337+
// back-deployed Span library.
338+
let backDeployedStdlib = try buildParameters.toolchain.macosSwiftStdlib
339+
.parentDirectory
340+
.parentDirectory
341+
.appending("swift-6.2")
342+
.appending("macosx")
343+
args += ["-Xlinker", "-rpath", "-Xlinker", backDeployedStdlib.pathString]
344+
}
345+
346+
// If either back deployment library is used, the driver is responsible for injecting
347+
// a /usr/lib/swift -rpath at the front to ensure OS content is preferred when
348+
// available.
334349
}
335350
} else {
336351
// Don't link runtime compatibility patch libraries if there are no

Tests/BuildTests/BuildPlanTests.swift

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -834,6 +834,7 @@ class BuildPlanTestCase: BuildSystemProviderTestCase {
834834
"-Xlinker", "-rpath", "-Xlinker", "@loader_path",
835835
"@\(buildPath.appending(components: "exe.product", "Objects.LinkFileList"))",
836836
"-Xlinker", "-rpath", "-Xlinker", "/fake/path/lib/swift-5.5/macosx",
837+
"-Xlinker", "-rpath", "-Xlinker", "/fake/path/lib/swift-6.2/macosx",
837838
"-target", defaultTargetTriple,
838839
"-Xlinker", "-add_ast_path", "-Xlinker",
839840
buildPath.appending(components: "Modules", "lib.swiftmodule").pathString,
@@ -1149,6 +1150,7 @@ class BuildPlanTestCase: BuildSystemProviderTestCase {
11491150
"-Xlinker", "-rpath", "-Xlinker", "@loader_path",
11501151
"@\(buildPath.appending(components: "exe.product", "Objects.LinkFileList"))",
11511152
"-Xlinker", "-rpath", "-Xlinker", "/fake/path/lib/swift-5.5/macosx",
1153+
"-Xlinker", "-rpath", "-Xlinker", "/fake/path/lib/swift-6.2/macosx",
11521154
"-target", defaultTargetTriple,
11531155
"-g",
11541156
])
@@ -1243,6 +1245,7 @@ class BuildPlanTestCase: BuildSystemProviderTestCase {
12431245
"-Xlinker", "-rpath", "-Xlinker", "@loader_path",
12441246
"@\(buildPath.appending(components: "exe.product", "Objects.LinkFileList"))",
12451247
"-Xlinker", "-rpath", "-Xlinker", "/fake/path/lib/swift-5.5/macosx",
1248+
"-Xlinker", "-rpath", "-Xlinker", "/fake/path/lib/swift-6.2/macosx",
12461249
"-target", defaultTargetTriple,
12471250
"-g",
12481251
])
@@ -1793,6 +1796,7 @@ class BuildPlanTestCase: BuildSystemProviderTestCase {
17931796
"-Xlinker", "-rpath", "-Xlinker", "@loader_path",
17941797
"@\(buildPath.appending(components: "exe.product", "Objects.LinkFileList"))",
17951798
"-Xlinker", "-rpath", "-Xlinker", "/fake/path/lib/swift-5.5/macosx",
1799+
"-Xlinker", "-rpath", "-Xlinker", "/fake/path/lib/swift-6.2/macosx",
17961800
"-target", defaultTargetTriple,
17971801
"-Xlinker", "-add_ast_path", "-Xlinker", "/path/to/build/\(result.plan.destinationBuildParameters.triple)/debug/exe.build/exe.swiftmodule",
17981802
"-g",
@@ -2352,11 +2356,12 @@ class BuildPlanTestCase: BuildSystemProviderTestCase {
23522356

23532357
#if os(macOS)
23542358
let version = MinimumDeploymentTarget.computeXCTestMinimumDeploymentTarget(for: .macOS).versionString
2355-
let rpathsForBackdeployment: [String]
2359+
var rpathsForBackdeployment: [String] = []
23562360
if let version = try? Version(string: version, lenient: true), version.major < 12 {
2357-
rpathsForBackdeployment = ["-Xlinker", "-rpath", "-Xlinker", "/fake/path/lib/swift-5.5/macosx"]
2358-
} else {
2359-
rpathsForBackdeployment = []
2361+
rpathsForBackdeployment += ["-Xlinker", "-rpath", "-Xlinker", "/fake/path/lib/swift-5.5/macosx"]
2362+
}
2363+
if let version = try? Version(string: version, lenient: true), version.major < 26 {
2364+
rpathsForBackdeployment += ["-Xlinker", "-rpath", "-Xlinker", "/fake/path/lib/swift-6.2/macosx"]
23602365
}
23612366
XCTAssertEqual(
23622367
try result.buildProduct(for: "PkgPackageTests").linkArguments(),
@@ -2474,6 +2479,7 @@ class BuildPlanTestCase: BuildSystemProviderTestCase {
24742479
"-Xlinker", "-dead_strip",
24752480
"-Xlinker", "-rpath", "-Xlinker", "@loader_path",
24762481
"@\(buildPath.appending(components: "exe.product", "Objects.LinkFileList"))",
2482+
"-Xlinker", "-rpath", "-Xlinker", "/fake/path/lib/swift-6.2/macosx",
24772483
"-target", hostTriple.tripleString(forPlatformVersion: "12.0"),
24782484
"-g",
24792485
])
@@ -2845,6 +2851,7 @@ class BuildPlanTestCase: BuildSystemProviderTestCase {
28452851
"-Xlinker", "-rpath", "-Xlinker", "@loader_path",
28462852
"@\(buildPath.appending(components: "exe.product", "Objects.LinkFileList"))",
28472853
"-Xlinker", "-rpath", "-Xlinker", "/fake/path/lib/swift-5.5/macosx",
2854+
"-Xlinker", "-rpath", "-Xlinker", "/fake/path/lib/swift-6.2/macosx",
28482855
"-target", defaultTargetTriple,
28492856
"-Xlinker", "-add_ast_path",
28502857
"-Xlinker", buildPath.appending(components: "exe.build", "exe.swiftmodule").pathString,
@@ -2991,6 +2998,7 @@ class BuildPlanTestCase: BuildSystemProviderTestCase {
29912998
"-Xlinker", "-rpath", "-Xlinker", "@loader_path",
29922999
"@\(buildPath.appending(components: "Foo.product", "Objects.LinkFileList"))",
29933000
"-Xlinker", "-rpath", "-Xlinker", "/fake/path/lib/swift-5.5/macosx",
3001+
"-Xlinker", "-rpath", "-Xlinker", "/fake/path/lib/swift-6.2/macosx",
29943002
"-target", defaultTargetTriple,
29953003
"-Xlinker", "-add_ast_path",
29963004
"-Xlinker", buildPath.appending(components: "Foo.build", "Foo.swiftmodule").pathString,
@@ -3008,6 +3016,7 @@ class BuildPlanTestCase: BuildSystemProviderTestCase {
30083016
"-Xlinker", "-rpath", "-Xlinker", "@loader_path",
30093017
"@\(buildPath.appending(components: "Bar-Baz.product", "Objects.LinkFileList"))",
30103018
"-Xlinker", "-rpath", "-Xlinker", "/fake/path/lib/swift-5.5/macosx",
3019+
"-Xlinker", "-rpath", "-Xlinker", "/fake/path/lib/swift-6.2/macosx",
30113020
"-target", defaultTargetTriple,
30123021
"-Xlinker", "-add_ast_path",
30133022
"-Xlinker", buildPath.appending(components: "Modules", "Bar.swiftmodule").pathString,
@@ -3164,6 +3173,7 @@ class BuildPlanTestCase: BuildSystemProviderTestCase {
31643173
"-Xlinker", "-rpath", "-Xlinker", "@loader_path",
31653174
"@\(buildPath.appending(components: "lib.product", "Objects.LinkFileList"))",
31663175
"-Xlinker", "-rpath", "-Xlinker", "/fake/path/lib/swift-5.5/macosx",
3176+
"-Xlinker", "-rpath", "-Xlinker", "/fake/path/lib/swift-6.2/macosx",
31673177
"-target", defaultTargetTriple,
31683178
"-Xlinker", "-add_ast_path", "-Xlinker",
31693179
buildPath.appending(components: "Modules", "lib.swiftmodule").pathString,
@@ -7294,6 +7304,7 @@ class BuildPlanTestCase: BuildSystemProviderTestCase {
72947304
"-emit-executable",
72957305
"@\(buildPath.appending(components: "exe.product", "Objects.LinkFileList"))",
72967306
"-Xlinker", "-rpath", "-Xlinker", "/fake/path/lib/swift-5.5/macosx",
7307+
"-Xlinker", "-rpath", "-Xlinker", "/fake/path/lib/swift-6.2/macosx",
72977308
"-target", defaultTargetTriple,
72987309
"-Xlinker", "-add_ast_path",
72997310
"-Xlinker", buildPath.appending(components: "Modules", "lib.swiftmodule").pathString,

0 commit comments

Comments
 (0)