Skip to content

Swift SDKs: fix toolset.linker.path not passed to -ld-path #6719

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Sep 19, 2023
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
6 changes: 5 additions & 1 deletion Sources/PackageModel/UserToolchain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,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 @@ -3607,7 +3607,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 @@ -3688,7 +3688,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 @@ -3711,7 +3713,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