Skip to content
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

Forward --ld-path to linker driver #1416

Merged
merged 2 commits into from Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions Sources/SwiftDriver/Jobs/DarwinToolchain+LinkerSupport.swift
Expand Up @@ -181,6 +181,8 @@ extension DarwinToolchain {
commandLine.appendFlag("-fuse-ld=\(arg.asSingle)")
}

try commandLine.appendLast(.ldPath, from: &parsedOptions)

let fSystemArgs = parsedOptions.arguments(for: .F, .Fsystem)
for opt in fSystemArgs {
commandLine.appendFlag(.F)
Expand Down
Expand Up @@ -101,6 +101,8 @@ extension GenericUnixToolchain {
}
}

try commandLine.appendLast(.ldPath, from: &parsedOptions)

// Configure the toolchain.
//
// By default use the system `clang` to perform the link. We use `clang` for
Expand Down
Expand Up @@ -43,6 +43,8 @@ extension WebAssemblyToolchain {
commandLine.appendFlag("-fuse-ld=\(linkerArg)")
}

try commandLine.appendLast(.ldPath, from: &parsedOptions)

// Configure the toolchain.
//
// By default use the system `clang` to perform the link. We use `clang` for
Expand Down
2 changes: 2 additions & 0 deletions Sources/SwiftDriver/Jobs/WindowsToolchain+LinkerSupport.swift
Expand Up @@ -105,6 +105,8 @@ extension WindowsToolchain {
commandLine.appendFlag("-fuse-ld=lld")
}

try commandLine.appendLast(.ldPath, from: &parsedOptions)

switch lto {
case .some(.llvmThin):
commandLine.appendFlag("-flto=thin")
Expand Down
4 changes: 3 additions & 1 deletion Sources/SwiftOptions/Options.swift
Expand Up @@ -530,6 +530,7 @@ extension Option {
public static let json_: Option = Option("--json", .flag, alias: Option.json, attributes: [.noDriver], helpText: "Print output in JSON format.")
public static let j: Option = Option("-j", .joinedOrSeparate, attributes: [.doesNotAffectIncrementalBuild], metaVar: "<n>", helpText: "Number of commands to execute in parallel")
public static let LEQ: Option = Option("-L=", .joined, alias: Option.L, attributes: [.frontend, .doesNotAffectIncrementalBuild, .argumentIsPath], group: .linkerOption)
public static let ldPath: Option = Option("--ld-path=", .joined, attributes: [.doesNotAffectIncrementalBuild, .argumentIsPath], helpText: "Specifies the path to the linker to be used")
public static let libc: Option = Option("-libc", .separate, attributes: [], helpText: "libc runtime library to use")
public static let libraryLevelEQ: Option = Option("-library-level=", .joined, alias: Option.libraryLevel, attributes: [.helpHidden, .frontend, .moduleInterface], metaVar: "<level>")
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)")
Expand Down Expand Up @@ -757,7 +758,7 @@ extension Option {
public static let useInterfaceForModule: Option = Option("-use-interface-for-module", .separate, attributes: [.noDriver], metaVar: "<name>", helpText: "Prefer loading these modules via interface")
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")
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")
public static let useLd: Option = Option("-use-ld=", .joined, attributes: [.doesNotAffectIncrementalBuild], helpText: "Specifies the linker to be used")
public static let useLd: Option = Option("-use-ld=", .joined, attributes: [.doesNotAffectIncrementalBuild], helpText: "Specifies the flavor of the linker to be used")
public static let useMalloc: Option = Option("-use-malloc", .flag, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Allocate internal data structures using malloc (for memory debugging)")
public static let useStaticResourceDir: Option = Option("-use-static-resource-dir", .flag, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Use resources in the static resource directory")
public static let useTabs: Option = Option("-use-tabs", .flag, attributes: [.noInteractive, .noBatch, .indent], helpText: "Use tabs for indentation.", group: .codeFormatting)
Expand Down Expand Up @@ -1325,6 +1326,7 @@ extension Option {
Option.json_,
Option.j,
Option.LEQ,
Option.ldPath,
Option.libc,
Option.libraryLevelEQ,
Option.libraryLevel,
Expand Down
3 changes: 2 additions & 1 deletion Tests/SwiftDriverTests/SwiftDriverTests.swift
Expand Up @@ -1679,7 +1679,7 @@ final class SwiftDriverTests: XCTestCase {

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

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

Expand Down