Skip to content

Commit 84c6db8

Browse files
authored
[native] Add toolchain span back deployment rpaths when required (#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 #9163
1 parent ab60142 commit 84c6db8

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
@@ -835,6 +835,7 @@ class BuildPlanTestCase: BuildSystemProviderTestCase {
835835
"-Xlinker", "-rpath", "-Xlinker", "@loader_path",
836836
"@\(buildPath.appending(components: "exe.product", "Objects.LinkFileList"))",
837837
"-Xlinker", "-rpath", "-Xlinker", "/fake/path/lib/swift-5.5/macosx",
838+
"-Xlinker", "-rpath", "-Xlinker", "/fake/path/lib/swift-6.2/macosx",
838839
"-target", defaultTargetTriple,
839840
"-Xlinker", "-add_ast_path", "-Xlinker",
840841
buildPath.appending(components: "Modules", "lib.swiftmodule").pathString,
@@ -1150,6 +1151,7 @@ class BuildPlanTestCase: BuildSystemProviderTestCase {
11501151
"-Xlinker", "-rpath", "-Xlinker", "@loader_path",
11511152
"@\(buildPath.appending(components: "exe.product", "Objects.LinkFileList"))",
11521153
"-Xlinker", "-rpath", "-Xlinker", "/fake/path/lib/swift-5.5/macosx",
1154+
"-Xlinker", "-rpath", "-Xlinker", "/fake/path/lib/swift-6.2/macosx",
11531155
"-target", defaultTargetTriple,
11541156
"-g",
11551157
])
@@ -1244,6 +1246,7 @@ class BuildPlanTestCase: BuildSystemProviderTestCase {
12441246
"-Xlinker", "-rpath", "-Xlinker", "@loader_path",
12451247
"@\(buildPath.appending(components: "exe.product", "Objects.LinkFileList"))",
12461248
"-Xlinker", "-rpath", "-Xlinker", "/fake/path/lib/swift-5.5/macosx",
1249+
"-Xlinker", "-rpath", "-Xlinker", "/fake/path/lib/swift-6.2/macosx",
12471250
"-target", defaultTargetTriple,
12481251
"-g",
12491252
])
@@ -1794,6 +1797,7 @@ class BuildPlanTestCase: BuildSystemProviderTestCase {
17941797
"-Xlinker", "-rpath", "-Xlinker", "@loader_path",
17951798
"@\(buildPath.appending(components: "exe.product", "Objects.LinkFileList"))",
17961799
"-Xlinker", "-rpath", "-Xlinker", "/fake/path/lib/swift-5.5/macosx",
1800+
"-Xlinker", "-rpath", "-Xlinker", "/fake/path/lib/swift-6.2/macosx",
17971801
"-target", defaultTargetTriple,
17981802
"-Xlinker", "-add_ast_path", "-Xlinker", "/path/to/build/\(result.plan.destinationBuildParameters.triple)/debug/exe.build/exe.swiftmodule",
17991803
"-g",
@@ -2353,11 +2357,12 @@ class BuildPlanTestCase: BuildSystemProviderTestCase {
23532357

23542358
#if os(macOS)
23552359
let version = MinimumDeploymentTarget.computeXCTestMinimumDeploymentTarget(for: .macOS).versionString
2356-
let rpathsForBackdeployment: [String]
2360+
var rpathsForBackdeployment: [String] = []
23572361
if let version = try? Version(string: version, lenient: true), version.major < 12 {
2358-
rpathsForBackdeployment = ["-Xlinker", "-rpath", "-Xlinker", "/fake/path/lib/swift-5.5/macosx"]
2359-
} else {
2360-
rpathsForBackdeployment = []
2362+
rpathsForBackdeployment += ["-Xlinker", "-rpath", "-Xlinker", "/fake/path/lib/swift-5.5/macosx"]
2363+
}
2364+
if let version = try? Version(string: version, lenient: true), version.major < 26 {
2365+
rpathsForBackdeployment += ["-Xlinker", "-rpath", "-Xlinker", "/fake/path/lib/swift-6.2/macosx"]
23612366
}
23622367
XCTAssertEqual(
23632368
try result.buildProduct(for: "PkgPackageTests").linkArguments(),
@@ -2475,6 +2480,7 @@ class BuildPlanTestCase: BuildSystemProviderTestCase {
24752480
"-Xlinker", "-dead_strip",
24762481
"-Xlinker", "-rpath", "-Xlinker", "@loader_path",
24772482
"@\(buildPath.appending(components: "exe.product", "Objects.LinkFileList"))",
2483+
"-Xlinker", "-rpath", "-Xlinker", "/fake/path/lib/swift-6.2/macosx",
24782484
"-target", hostTriple.tripleString(forPlatformVersion: "12.0"),
24792485
"-g",
24802486
])
@@ -2846,6 +2852,7 @@ class BuildPlanTestCase: BuildSystemProviderTestCase {
28462852
"-Xlinker", "-rpath", "-Xlinker", "@loader_path",
28472853
"@\(buildPath.appending(components: "exe.product", "Objects.LinkFileList"))",
28482854
"-Xlinker", "-rpath", "-Xlinker", "/fake/path/lib/swift-5.5/macosx",
2855+
"-Xlinker", "-rpath", "-Xlinker", "/fake/path/lib/swift-6.2/macosx",
28492856
"-target", defaultTargetTriple,
28502857
"-Xlinker", "-add_ast_path",
28512858
"-Xlinker", buildPath.appending(components: "exe.build", "exe.swiftmodule").pathString,
@@ -2992,6 +2999,7 @@ class BuildPlanTestCase: BuildSystemProviderTestCase {
29922999
"-Xlinker", "-rpath", "-Xlinker", "@loader_path",
29933000
"@\(buildPath.appending(components: "Foo.product", "Objects.LinkFileList"))",
29943001
"-Xlinker", "-rpath", "-Xlinker", "/fake/path/lib/swift-5.5/macosx",
3002+
"-Xlinker", "-rpath", "-Xlinker", "/fake/path/lib/swift-6.2/macosx",
29953003
"-target", defaultTargetTriple,
29963004
"-Xlinker", "-add_ast_path",
29973005
"-Xlinker", buildPath.appending(components: "Foo.build", "Foo.swiftmodule").pathString,
@@ -3009,6 +3017,7 @@ class BuildPlanTestCase: BuildSystemProviderTestCase {
30093017
"-Xlinker", "-rpath", "-Xlinker", "@loader_path",
30103018
"@\(buildPath.appending(components: "Bar-Baz.product", "Objects.LinkFileList"))",
30113019
"-Xlinker", "-rpath", "-Xlinker", "/fake/path/lib/swift-5.5/macosx",
3020+
"-Xlinker", "-rpath", "-Xlinker", "/fake/path/lib/swift-6.2/macosx",
30123021
"-target", defaultTargetTriple,
30133022
"-Xlinker", "-add_ast_path",
30143023
"-Xlinker", buildPath.appending(components: "Modules", "Bar.swiftmodule").pathString,
@@ -3165,6 +3174,7 @@ class BuildPlanTestCase: BuildSystemProviderTestCase {
31653174
"-Xlinker", "-rpath", "-Xlinker", "@loader_path",
31663175
"@\(buildPath.appending(components: "lib.product", "Objects.LinkFileList"))",
31673176
"-Xlinker", "-rpath", "-Xlinker", "/fake/path/lib/swift-5.5/macosx",
3177+
"-Xlinker", "-rpath", "-Xlinker", "/fake/path/lib/swift-6.2/macosx",
31683178
"-target", defaultTargetTriple,
31693179
"-Xlinker", "-add_ast_path", "-Xlinker",
31703180
buildPath.appending(components: "Modules", "lib.swiftmodule").pathString,
@@ -7295,6 +7305,7 @@ class BuildPlanTestCase: BuildSystemProviderTestCase {
72957305
"-emit-executable",
72967306
"@\(buildPath.appending(components: "exe.product", "Objects.LinkFileList"))",
72977307
"-Xlinker", "-rpath", "-Xlinker", "/fake/path/lib/swift-5.5/macosx",
7308+
"-Xlinker", "-rpath", "-Xlinker", "/fake/path/lib/swift-6.2/macosx",
72987309
"-target", defaultTargetTriple,
72997310
"-Xlinker", "-add_ast_path",
73007311
"-Xlinker", buildPath.appending(components: "Modules", "lib.swiftmodule").pathString,

0 commit comments

Comments
 (0)