Skip to content

Commit

Permalink
Merge pull request #1549 from al45tair/eng/PR-123442522
Browse files Browse the repository at this point in the history
Update driver for fully static Linux.
  • Loading branch information
al45tair committed Mar 14, 2024
2 parents 7a2e187 + 7b22cc6 commit 6bf6442
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 9 deletions.
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
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
Expand Up @@ -1032,6 +1032,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 @@ -1067,6 +1068,8 @@ extension Triple {
return .suse
case "oe":
return .openEmbedded
case "swift":
return .swift
default:
return nil
}
Expand Down Expand Up @@ -1711,13 +1714,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
}
}

0 comments on commit 6bf6442

Please sign in to comment.