Skip to content

Commit 66f1c0d

Browse files
authored
Add support for Musl libc with canImport(Musl) checks (#772)
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. Musl is a low footprint libc that's used in Linux distributions such as Alpine Linux, which allows producing fairly small container images. Additionally, unlike Glibc, musl allows full static linking, meaning apps can be easily distributed to an arbitrary Linux distribution that may have a version of Glibc incompatible with the one that Swift is usually built with or no Glibc installed at all.
1 parent d261b0d commit 66f1c0d

File tree

7 files changed

+17
-3
lines changed

7 files changed

+17
-3
lines changed

Sources/LanguageServerProtocolJSONRPC/DisableSigpipe.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@
1313

1414
#if canImport(Glibc)
1515
import Glibc
16+
#elseif canImport(Musl)
17+
import Musl
1618
#endif
1719

18-
#if os(Linux) || os(Android)
20+
#if canImport(Glibc) || canImport(Musl)
1921
// This is a lazily initialised global variable that when read for the first time, will ignore SIGPIPE.
2022
private let globallyIgnoredSIGPIPE: Bool = {
2123
/* no F_SETNOSIGPIPE on Linux :( */
22-
_ = Glibc.signal(SIGPIPE, SIG_IGN)
24+
_ = signal(SIGPIPE, SIG_IGN)
2325
return true
2426
}()
2527

Sources/SKSupport/dlopen.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ import CRT
1515
import WinSDK
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
public final class DLHandle {

Sources/SourceKitD/SKDRequestArray.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
import Csourcekitd
1414
#if canImport(Glibc)
1515
import Glibc
16+
#elseif canImport(Musl)
17+
import Musl
1618
#elseif canImport(CRT)
1719
import CRT
1820
#endif

Sources/SourceKitD/SKDRequestDictionary.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
import Csourcekitd
1414
#if canImport(Glibc)
1515
import Glibc
16+
#elseif canImport(Musl)
17+
import Musl
1618
#elseif canImport(CRT)
1719
import CRT
1820
#endif

Sources/SourceKitD/SKDResponse.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
import Csourcekitd
1414
#if canImport(Glibc)
1515
import Glibc
16+
#elseif canImport(Musl)
17+
import Musl
1618
#elseif canImport(CRT)
1719
import CRT
1820
#endif

Sources/SourceKitD/SKDResponseArray.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
import Csourcekitd
1414
#if canImport(Glibc)
1515
import Glibc
16+
#elseif canImport(Musl)
17+
import Musl
1618
#elseif canImport(CRT)
1719
import CRT
1820
#endif

Sources/SourceKitD/SKDResponseDictionary.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
import Csourcekitd
1414
#if canImport(Glibc)
1515
import Glibc
16+
#elseif canImport(Musl)
17+
import Musl
1618
#elseif canImport(CRT)
1719
import CRT
1820
#endif

0 commit comments

Comments
 (0)