Skip to content

Commit 3c5f731

Browse files
committed
Remove improper stdlib overrides on macOS when running plugins
1 parent 04ab3dc commit 3c5f731

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

Sources/SPMBuildCore/Plugins/DefaultPluginScriptRunner.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,12 +466,19 @@ public struct DefaultPluginScriptRunner: PluginScriptRunner, Cancellable {
466466

467467
var env = Environment.current
468468

469+
// FIXME: This is largely a workaround for improper rpath setup on Linux. It should be
470+
// removed once the Swift Build backend switches to use swiftc as the linker driver
471+
// for targets with Swift sources. For now, limit the scope to non-macOS, so that
472+
// plugins do not inadvertently use the toolchain stdlib instead of the OS stdlib
473+
// when built with a Swift.org toolchain.
474+
#if !os(macOS)
469475
// Update the environment for any runtime library paths that tools compiled
470476
// for the command plugin might require after they have been built.
471477
let runtimeLibPaths = self.toolchain.runtimeLibraryPaths
472478
for libPath in runtimeLibPaths {
473479
env.appendPath(key: .libraryPath, value: libPath.pathString)
474480
}
481+
#endif
475482

476483
#if os(Windows)
477484
let pluginLibraryPath = self.toolchain.swiftPMLibrariesLocation.pluginLibraryPath.pathString

Sources/SwiftBuildSupport/PIFBuilder.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,12 +367,18 @@ public final class PIFBuilder {
367367
buildCommands: result.buildCommands.map( { buildCommand in
368368
var newEnv: Environment = buildCommand.configuration.environment
369369

370+
// FIXME: This is largely a workaround for improper rpath setup on Linux. It should be
371+
// removed once the Swift Build backend switches to use swiftc as the linker driver
372+
// for targets with Swift sources. For now, limit the scope to non-macOS, so that
373+
// plugins do not inadvertently use the toolchain stdlib instead of the OS stdlib
374+
// when built with a Swift.org toolchain.
375+
#if !os(macOS)
370376
let runtimeLibPaths = buildParameters.toolchain.runtimeLibraryPaths
371-
372377
// Add paths to swift standard runtime libraries to the library path so that they can be found at runtime
373378
for libPath in runtimeLibPaths {
374379
newEnv.appendPath(key: .libraryPath, value: libPath.pathString)
375380
}
381+
#endif
376382

377383
// Append the system path at the end so that necessary system tool paths can be found
378384
if let pathValue = Environment.current[EnvironmentKey.path] {

Tests/CommandsTests/BuildCommandTests.swift

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1415,8 +1415,11 @@ struct BuildCommandTestCases {
14151415
let hostArch: String
14161416
#if arch(arm64)
14171417
hostArch = "arm64"
1418-
#else
1418+
#elseif arch(x86_64)
14191419
hostArch = "x86_64"
1420+
#else
1421+
Issue.record("test is not supported on host arch")
1422+
return
14201423
#endif
14211424

14221425
// Unversioned triple - build should pass
@@ -1439,9 +1442,9 @@ struct BuildCommandTestCases {
14391442
)
14401443
}
14411444

1442-
if buildSystem == .swiftbuild {
1443-
// Versioned triple with unsupported deployment target - build should fail
1444-
try await fixture(name: "Miscellaneous/RequiresOlderDeploymentTarget") { path in
1445+
// Versioned triple with unsupported deployment target - build should fail
1446+
try await withKnownIssue {
1447+
_ = try await fixture(name: "Miscellaneous/RequiresOlderDeploymentTarget") { path in
14451448
await #expect(throws: Error.self) {
14461449
try await executeSwiftBuild(
14471450
path,
@@ -1451,6 +1454,9 @@ struct BuildCommandTestCases {
14511454
)
14521455
}
14531456
}
1457+
} when: {
1458+
// The native build system does not correctly pass the elevated deployment target
1459+
buildSystem != .swiftbuild
14541460
}
14551461
}
14561462
}

0 commit comments

Comments
 (0)