Skip to content

Commit 42bf5a9

Browse files
committed
[Unix] Go back to only checking the runtime resource path for swiftrt.o
1 parent 049acb8 commit 42bf5a9

File tree

2 files changed

+10
-23
lines changed

2 files changed

+10
-23
lines changed

Sources/SwiftDriver/Jobs/GenericUnixToolchain+LinkerSupport.swift

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -181,22 +181,13 @@ extension GenericUnixToolchain {
181181
}
182182

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

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

Tests/SwiftDriverTests/SwiftDriverTests.swift

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7389,14 +7389,10 @@ final class SwiftDriverTests: XCTestCase {
73897389

73907390
func testRelativeResourceDir() throws {
73917391
do {
7392-
// Reset the environment to avoid 'SDKROOT' influencing the
7393-
// linux driver paths and taking the priority over the resource directory.
7394-
var env = ProcessEnv.block
7395-
env["SDKROOT"] = nil
73967392
var driver = try Driver(args: ["swiftc",
73977393
"-target", "x86_64-unknown-linux", "-lto=llvm-thin",
73987394
"foo.swift",
7399-
"-resource-dir", "resource/dir"], env: env)
7395+
"-resource-dir", "resource/dir"])
74007396
let plannedJobs = try driver.planBuild().removingAutolinkExtractJobs()
74017397

74027398
let compileJob = plannedJobs[0]
@@ -7411,7 +7407,7 @@ final class SwiftDriverTests: XCTestCase {
74117407
}
74127408
}
74137409

7414-
func testSDKDirLinuxPrioritizedOverRelativeResourceDirForLinkingSwiftRT() throws {
7410+
func testRelativeResourceDirLinuxPrioritizedOverSDKDirForLinkingSwiftRT() throws {
74157411
do {
74167412
let sdkRoot = try testInputsPath.appending(component: "mock-sdk.sdk")
74177413
var env = ProcessEnv.block
@@ -7425,7 +7421,7 @@ final class SwiftDriverTests: XCTestCase {
74257421
XCTAssertEqual(compileJob.kind, .compile)
74267422
let linkJob = plannedJobs[1]
74277423
XCTAssertEqual(linkJob.kind, .link)
7428-
try XCTAssertJobInvocationMatches(linkJob, toPathOption(sdkRoot.pathString + "/usr/lib/swift/linux/x86_64/swiftrt.o", isRelative: false))
7424+
try XCTAssertJobInvocationMatches(linkJob, toPathOption("resource/dir/linux/x86_64/swiftrt.o"))
74297425
}
74307426
}
74317427

0 commit comments

Comments
 (0)