Skip to content

Commit 6fb9d0c

Browse files
committed
Only change if -sysroot is specified
1 parent 5537899 commit 6fb9d0c

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

Sources/SwiftDriver/Jobs/GenericUnixToolchain+LinkerSupport.swift

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

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

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

0 commit comments

Comments
 (0)