Skip to content

Commit 2dd4716

Browse files
committed
PackageModel: Respect toolset linker
1 parent d8e22aa commit 2dd4716

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

Sources/PackageModel/UserToolchain.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,11 @@ public final class UserToolchain: Toolchain {
321321
destination: Destination,
322322
environment: EnvironmentVariables
323323
) throws -> [String] {
324-
let swiftCompilerFlags = destination.toolset.knownTools[.swiftCompiler]?.extraCLIOptions ?? []
324+
var swiftCompilerFlags = destination.toolset.knownTools[.swiftCompiler]?.extraCLIOptions ?? []
325+
326+
if let linker = destination.toolset.knownTools[.linker]?.path {
327+
swiftCompilerFlags += ["-use-ld=\(linker.pathString)"]
328+
}
325329

326330
guard let sdkDir = destination.pathsConfiguration.sdkRootPath else {
327331
if triple.isWindows() {

Tests/BuildTests/BuildPlanTests.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3607,7 +3607,7 @@ final class BuildPlanTests: XCTestCase {
36073607
.cxxCompiler: .init(extraCLIOptions: [jsonFlag(tool: .cxxCompiler)]),
36083608
.swiftCompiler: .init(extraCLIOptions: [jsonFlag(tool: .swiftCompiler)]),
36093609
.librarian: .init(path: "/fake/toolchain/usr/bin/librarian"),
3610-
.linker: .init(extraCLIOptions: [jsonFlag(tool: .linker)]),
3610+
.linker: .init(path: "/fake/toolchain/usr/bin/linker", extraCLIOptions: [jsonFlag(tool: .linker)]),
36113611
],
36123612
rootPaths: try UserToolchain.default.destination.toolset.rootPaths)
36133613
let targetTriple = try Triple("armv7em-unknown-none-macho")
@@ -3688,7 +3688,9 @@ final class BuildPlanTests: XCTestCase {
36883688
// Compile Swift Target
36893689
let exeCompileArguments = try result.target(for: "exe").swiftTarget().compileArguments()
36903690
let exeCompileArgumentsPattern: [StringPattern] = [
3691-
jsonFlag(tool: .swiftCompiler), "-g", cliFlag(tool: .swiftCompiler),
3691+
jsonFlag(tool: .swiftCompiler),
3692+
"-use-ld=/fake/toolchain/usr/bin/linker",
3693+
"-g", cliFlag(tool: .swiftCompiler),
36923694
.anySequence,
36933695
"-Xcc", jsonFlag(tool: .cCompiler), "-Xcc", "-g", "-Xcc", cliFlag(tool: .cCompiler),
36943696
// TODO: Pass -Xcxx flags to swiftc (#6491)
@@ -3711,7 +3713,9 @@ final class BuildPlanTests: XCTestCase {
37113713
// Link Product
37123714
let exeLinkArguments = try result.buildProduct(for: "exe").linkArguments()
37133715
let exeLinkArgumentsPattern: [StringPattern] = [
3714-
jsonFlag(tool: .swiftCompiler), "-g", cliFlag(tool: .swiftCompiler),
3716+
jsonFlag(tool: .swiftCompiler),
3717+
"-use-ld=/fake/toolchain/usr/bin/linker",
3718+
"-g", cliFlag(tool: .swiftCompiler),
37153719
.anySequence,
37163720
"-Xlinker", jsonFlag(tool: .linker), "-Xlinker", cliFlag(tool: .linker),
37173721
]

0 commit comments

Comments
 (0)