Skip to content

Commit cdc476f

Browse files
committed
[Unix] Go back to only checking the runtime resource path for swiftrt.o
1 parent 953b322 commit cdc476f

2 files changed

Lines changed: 10 additions & 24 deletions

File tree

Sources/SwiftDriver/Jobs/GenericUnixToolchain+LinkerSupport.swift

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -187,22 +187,13 @@ extension GenericUnixToolchain {
187187
}
188188

189189
if !isEmbeddedEnabled && !parsedOptions.hasArgument(.nostartfiles) {
190-
let rsrc: VirtualPath
191-
// Prefer the swiftrt.o runtime file from the SDK if it's specified.
192-
if let sdk = targetInfo.sdkPath {
193-
let swiftDir: String
194-
if staticStdlib || staticExecutable {
195-
swiftDir = "swift_static"
196-
} else {
197-
swiftDir = "swift"
198-
}
199-
rsrc = VirtualPath.lookup(sdk.path).appending(components: "usr", "lib", swiftDir)
200-
} else {
201-
rsrc = VirtualPath.lookup(targetInfo.runtimeResourcePath.path)
202-
}
203-
let platform: String = targetTriple.platformName() ?? ""
204-
let architecture: String = majorArchitectureName(for: targetTriple)
205-
commandLine.appendPath(rsrc.appending(components: platform, architecture, "swiftrt.o"))
190+
let swiftrtPath = VirtualPath.lookup(targetInfo.runtimeResourcePath.path)
191+
.appending(
192+
components: targetTriple.platformName() ?? "",
193+
String(majorArchitectureName(for: targetTriple)),
194+
"swiftrt.o"
195+
)
196+
commandLine.appendPath(swiftrtPath)
206197
}
207198

208199
// If we are linking statically, we need to add all

Tests/SwiftDriverTests/ToolchainTests.swift

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -485,18 +485,13 @@ import CRT
485485

486486
@Test func relativeResourceDir() async throws {
487487
do {
488-
// Reset the environment to avoid 'SDKROOT' influencing the
489-
// linux driver paths and taking the priority over the resource directory.
490-
var env = ProcessEnv.block
491-
env["SDKROOT"] = nil
492488
var driver = try TestDriver(
493489
args: [
494490
"swiftc",
495491
"-target", "x86_64-unknown-linux", "-lto=llvm-thin",
496492
"foo.swift",
497493
"-resource-dir", "resource/dir",
498-
],
499-
env: env
494+
]
500495
)
501496
let plannedJobs = try await driver.planBuild().removingAutolinkExtractJobs()
502497

@@ -518,7 +513,7 @@ import CRT
518513
}
519514
}
520515

521-
@Test func sdkDirLinuxPrioritizedOverRelativeResourceDirForLinkingSwiftRT() async throws {
516+
@Test func RelativeResourceDirLinuxPrioritizedOverSDKDirForLinkingSwiftRT() async throws {
522517
do {
523518
let sdkRoot = try testInputsPath.appending(component: "mock-sdk.sdk")
524519
var env = ProcessEnv.block
@@ -539,7 +534,7 @@ import CRT
539534
#expect(linkJob.kind == .link)
540535
try expectJobInvocationMatches(
541536
linkJob,
542-
toPathOption(sdkRoot.pathString + "/usr/lib/swift/linux/x86_64/swiftrt.o", isRelative: false)
537+
toPathOption("resource/dir/linux/x86_64/swiftrt.o")
543538
)
544539
}
545540
}

0 commit comments

Comments
 (0)