Skip to content

Commit e51585a

Browse files
etcwildecthielen
authored andcommitted
[main] Get Swift-Foundation building against MUSL for Swift Static SDK (swiftlang#848)
* Get FoundationEssentials building Adding the missing musl imports to get FoundationEssentials building for the Swift static SDKs again. Also providing an option to disable building the macros. The macros aren't necessary for building the library and will not be run as part of the static SDK. No need to bloat the SDK or build times further. For Swift 6, the macros should be provided by the toolchain since the toolchain and SDK are current revlocked due to swiftmodules. * Get FoundationInternationalization building Adding the missing Musl imports to get FoundationInternationalization building for the static SDK.
1 parent 9e09ca4 commit e51585a

27 files changed

+67
-10
lines changed

Sources/FoundationEssentials/Calendar/Calendar.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ internal import os
1616
import Android
1717
#elseif canImport(Glibc)
1818
import Glibc
19+
#elseif canImport(Musl)
20+
import Musl
1921
#elseif canImport(CRT)
2022
import CRT
2123
#elseif os(WASI)

Sources/FoundationEssentials/Calendar/Calendar_Gregorian.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ internal import os
1616
import Android
1717
#elseif canImport(Glibc)
1818
import Glibc
19+
#elseif canImport(Musl)
20+
import Musl
1921
#elseif canImport(CRT)
2022
import CRT
2123
#elseif os(WASI)

Sources/FoundationEssentials/Data/Data+Reading.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ import Darwin
2222
import Android
2323
#elseif canImport(Glibc)
2424
import Glibc
25+
#elseif canImport(Musl)
26+
import Musl
2527
#elseif os(Windows)
2628
import CRT
2729
import WinSDK
@@ -32,7 +34,7 @@ import WASILibc
3234
func _fgetxattr(_ fd: Int32, _ name: UnsafePointer<CChar>!, _ value: UnsafeMutableRawPointer!, _ size: Int, _ position: UInt32, _ options: Int32) -> Int {
3335
#if canImport(Darwin)
3436
return fgetxattr(fd, name, value, size, position, options)
35-
#elseif canImport(Glibc)
37+
#elseif canImport(Glibc) || canImport(Musl)
3638
return fgetxattr(fd, name, value, size)
3739
#else
3840
return -1

Sources/FoundationEssentials/Data/Data+Writing.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import Android
2424
import unistd
2525
#elseif canImport(Glibc)
2626
import Glibc
27+
#elseif canImport(Musl)
28+
import Musl
2729
#elseif os(Windows)
2830
import CRT
2931
import WinSDK
@@ -632,7 +634,7 @@ private func writeExtendedAttributes(fd: Int32, attributes: [String : Data]) {
632634
// Returns non-zero on error, but we ignore them
633635
#if canImport(Darwin)
634636
_ = fsetxattr(fd, key, valueBuf.baseAddress!, valueBuf.count, 0, 0)
635-
#elseif canImport(Glibc)
637+
#elseif canImport(Glibc) || canImport(Musl)
636638
_ = fsetxattr(fd, key, valueBuf.baseAddress!, valueBuf.count, 0)
637639
#endif
638640
}

Sources/FoundationEssentials/Date.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import Darwin
1616
import Bionic
1717
#elseif canImport(Glibc)
1818
import Glibc
19+
#elseif canImport(Musl)
20+
import Musl
1921
#elseif canImport(WinSDK)
2022
import WinSDK
2123
#elseif os(WASI)

Sources/FoundationEssentials/Decimal/Decimal+Math.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import Darwin
1616
import Android
1717
#elseif canImport(Glibc)
1818
import Glibc
19+
#elseif canImport(Musl)
20+
import Musl
1921
#elseif canImport(CRT)
2022
import CRT
2123
#elseif os(WASI)

Sources/FoundationEssentials/Error/CocoaError+FilePath.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import Darwin
1919
import Bionic
2020
#elseif canImport(Glibc)
2121
import Glibc
22+
#elseif canImport(Musl)
23+
import Musl
2224
#elseif os(Windows)
2325
import CRT
2426
import WinSDK

Sources/FoundationEssentials/Error/ErrorCodes+POSIX.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
@preconcurrency import Android
1515
#elseif canImport(Glibc)
1616
@preconcurrency import Glibc
17+
#elseif canImport(Musl)
18+
@preconcurrency import Musl
1719
#elseif canImport(Darwin)
1820
@preconcurrency import Darwin
1921
#elseif os(Windows)

Sources/FoundationEssentials/FileManager/FileManager+Basics.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import Darwin
1616
import Android
1717
#elseif canImport(Glibc)
1818
import Glibc
19+
#elseif canImport(Musl)
20+
import Musl
1921
#elseif os(Windows)
2022
import CRT
2123
import WinSDK

Sources/FoundationEssentials/FileManager/FileManager+Directories.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ import Android
2323
import unistd
2424
#elseif canImport(Glibc)
2525
import Glibc
26+
#elseif canImport(Musl)
27+
import Musl
2628
#elseif os(Windows)
2729
import CRT
2830
import WinSDK

Sources/FoundationEssentials/FileManager/FileManager+Files.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ import posix_filesystem
2323
#elseif canImport(Glibc)
2424
import Glibc
2525
internal import _FoundationCShims
26+
#elseif canImport(Musl)
27+
import Musl
28+
internal import _FoundationCShims
2629
#elseif os(Windows)
2730
import CRT
2831
import WinSDK

Sources/FoundationEssentials/FileManager/FileManager+SymbolicLinks.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import Android
1717
import unistd
1818
#elseif canImport(Glibc)
1919
import Glibc
20+
#elseif canImport(Musl)
21+
import Musl
2022
#elseif os(Windows)
2123
import CRT
2224
import WinSDK

Sources/FoundationEssentials/FileManager/FileManager+Utilities.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ import Android
2828
#elseif canImport(Glibc)
2929
import Glibc
3030
internal import _FoundationCShims
31+
#elseif canImport(Musl)
32+
import Musl
33+
internal import _FoundationCShims
3134
#elseif os(Windows)
3235
import CRT
3336
import WinSDK

Sources/FoundationEssentials/FileManager/FileOperations+Enumeration.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ import posix_filesystem.dirent
115115
#elseif canImport(Glibc)
116116
import Glibc
117117
internal import _FoundationCShims
118+
#elseif canImport(Musl)
119+
import Musl
118120
#elseif os(WASI)
119121
import WASILibc
120122
internal import _FoundationCShims
@@ -326,7 +328,7 @@ extension Sequence<_FTSSequence.Element> {
326328
struct _POSIXDirectoryContentsSequence: Sequence {
327329
#if canImport(Darwin)
328330
typealias DirectoryEntryPtr = UnsafeMutablePointer<DIR>
329-
#elseif os(Android) || canImport(Glibc) || os(WASI)
331+
#elseif os(Android) || canImport(Glibc) || canImport(Musl) || os(WASI)
330332
typealias DirectoryEntryPtr = OpaquePointer
331333
#endif
332334

Sources/FoundationEssentials/FileManager/FileOperations.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import Darwin
1616
import Android
1717
#elseif canImport(Glibc)
1818
import Glibc
19+
#elseif canImport(Musl)
20+
import Musl
1921
#elseif os(Windows)
2022
import CRT
2123
import WinSDK

Sources/FoundationEssentials/Formatting/BinaryInteger+NumericStringRepresentation.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import Darwin
1616
import Android
1717
#elseif canImport(Glibc)
1818
import Glibc
19+
#elseif canImport(Musl)
20+
import Musl
1921
#elseif os(Windows)
2022
import CRT
2123
#elseif os(WASI)

Sources/FoundationEssentials/LockedState.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ internal import C.os.lock
1919
import Bionic
2020
#elseif canImport(Glibc)
2121
import Glibc
22+
#elseif canImport(Musl)
23+
import Musl
2224
#elseif canImport(WinSDK)
2325
import WinSDK
2426
#endif
@@ -29,7 +31,7 @@ package struct LockedState<State> {
2931
private struct _Lock {
3032
#if canImport(os)
3133
typealias Primitive = os_unfair_lock
32-
#elseif os(Android) || canImport(Glibc)
34+
#elseif os(Android) || canImport(Glibc) || canImport(Musl)
3335
typealias Primitive = pthread_mutex_t
3436
#elseif canImport(WinSDK)
3537
typealias Primitive = SRWLOCK

Sources/FoundationEssentials/Platform.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ fileprivate let _pageSize: Int = Int(getpagesize())
3535
#elseif canImport(Glibc)
3636
import Glibc
3737
fileprivate let _pageSize: Int = Int(getpagesize())
38+
#elseif canImport(Musl)
39+
import Musl
40+
fileprivate let _pageSize: Int = Int(getpagesize())
3841
#elseif canImport(C)
3942
fileprivate let _pageSize: Int = Int(getpagesize())
4043
#endif // canImport(Darwin)

Sources/FoundationEssentials/ProcessInfo/ProcessInfo.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import Bionic
1919
import unistd
2020
#elseif canImport(Glibc)
2121
import Glibc
22+
#elseif canImport(Musl)
23+
import Musl
2224
#elseif os(Windows)
2325
import WinSDK
2426
#elseif os(WASI)
@@ -163,7 +165,7 @@ final class _ProcessInfo: Sendable {
163165
}
164166

165167
var userName: String {
166-
#if canImport(Darwin) || os(Android) || canImport(Glibc)
168+
#if canImport(Darwin) || os(Android) || canImport(Glibc) || canImport(Musl)
167169
// Darwin and Linux
168170
let (euid, _) = Platform.getUGIDs()
169171
if let upwd = getpwuid(euid),
@@ -201,7 +203,7 @@ final class _ProcessInfo: Sendable {
201203
#if os(Android) && (arch(i386) || arch(arm))
202204
// On LP32 Android, pw_gecos doesn't exist and is presumed to be NULL.
203205
return ""
204-
#elseif canImport(Darwin) || os(Android) || canImport(Glibc)
206+
#elseif canImport(Darwin) || os(Android) || canImport(Glibc) || canImport(Musl)
205207
let (euid, _) = Platform.getUGIDs()
206208
if let upwd = getpwuid(euid),
207209
let fullname = upwd.pointee.pw_gecos {

Sources/FoundationEssentials/PropertyList/OpenStepPlist.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import Darwin
1616
import Bionic
1717
#elseif canImport(Glibc)
1818
import Glibc
19+
#elseif canImport(Musl)
20+
import Musl
1921
#elseif os(WASI)
2022
import WASILibc
2123
#endif

Sources/FoundationEssentials/String/String+Path.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ internal import os
1616
import Android
1717
#elseif canImport(Glibc)
1818
import Glibc
19+
#elseif canImport(Musl)
20+
import Musl
1921
#elseif os(Windows)
2022
import WinSDK
2123
#elseif os(WASI)

Sources/FoundationEssentials/TimeZone/TimeZone_Cache.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import Darwin
1616
import unistd
1717
#elseif canImport(Glibc)
1818
import Glibc
19+
#elseif canImport(Musl)
20+
import Musl
1921
#elseif canImport(ucrt)
2022
import ucrt
2123
#endif

Sources/FoundationEssentials/_ThreadLocal.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import Darwin
1515
import Bionic
1616
#elseif canImport(Glibc)
1717
import Glibc
18+
#elseif canImport(Musl)
19+
import Musl
1820
#elseif canImport(WinSDK)
1921
import WinSDK
2022
#elseif canImport(threads_h)
@@ -24,7 +26,7 @@ internal import threads
2426
#endif
2527

2628
struct _ThreadLocal {
27-
#if canImport(Darwin) || os(Android) || canImport(Glibc)
29+
#if canImport(Darwin) || os(Android) || canImport(Glibc) || canImport(Musl)
2830
fileprivate typealias PlatformKey = pthread_key_t
2931
#elseif USE_TSS
3032
fileprivate typealias PlatformKey = tss_t
@@ -38,7 +40,7 @@ struct _ThreadLocal {
3840
fileprivate let key: PlatformKey
3941

4042
init() {
41-
#if canImport(Darwin) || os(Android) || canImport(Glibc)
43+
#if canImport(Darwin) || os(Android) || canImport(Glibc) || canImport(Musl)
4244
var key = PlatformKey()
4345
pthread_key_create(&key, nil)
4446
self.key = key
@@ -56,7 +58,7 @@ struct _ThreadLocal {
5658

5759
private static subscript(_ key: PlatformKey) -> UnsafeMutableRawPointer? {
5860
get {
59-
#if canImport(Darwin) || os(Android) || canImport(Glibc)
61+
#if canImport(Darwin) || os(Android) || canImport(Glibc) || canImport(Musl)
6062
pthread_getspecific(key)
6163
#elseif USE_TSS
6264
tss_get(key)
@@ -68,7 +70,7 @@ struct _ThreadLocal {
6870
}
6971

7072
set {
71-
#if canImport(Darwin) || os(Android) || canImport(Glibc)
73+
#if canImport(Darwin) || os(Android) || canImport(Glibc) || canImport(Musl)
7274
pthread_setspecific(key, newValue)
7375
#elseif USE_TSS
7476
tss_set(key, newValue)

Sources/FoundationInternationalization/Calendar/Calendar_ICU.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import FoundationEssentials
1818
import Android
1919
#elseif canImport(Glibc)
2020
import Glibc
21+
#elseif canImport(Musl)
22+
import Musl
2123
#elseif canImport(CRT)
2224
import CRT
2325
#elseif canImport(Darwin)

Sources/FoundationInternationalization/Date+ICU.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ internal import _FoundationICU
1919
import Android
2020
#elseif canImport(Glibc)
2121
import Glibc
22+
#elseif canImport(Musl)
23+
import Musl
2224
#elseif canImport(Darwin)
2325
import Darwin
2426
#endif

Sources/FoundationInternationalization/Formatting/Date/ICUDateFormatter.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ import Darwin
2222
import Android
2323
#elseif canImport(Glibc)
2424
import Glibc
25+
#elseif canImport(Musl)
26+
import Musl
2527
#endif
2628

2729
typealias UChar = UInt16

Sources/FoundationInternationalization/Formatting/Duration+Formatting.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import Darwin
2020
import Android
2121
#elseif canImport(Glibc)
2222
import Glibc
23+
#elseif canImport(Musl)
24+
import Musl
2325
#elseif os(Windows)
2426
import CRT
2527
#elseif os(WASI)

0 commit comments

Comments
 (0)