Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,9 @@ 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 {
// Prefer the swiftrt.o runtime file from the SDK, if it's specified
// with a separate C/C++ sysroot.
if let sdk = targetInfo.sdkPath, parsedOptions.hasArgument(.sysroot) {
let swiftDir: String
if staticStdlib || staticExecutable {
swiftDir = "swift_static"
Expand Down
11 changes: 3 additions & 8 deletions Tests/SwiftDriverTests/ToolchainTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -485,18 +485,13 @@ import CRT

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

Expand All @@ -518,7 +513,7 @@ import CRT
}
}

@Test func sdkDirLinuxPrioritizedOverRelativeResourceDirForLinkingSwiftRT() async throws {
@Test func RelativeResourceDirLinuxPrioritizedOverSDKDirForLinkingSwiftRT() async throws {
do {
let sdkRoot = try testInputsPath.appending(component: "mock-sdk.sdk")
var env = ProcessEnv.block
Expand All @@ -539,7 +534,7 @@ import CRT
#expect(linkJob.kind == .link)
try expectJobInvocationMatches(
linkJob,
toPathOption(sdkRoot.pathString + "/usr/lib/swift/linux/x86_64/swiftrt.o", isRelative: false)
toPathOption("resource/dir/linux/x86_64/swiftrt.o")
)
}
}
Expand Down