Skip to content

Commit 4d7f6a0

Browse files
authored
Forward --ld-path to linker driver (#1416)
This PR introduces an `--ld-path` option, which is forwarded to the Clang linker-driver option with the same name. This change is required to support the `toolset.linker.path` option in [SE-0387](https://github.com/apple/swift-evolution/blob/main/proposals/0387-cross-compilation-destinations.md). ## See also Upstream: swiftlang/swift#67956. Downstream: swiftlang/swift-package-manager#6719.
1 parent 3e4d4c0 commit 4d7f6a0

6 files changed

+13
-2
lines changed

Sources/SwiftDriver/Jobs/DarwinToolchain+LinkerSupport.swift

+2
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,8 @@ extension DarwinToolchain {
181181
commandLine.appendFlag("-fuse-ld=\(arg.asSingle)")
182182
}
183183

184+
try commandLine.appendLast(.ldPath, from: &parsedOptions)
185+
184186
let fSystemArgs = parsedOptions.arguments(for: .F, .Fsystem)
185187
for opt in fSystemArgs {
186188
commandLine.appendFlag(.F)

Sources/SwiftDriver/Jobs/GenericUnixToolchain+LinkerSupport.swift

+2
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ extension GenericUnixToolchain {
101101
}
102102
}
103103

104+
try commandLine.appendLast(.ldPath, from: &parsedOptions)
105+
104106
// Configure the toolchain.
105107
//
106108
// By default use the system `clang` to perform the link. We use `clang` for

Sources/SwiftDriver/Jobs/WebAssemblyToolchain+LinkerSupport.swift

+2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ extension WebAssemblyToolchain {
4343
commandLine.appendFlag("-fuse-ld=\(linkerArg)")
4444
}
4545

46+
try commandLine.appendLast(.ldPath, from: &parsedOptions)
47+
4648
// Configure the toolchain.
4749
//
4850
// By default use the system `clang` to perform the link. We use `clang` for

Sources/SwiftDriver/Jobs/WindowsToolchain+LinkerSupport.swift

+2
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ extension WindowsToolchain {
105105
commandLine.appendFlag("-fuse-ld=lld")
106106
}
107107

108+
try commandLine.appendLast(.ldPath, from: &parsedOptions)
109+
108110
switch lto {
109111
case .some(.llvmThin):
110112
commandLine.appendFlag("-flto=thin")

Sources/SwiftOptions/Options.swift

+3-1
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,7 @@ extension Option {
531531
public static let json_: Option = Option("--json", .flag, alias: Option.json, attributes: [.noDriver], helpText: "Print output in JSON format.")
532532
public static let j: Option = Option("-j", .joinedOrSeparate, attributes: [.doesNotAffectIncrementalBuild], metaVar: "<n>", helpText: "Number of commands to execute in parallel")
533533
public static let LEQ: Option = Option("-L=", .joined, alias: Option.L, attributes: [.frontend, .doesNotAffectIncrementalBuild, .argumentIsPath], group: .linkerOption)
534+
public static let ldPath: Option = Option("--ld-path=", .joined, attributes: [.helpHidden, .doesNotAffectIncrementalBuild, .argumentIsPath], helpText: "Specifies the path to the linker to be used")
534535
public static let libc: Option = Option("-libc", .separate, attributes: [], helpText: "libc runtime library to use")
535536
public static let libraryLevelEQ: Option = Option("-library-level=", .joined, alias: Option.libraryLevel, attributes: [.helpHidden, .frontend, .moduleInterface], metaVar: "<level>")
536537
public static let libraryLevel: Option = Option("-library-level", .separate, attributes: [.helpHidden, .frontend, .moduleInterface], metaVar: "<level>", helpText: "Library distribution level 'api', 'spi' or 'other' (the default)")
@@ -758,7 +759,7 @@ extension Option {
758759
public static let useInterfaceForModule: Option = Option("-use-interface-for-module", .separate, attributes: [.noDriver], metaVar: "<name>", helpText: "Prefer loading these modules via interface")
759760
public static let useInterfaceForModule_: Option = Option("--use-interface-for-module", .separate, alias: Option.useInterfaceForModule, attributes: [.noDriver], metaVar: "<name>", helpText: "Prefer loading these modules via interface")
760761
public static let useJit: Option = Option("-use-jit", .flag, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Register Objective-C classes as if the JIT were in use")
761-
public static let useLd: Option = Option("-use-ld=", .joined, attributes: [.doesNotAffectIncrementalBuild], helpText: "Specifies the linker to be used")
762+
public static let useLd: Option = Option("-use-ld=", .joined, attributes: [.doesNotAffectIncrementalBuild], helpText: "Specifies the flavor of the linker to be used")
762763
public static let useMalloc: Option = Option("-use-malloc", .flag, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Allocate internal data structures using malloc (for memory debugging)")
763764
public static let useStaticResourceDir: Option = Option("-use-static-resource-dir", .flag, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Use resources in the static resource directory")
764765
public static let useTabs: Option = Option("-use-tabs", .flag, attributes: [.noInteractive, .noBatch, .indent], helpText: "Use tabs for indentation.", group: .codeFormatting)
@@ -1327,6 +1328,7 @@ extension Option {
13271328
Option.json_,
13281329
Option.j,
13291330
Option.LEQ,
1331+
Option.ldPath,
13301332
Option.libc,
13311333
Option.libraryLevelEQ,
13321334
Option.libraryLevel,

Tests/SwiftDriverTests/SwiftDriverTests.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -1679,7 +1679,7 @@ final class SwiftDriverTests: XCTestCase {
16791679

16801680
do {
16811681
// macOS target
1682-
var driver = try Driver(args: commonArgs + ["-emit-library", "-target", "x86_64-apple-macosx10.15", "-Onone", "-use-ld=foo"], env: env)
1682+
var driver = try Driver(args: commonArgs + ["-emit-library", "-target", "x86_64-apple-macosx10.15", "-Onone", "-use-ld=foo", "--ld-path=/bar/baz"], env: env)
16831683
let plannedJobs = try driver.planBuild()
16841684

16851685
XCTAssertEqual(3, plannedJobs.count)
@@ -1691,6 +1691,7 @@ final class SwiftDriverTests: XCTestCase {
16911691
let cmd = linkJob.commandLine
16921692
XCTAssertTrue(cmd.contains(.flag("-dynamiclib")))
16931693
XCTAssertTrue(cmd.contains(.flag("-fuse-ld=foo")))
1694+
XCTAssertTrue(cmd.contains(.joinedOptionAndPath("--ld-path=", try VirtualPath(path: "/bar/baz"))))
16941695
XCTAssertTrue(cmd.contains(.flag("--target=x86_64-apple-macosx10.15")))
16951696
XCTAssertEqual(linkJob.outputs[0].file, try VirtualPath(path: "libTest.dylib"))
16961697

0 commit comments

Comments
 (0)