Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Unix] Go back to only checking the runtime resource path for swiftrt.o #1822

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 7 additions & 16 deletions Sources/SwiftDriver/Jobs/GenericUnixToolchain+LinkerSupport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -168,22 +168,13 @@ extension GenericUnixToolchain {
}

if !isEmbeddedEnabled && !parsedOptions.hasArgument(.nostartfiles) {
let rsrc: VirtualPath
// Prefer the swiftrt.o runtime file from the SDK if it's specified.
if let sdk = targetInfo.sdkPath {
let swiftDir: String
if staticStdlib || staticExecutable {
swiftDir = "swift_static"
} else {
swiftDir = "swift"
}
rsrc = VirtualPath.lookup(sdk.path).appending(components: "usr", "lib", swiftDir)
} else {
rsrc = VirtualPath.lookup(targetInfo.runtimeResourcePath.path)
}
let platform: String = targetTriple.platformName() ?? ""
let architecture: String = majorArchitectureName(for: targetTriple)
commandLine.appendPath(rsrc.appending(components: platform, architecture, "swiftrt.o"))
let swiftrtPath = VirtualPath.lookup(targetInfo.runtimeResourcePath.path)
.appending(
components: targetTriple.platformName() ?? "",
String(majorArchitectureName(for: targetTriple)),
"swiftrt.o"
)
commandLine.appendPath(swiftrtPath)
}

// If we are linking statically, we need to add all
Expand Down
10 changes: 3 additions & 7 deletions Tests/SwiftDriverTests/SwiftDriverTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7159,14 +7159,10 @@ final class SwiftDriverTests: XCTestCase {

func testRelativeResourceDir() throws {
do {
// Reset the environment to avoid 'SDKROOT' influencing the
// linux driver paths and taking the priority over the resource directory.
var env = ProcessEnv.vars
env["SDKROOT"] = nil
var driver = try Driver(args: ["swiftc",
"-target", "x86_64-unknown-linux", "-lto=llvm-thin",
"foo.swift",
"-resource-dir", "resource/dir"], env: env)
"-resource-dir", "resource/dir"])
let plannedJobs = try driver.planBuild().removingAutolinkExtractJobs()

let compileJob = plannedJobs[0]
Expand All @@ -7181,7 +7177,7 @@ final class SwiftDriverTests: XCTestCase {
}
}

func testSDKDirLinuxPrioritizedOverRelativeResourceDirForLinkingSwiftRT() throws {
func testRelativeResourceDirLinuxPrioritizedOverSDKDirForLinkingSwiftRT() throws {
do {
let sdkRoot = try testInputsPath.appending(component: "mock-sdk.sdk")
var env = ProcessEnv.vars
Expand All @@ -7195,7 +7191,7 @@ final class SwiftDriverTests: XCTestCase {
XCTAssertEqual(compileJob.kind, .compile)
let linkJob = plannedJobs[1]
XCTAssertEqual(linkJob.kind, .link)
try XCTAssertJobInvocationMatches(linkJob, toPathOption(sdkRoot.pathString + "/usr/lib/swift/linux/x86_64/swiftrt.o", isRelative: false))
try XCTAssertJobInvocationMatches(linkJob, toPathOption("resource/dir/linux/x86_64/swiftrt.o"))
}
}

Expand Down