Skip to content

Commit 6bf6442

Browse files
authored
Merge pull request swiftlang#1549 from al45tair/eng/PR-123442522
Update driver for fully static Linux.
2 parents 7a2e187 + 7b22cc6 commit 6bf6442

File tree

3 files changed

+35
-9
lines changed

3 files changed

+35
-9
lines changed

Sources/SwiftDriver/Jobs/GenericUnixToolchain+LinkerSupport.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ import struct TSCBasic.AbsolutePath
1818
extension GenericUnixToolchain {
1919
private func defaultLinker(for targetTriple: Triple) -> String? {
2020
if targetTriple.os == .openbsd || targetTriple.os == .freeBSD ||
21-
targetTriple.environment == .android {
21+
targetTriple.environment == .android ||
22+
targetTriple.isFullyStaticLinux {
2223
return "lld"
2324
}
2425

Sources/SwiftDriver/Utilities/Triple+Platforms.swift

+15-1
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,21 @@ extension Triple {
292292
return conflatingDarwin ? "darwin" : darwinPlatform.platformName
293293

294294
case .linux:
295-
return environment == .android ? "android" : "linux"
295+
switch environment {
296+
case .musl:
297+
// The triple for linux-static is <arch>-swift-linux-musl, to distinguish
298+
// it from a "normal" musl set-up (ala Alpine).
299+
if vendor == .swift {
300+
return "linux-static"
301+
}
302+
fallthrough
303+
case .musl, .musleabihf, .musleabi:
304+
return "musl"
305+
case .android:
306+
return "android"
307+
default:
308+
return "linux"
309+
}
296310
case .freeBSD:
297311
return "freebsd"
298312
case .openbsd:

Sources/SwiftDriver/Utilities/Triple.swift

+18-7
Original file line numberDiff line numberDiff line change
@@ -1032,6 +1032,7 @@ extension Triple {
10321032
case mesa
10331033
case suse
10341034
case openEmbedded = "oe"
1035+
case swift
10351036

10361037
fileprivate static func parse(_ component: Substring) -> Triple.Vendor? {
10371038
switch component {
@@ -1067,6 +1068,8 @@ extension Triple {
10671068
return .suse
10681069
case "oe":
10691070
return .openEmbedded
1071+
case "swift":
1072+
return .swift
10701073
default:
10711074
return nil
10721075
}
@@ -1711,13 +1714,21 @@ fileprivate extension Array {
17111714
}
17121715
}
17131716

1714-
// MARK: - Linker support
1717+
// MARK: - Fully static Linux support
17151718

17161719
extension Triple {
1717-
/// Returns `true` if a given triple supports producing fully statically linked executables by providing `-static`
1718-
/// flag to the linker. This implies statically linking platform's libc, and of those that Swift supports currently
1719-
/// only Musl allows that reliably.
1720-
var supportsStaticExecutables: Bool {
1721-
self.environment == .musl
1722-
}
1720+
/// Returns `true` if this is the triple for Swift's fully statically
1721+
/// linked Linux target.
1722+
var isFullyStaticLinux: Bool {
1723+
self.vendor == .swift && self.environment == .musl
1724+
}
1725+
1726+
/// Returns `true` if a given triple supports producing fully
1727+
/// statically linked executables by providing `-static` flag to
1728+
/// the linker. This implies statically linking platform's libc,
1729+
/// and of those that Swift supports currently only Musl allows
1730+
/// that reliably.
1731+
var supportsStaticExecutables: Bool {
1732+
self.isFullyStaticLinux
1733+
}
17231734
}

0 commit comments

Comments
 (0)