Skip to content
Merged
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 @@ -114,7 +114,11 @@ extension WebAssemblyToolchain {
}
commandLine.append(contentsOf: inputFiles)

if let path = targetInfo.sdkPath?.path {
// Prefer -sysroot as the native sysroot path if provided.
if let sysroot = parsedOptions.getLastArgument(.sysroot)?.asSingle {
commandLine.appendFlag("--sysroot")
try commandLine.appendPath(VirtualPath(path: sysroot))
} else if let path = targetInfo.sdkPath?.path {
commandLine.appendFlag("--sysroot")
commandLine.appendPath(VirtualPath.lookup(path))
}
Expand Down
17 changes: 17 additions & 0 deletions Tests/SwiftDriverTests/SwiftDriverTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2790,6 +2790,23 @@ final class SwiftDriverTests: XCTestCase {
}
}

do {
// -sysroot is preferred over -sdk as the sysroot passed to the clang linker
try withTemporaryDirectory { path in
try localFileSystem.writeFileContents(path.appending(components: "wasi", "static-executable-args.lnk")) {
$0.send("garbage")
}
var driver = try Driver(args: commonArgs + ["-emit-executable", "-Ounchecked",
"-target", "wasm32-unknown-wasi",
"-resource-dir", path.pathString,
"-sysroot", "/sysroot/path",
"-sdk", "/sdk/path"], env: env)
let plannedJobs = try driver.planBuild()
let cmd = plannedJobs.last!.commandLine
XCTAssertTrue(cmd.contains(subsequence: ["--sysroot", .path(.absolute(try .init(validating: "/sysroot/path")))]))
}
}

do {
// Linker flags with and without space
var driver = try Driver(args: commonArgs + ["-lsomelib","-l","otherlib"], env: env)
Expand Down
Loading