Skip to content

Commit ba8ed95

Browse files
authored
Add support for Musl libc (#1385)
Since Musl is sufficiently different from Glibc (see https://wiki.musl-libc.org/functional-differences-from-glibc.html), it requires a different import, which now should be applied to files that have `import Glibc` in them.
1 parent b9cd96b commit ba8ed95

File tree

6 files changed

+17
-5
lines changed

6 files changed

+17
-5
lines changed

Sources/SwiftDriver/Driver/ToolExecutionDelegate.swift

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import ucrt
1717
import WinSDK
1818
#elseif canImport(Glibc)
1919
import Glibc
20+
#elseif canImport(Musl)
21+
import Musl
2022
#else
2123
#error("Missing libc or equivalent")
2224
#endif

Sources/SwiftDriver/SwiftScan/Loader.swift

+4-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ import var Foundation.NSLocalizedDescriptionKey
1717
import WinSDK
1818
#elseif os(iOS) || os(macOS) || os(tvOS) || os(watchOS)
1919
import Darwin
20-
#else
20+
#elseif canImport(Glibc)
2121
import Glibc
22+
#elseif canImport(Musl)
23+
import Musl
2224
#endif
2325

2426
internal enum Loader {
@@ -130,7 +132,7 @@ extension Loader.Flags {
130132
Loader.Flags(rawValue: 0)
131133
}
132134

133-
#if os(Linux)
135+
#if os(Linux) && canImport(Glibc)
134136
public static var deepBind: Loader.Flags {
135137
Loader.Flags(rawValue: RTLD_DEEPBIND)
136138
}

Sources/SwiftDriver/Utilities/DateAdditions.swift

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@
1414
import WinSDK
1515
#elseif os(iOS) || os(macOS) || os(tvOS) || os(watchOS)
1616
import Darwin
17-
#else
17+
#elseif canImport(Glibc)
1818
import Glibc
19+
#elseif canImport(Musl)
20+
import Musl
1921
#endif
2022

2123
/// Represents a time point value with nanosecond precision.

Sources/SwiftDriver/Utilities/System.swift

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
import Darwin
1515
#elseif canImport(Glibc)
1616
import Glibc
17+
#elseif canImport(Musl)
18+
import Musl
1719
#endif
1820

1921
func argumentNeedsQuoting(_ argument: String) -> Bool {

Sources/swift-build-sdk-interfaces/main.swift

+3-1
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ import SwiftDriver
1515
import CRT
1616
#elseif os(iOS) || os(macOS) || os(tvOS) || os(watchOS)
1717
import Darwin
18-
#else
18+
#elseif canImport(Glibc)
1919
import Glibc
20+
#elseif canImport(Musl)
21+
import Musl
2022
#endif
2123

2224
import TSCBasic // <<<

Sources/swift-driver/main.swift

+3-1
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ import SwiftDriver
1515
import CRT
1616
#elseif os(iOS) || os(macOS) || os(tvOS) || os(watchOS)
1717
import Darwin
18-
#else
18+
#elseif canImport(Glibc)
1919
import Glibc
20+
#elseif canImport(Musl)
21+
import Musl
2022
#endif
2123

2224
import Dispatch

0 commit comments

Comments
 (0)