Skip to content

Distro-overridable default Unix linker #1448

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

Closed
Closed
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
5 changes: 5 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,18 @@ let package = Package(
.target(name: "CSwiftScan",
exclude: [ "CMakeLists.txt" ]),

/// Header containing distribution-configurable defaults.
.target(name: "DriverDefaults",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We must also implement the building of this module in our CMake build infrastructure.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

heh, I thought I put that comment in my draft notes. Yeah, I put up the draft to get feedback on the approach at the moment. :)

exclude: [ "CMakeLists.txt" ]),

/// The driver library.
.target(
name: "SwiftDriver",
dependencies: [
"SwiftOptions",
.product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core"),
"CSwiftScan",
"DriverDefaults",
.product(name: "Yams", package: "yams"),
],
exclude: ["CMakeLists.txt"]),
Expand Down
6 changes: 6 additions & 0 deletions Sources/DriverDefaults/constants.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include "constants.h"

#define Q(X) #X
#define QUOTE(X) Q(X)

const char * defaultLinker = QUOTE(SWIFT_DEFAULT_LINKER);
16 changes: 16 additions & 0 deletions Sources/DriverDefaults/include/constants.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#ifndef DRIVER_DEFAULTS_CONSTANTS_H
#define DRIVER_DEFAULTS_CONSTANTS_H

/// Default Linker
///
/// This macro allows configuring the Swift driver build to specify a default
/// linker, overriding the existing heuristic.
///
/// NOTE: Darwin and Windows use clang as the linker. This does not affect the
/// linker that the clang linker selects.
#ifndef SWIFT_DEFAULT_LINKER
#define SWIFT_DEFAULT_LINKER
#endif
const char *defaultLinker;

#endif // DRIVER_DEFAULTS_CONSTANTS_H
4 changes: 4 additions & 0 deletions Sources/DriverDefaults/include/module.modulemap
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module DriverDefaults {
header "constants.h"
export *
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,19 @@
//===----------------------------------------------------------------------===//

import SwiftOptions
import DriverDefaults

import func TSCBasic.lookupExecutablePath
import struct TSCBasic.AbsolutePath

extension GenericUnixToolchain {
private func defaultLinker(for targetTriple: Triple) -> String? {
let constantDefaultLinker = String(cString: DriverDefaults.defaultLinker)
if !constantDefaultLinker.isEmpty {
print("Using linker: \(constantDefaultLinker)")
return constantDefaultLinker
}

if targetTriple.os == .openbsd || targetTriple.os == .freeBSD ||
targetTriple.environment == .android {
return "lld"
Expand Down