Skip to content

Commit c1956bc

Browse files
kabiroberaiMaxDesiatov
authored andcommitted
Swift SDKs: fix toolset.linker.path not passed to -ld-path (#6719)
This PR implements support for the `linker.path` field in the Swift SDK toolset spec. Depends on swiftlang/swift#68495 and swiftlang/swift-driver#1441. ### Motivation: This field was previously parsed but not respected. ### Modifications: Add `-ld-path=\(linker.path)` to the toolchain's Swift flags if a linker path override is supplied ### Result: The linker path is now respected.
1 parent 4362bd7 commit c1956bc

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

Sources/PackageModel/UserToolchain.swift

+5-1
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,11 @@ public final class UserToolchain: Toolchain {
347347
swiftSDK: SwiftSDK,
348348
environment: EnvironmentVariables
349349
) throws -> [String] {
350-
let swiftCompilerFlags = swiftSDK.toolset.knownTools[.swiftCompiler]?.extraCLIOptions ?? []
350+
var swiftCompilerFlags = swiftSDK.toolset.knownTools[.swiftCompiler]?.extraCLIOptions ?? []
351+
352+
if let linker = swiftSDK.toolset.knownTools[.linker]?.path {
353+
swiftCompilerFlags += ["-ld-path=\(linker)"]
354+
}
351355

352356
guard let sdkDir = swiftSDK.pathsConfiguration.sdkRootPath else {
353357
if triple.isWindows() {

Tests/BuildTests/BuildPlanTests.swift

+7-3
Original file line numberDiff line numberDiff line change
@@ -3700,7 +3700,7 @@ final class BuildPlanTests: XCTestCase {
37003700
.cxxCompiler: .init(extraCLIOptions: [jsonFlag(tool: .cxxCompiler)]),
37013701
.swiftCompiler: .init(extraCLIOptions: [jsonFlag(tool: .swiftCompiler)]),
37023702
.librarian: .init(path: "/fake/toolchain/usr/bin/librarian"),
3703-
.linker: .init(extraCLIOptions: [jsonFlag(tool: .linker)]),
3703+
.linker: .init(path: "/fake/toolchain/usr/bin/linker", extraCLIOptions: [jsonFlag(tool: .linker)]),
37043704
],
37053705
rootPaths: try UserToolchain.default.swiftSDK.toolset.rootPaths)
37063706
let targetTriple = try Triple("armv7em-unknown-none-macho")
@@ -3781,7 +3781,9 @@ final class BuildPlanTests: XCTestCase {
37813781
// Compile Swift Target
37823782
let exeCompileArguments = try result.target(for: "exe").swiftTarget().compileArguments()
37833783
let exeCompileArgumentsPattern: [StringPattern] = [
3784-
jsonFlag(tool: .swiftCompiler), "-g", cliFlag(tool: .swiftCompiler),
3784+
jsonFlag(tool: .swiftCompiler),
3785+
"-ld-path=/fake/toolchain/usr/bin/linker",
3786+
"-g", cliFlag(tool: .swiftCompiler),
37853787
.anySequence,
37863788
"-Xcc", jsonFlag(tool: .cCompiler), "-Xcc", "-g", "-Xcc", cliFlag(tool: .cCompiler),
37873789
// TODO: Pass -Xcxx flags to swiftc (#6491)
@@ -3804,7 +3806,9 @@ final class BuildPlanTests: XCTestCase {
38043806
// Link Product
38053807
let exeLinkArguments = try result.buildProduct(for: "exe").linkArguments()
38063808
let exeLinkArgumentsPattern: [StringPattern] = [
3807-
jsonFlag(tool: .swiftCompiler), "-g", cliFlag(tool: .swiftCompiler),
3809+
jsonFlag(tool: .swiftCompiler),
3810+
"-ld-path=/fake/toolchain/usr/bin/linker",
3811+
"-g", cliFlag(tool: .swiftCompiler),
38083812
.anySequence,
38093813
"-Xlinker", jsonFlag(tool: .linker), "-Xlinker", cliFlag(tool: .linker),
38103814
]

0 commit comments

Comments
 (0)