Skip to content

Update driver for fully static Linux. #1549

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 2 commits into from
Mar 14, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ import struct TSCBasic.AbsolutePath
extension GenericUnixToolchain {
private func defaultLinker(for targetTriple: Triple) -> String? {
if targetTriple.os == .openbsd || targetTriple.os == .freeBSD ||
targetTriple.environment == .android {
targetTriple.environment == .android ||
targetTriple.isFullyStaticLinux {
return "lld"
}

Expand Down
16 changes: 15 additions & 1 deletion Sources/SwiftDriver/Utilities/Triple+Platforms.swift
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,21 @@ extension Triple {
return conflatingDarwin ? "darwin" : darwinPlatform.platformName

case .linux:
return environment == .android ? "android" : "linux"
switch environment {
case .musl:
// The triple for linux-static is <arch>-swift-linux-musl, to distinguish
// it from a "normal" musl set-up (ala Alpine).
if vendor == .swift {
return "linux-static"
}
fallthrough
case .musl, .musleabihf, .musleabi:
return "musl"
case .android:
return "android"
default:
return "linux"
}
case .freeBSD:
return "freebsd"
case .openbsd:
Expand Down
25 changes: 18 additions & 7 deletions Sources/SwiftDriver/Utilities/Triple.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1028,6 +1028,7 @@ extension Triple {
case mesa
case suse
case openEmbedded = "oe"
case swift

fileprivate static func parse(_ component: Substring) -> Triple.Vendor? {
switch component {
Expand Down Expand Up @@ -1063,6 +1064,8 @@ extension Triple {
return .suse
case "oe":
return .openEmbedded
case "swift":
return .swift
default:
return nil
}
Expand Down Expand Up @@ -1706,13 +1709,21 @@ fileprivate extension Array {
}
}

// MARK: - Linker support
// MARK: - Fully static Linux support

extension Triple {
/// Returns `true` if a given triple supports producing fully statically linked executables by providing `-static`
/// flag to the linker. This implies statically linking platform's libc, and of those that Swift supports currently
/// only Musl allows that reliably.
var supportsStaticExecutables: Bool {
self.environment == .musl
}
/// Returns `true` if this is the triple for Swift's fully statically
/// linked Linux target.
var isFullyStaticLinux: Bool {
self.vendor == .swift && self.environment == .musl
}

/// Returns `true` if a given triple supports producing fully
/// statically linked executables by providing `-static` flag to
/// the linker. This implies statically linking platform's libc,
/// and of those that Swift supports currently only Musl allows
/// that reliably.
var supportsStaticExecutables: Bool {
self.isFullyStaticLinux
}
}