Skip to content

Commit 14c512a

Browse files
committed
Only change if -sysroot is specified
1 parent cdc476f commit 14c512a

1 file changed

Lines changed: 17 additions & 7 deletions

File tree

Sources/SwiftDriver/Jobs/GenericUnixToolchain+LinkerSupport.swift

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

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

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

0 commit comments

Comments
 (0)