diff --git a/Sources/SwiftDriver/Jobs/WebAssemblyToolchain+LinkerSupport.swift b/Sources/SwiftDriver/Jobs/WebAssemblyToolchain+LinkerSupport.swift index 397ee24e1..6214fee4d 100644 --- a/Sources/SwiftDriver/Jobs/WebAssemblyToolchain+LinkerSupport.swift +++ b/Sources/SwiftDriver/Jobs/WebAssemblyToolchain+LinkerSupport.swift @@ -73,6 +73,10 @@ extension WebAssemblyToolchain { if let tool = lookupExecutablePath(filename: "clang", searchPaths: [toolsDir]) { clangPath = tool } + + // Look for binutils in the toolchain folder. + commandLine.appendFlag("-B") + commandLine.appendPath(toolsDir) } guard !parsedOptions.hasArgument(.noStaticStdlib, .noStaticExecutable) else { diff --git a/Tests/SwiftDriverTests/SwiftDriverTests.swift b/Tests/SwiftDriverTests/SwiftDriverTests.swift index 72856f91c..d60058862 100644 --- a/Tests/SwiftDriverTests/SwiftDriverTests.swift +++ b/Tests/SwiftDriverTests/SwiftDriverTests.swift @@ -4367,6 +4367,26 @@ final class SwiftDriverTests: XCTestCase { XCTAssertEqual(frontendJobs.count, 2) XCTAssertEqual(frontendJobs[1].kind, .link) XCTAssertEqual(frontendJobs[1].tool.absolutePath!.pathString, ld.pathString) + + // WASI toolchain + do { + try withTemporaryDirectory { resourceDir in + try localFileSystem.writeFileContents(resourceDir.appending(components: "wasi", "static-executable-args.lnk")) { + $0.send("garbage") + } + var driver = try Driver(args: ["swiftc", + "-target", "wasm32-unknown-wasi", + "-resource-dir", resourceDir.pathString, + "-tools-directory", tmpDir.pathString, + "foo.swift"], + env: env) + let frontendJobs = try driver.planBuild().removingAutolinkExtractJobs() + XCTAssertEqual(frontendJobs.count, 2) + XCTAssertTrue(frontendJobs[1].commandLine.contains(subsequence: [ + .flag("-B"), .path(.absolute(tmpDir)) + ])) + } + } } }