Skip to content

Commit

Permalink
Swift SDKs: fix toolset.linker.path not passed to -ld-path
Browse files Browse the repository at this point in the history
This reverts commit 57d0a55 and PR #6939.

Now that swiftlang/swift-driver#1447 and its 5.10 counterpart swiftlang/swift-driver#1454 were merged, we can reapply the fix for Swift SDKs linker metadata not being handled.
  • Loading branch information
MaxDesiatov committed Oct 18, 2023
1 parent 55e79b1 commit 13b9264
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
6 changes: 5 additions & 1 deletion Sources/PackageModel/UserToolchain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,11 @@ public final class UserToolchain: Toolchain {
swiftSDK: SwiftSDK,
environment: EnvironmentVariables
) throws -> [String] {
let swiftCompilerFlags = swiftSDK.toolset.knownTools[.swiftCompiler]?.extraCLIOptions ?? []
var swiftCompilerFlags = swiftSDK.toolset.knownTools[.swiftCompiler]?.extraCLIOptions ?? []

if let linker = swiftSDK.toolset.knownTools[.linker]?.path {
swiftCompilerFlags += ["-ld-path=\(linker)"]
}

guard let sdkDir = swiftSDK.pathsConfiguration.sdkRootPath else {
if triple.isWindows() {
Expand Down
10 changes: 7 additions & 3 deletions Tests/BuildTests/BuildPlanTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3716,7 +3716,7 @@ final class BuildPlanTests: XCTestCase {
.cxxCompiler: .init(extraCLIOptions: [jsonFlag(tool: .cxxCompiler)]),
.swiftCompiler: .init(extraCLIOptions: [jsonFlag(tool: .swiftCompiler)]),
.librarian: .init(path: "/fake/toolchain/usr/bin/librarian"),
.linker: .init(extraCLIOptions: [jsonFlag(tool: .linker)]),
.linker: .init(path: "/fake/toolchain/usr/bin/linker", extraCLIOptions: [jsonFlag(tool: .linker)]),
],
rootPaths: try UserToolchain.default.swiftSDK.toolset.rootPaths)
let targetTriple = try Triple("armv7em-unknown-none-macho")
Expand Down Expand Up @@ -3797,7 +3797,9 @@ final class BuildPlanTests: XCTestCase {
// Compile Swift Target
let exeCompileArguments = try result.target(for: "exe").swiftTarget().compileArguments()
let exeCompileArgumentsPattern: [StringPattern] = [
jsonFlag(tool: .swiftCompiler), "-g", cliFlag(tool: .swiftCompiler),
jsonFlag(tool: .swiftCompiler),
"-ld-path=/fake/toolchain/usr/bin/linker",
"-g", cliFlag(tool: .swiftCompiler),
.anySequence,
"-Xcc", jsonFlag(tool: .cCompiler), "-Xcc", "-g", "-Xcc", cliFlag(tool: .cCompiler),
// TODO: Pass -Xcxx flags to swiftc (#6491)
Expand All @@ -3820,7 +3822,9 @@ final class BuildPlanTests: XCTestCase {
// Link Product
let exeLinkArguments = try result.buildProduct(for: "exe").linkArguments()
let exeLinkArgumentsPattern: [StringPattern] = [
jsonFlag(tool: .swiftCompiler), "-g", cliFlag(tool: .swiftCompiler),
jsonFlag(tool: .swiftCompiler),
"-ld-path=/fake/toolchain/usr/bin/linker",
"-g", cliFlag(tool: .swiftCompiler),
.anySequence,
"-Xlinker", jsonFlag(tool: .linker), "-Xlinker", cliFlag(tool: .linker),
]
Expand Down

0 comments on commit 13b9264

Please sign in to comment.