Skip to content

Commit 85fdcac

Browse files
authored
Merge pull request #20 from the-braveknight/main
Fix building against Musl instead of glibc
2 parents 3a0b240 + 3d09585 commit 85fdcac

File tree

4 files changed

+12
-3
lines changed

4 files changed

+12
-3
lines changed

Sources/Socket/System/CInterop.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public extension CInterop {
4848
typealias SocketAddressFamily = sa_family_t
4949

5050
/// Socket Type
51-
#if os(Linux)
51+
#if os(Linux) && canImport(Glibc)
5252
typealias SocketType = __socket_type
5353
#else
5454
typealias SocketType = CInt

Sources/Socket/System/Constants.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,13 @@ internal var _O_RDWR: CInt { O_RDWR }
3131

3232
#if !os(Windows)
3333
// TODO: API?
34+
#if canImport(Glibc) || canImport(Darwin)
3435
@_alwaysEmitIntoClient
3536
internal var _O_ACCMODE: CInt { O_ACCMODE }
37+
#elseif canImport(Musl)
38+
@_alwaysEmitIntoClient
39+
internal var _O_ACCMODE: CInt { 03 } // O_ACCMODE equivalent for musl
40+
#endif
3641

3742
@_alwaysEmitIntoClient
3843
internal var _O_NONBLOCK: CInt { O_NONBLOCK }

Sources/Socket/System/SocketFlags.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,18 @@ public struct SocketFlags: OptionSet, Hashable, Codable, Sendable {
1313
@_alwaysEmitIntoClient
1414
public init(rawValue: CInt) { self.rawValue = rawValue }
1515

16-
#if os(Linux)
16+
#if os(Linux) && canImport(Glibc)
1717
private init(_ cValue: CInterop.SocketType) {
1818
self.init(rawValue: numericCast(cValue.rawValue))
1919
}
2020
#elseif os(Android)
2121
private init(_ cValue: CInt) {
2222
self.init(rawValue: cValue)
2323
}
24+
#else
25+
private init(_ cValue: CInterop.SocketType) {
26+
self.init(rawValue: cValue)
27+
}
2428
#endif
2529
}
2630

Sources/Socket/System/SocketType.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public struct SocketType: RawRepresentable, Hashable, Sendable {
1313
public init(rawValue: CInt) { self.rawValue = rawValue }
1414

1515
private init(_ cValue: CInterop.SocketType) {
16-
#if os(Linux)
16+
#if os(Linux) && canImport(Glibc)
1717
self.init(rawValue: numericCast(cValue.rawValue))
1818
#else
1919
self.init(rawValue: cValue)

0 commit comments

Comments
 (0)