Skip to content

[main] Get Swift-Foundation building against MUSL for Swift Static SDK #848

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Sources/FoundationEssentials/Calendar/Calendar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ internal import os
import Android
#elseif canImport(Glibc)
import Glibc
#elseif canImport(Musl)
import Musl
#elseif canImport(CRT)
import CRT
#elseif os(WASI)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ internal import os
import Android
#elseif canImport(Glibc)
import Glibc
#elseif canImport(Musl)
import Musl
#elseif canImport(CRT)
import CRT
#elseif os(WASI)
Expand Down
4 changes: 3 additions & 1 deletion Sources/FoundationEssentials/Data/Data+Reading.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import Darwin
import Android
#elseif canImport(Glibc)
import Glibc
#elseif canImport(Musl)
import Musl
#elseif os(Windows)
import CRT
import WinSDK
Expand All @@ -32,7 +34,7 @@ import WASILibc
func _fgetxattr(_ fd: Int32, _ name: UnsafePointer<CChar>!, _ value: UnsafeMutableRawPointer!, _ size: Int, _ position: UInt32, _ options: Int32) -> Int {
#if canImport(Darwin)
return fgetxattr(fd, name, value, size, position, options)
#elseif canImport(Glibc)
#elseif canImport(Glibc) || canImport(Musl)
return fgetxattr(fd, name, value, size)
#else
return -1
Expand Down
4 changes: 3 additions & 1 deletion Sources/FoundationEssentials/Data/Data+Writing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import Android
import unistd
#elseif canImport(Glibc)
import Glibc
#elseif canImport(Musl)
import Musl
#elseif os(Windows)
import CRT
import WinSDK
Expand Down Expand Up @@ -632,7 +634,7 @@ private func writeExtendedAttributes(fd: Int32, attributes: [String : Data]) {
// Returns non-zero on error, but we ignore them
#if canImport(Darwin)
_ = fsetxattr(fd, key, valueBuf.baseAddress!, valueBuf.count, 0, 0)
#elseif canImport(Glibc)
#elseif canImport(Glibc) || canImport(Musl)
_ = fsetxattr(fd, key, valueBuf.baseAddress!, valueBuf.count, 0)
#endif
}
Expand Down
2 changes: 2 additions & 0 deletions Sources/FoundationEssentials/Date.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import Darwin
import Bionic
#elseif canImport(Glibc)
import Glibc
#elseif canImport(Musl)
import Musl
#elseif canImport(WinSDK)
import WinSDK
#elseif os(WASI)
Expand Down
2 changes: 2 additions & 0 deletions Sources/FoundationEssentials/Decimal/Decimal+Math.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import Darwin
import Android
#elseif canImport(Glibc)
import Glibc
#elseif canImport(Musl)
import Musl
#elseif canImport(CRT)
import CRT
#elseif os(WASI)
Expand Down
2 changes: 2 additions & 0 deletions Sources/FoundationEssentials/Error/CocoaError+FilePath.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import Darwin
import Bionic
#elseif canImport(Glibc)
import Glibc
#elseif canImport(Musl)
import Musl
#elseif os(Windows)
import CRT
import WinSDK
Expand Down
2 changes: 2 additions & 0 deletions Sources/FoundationEssentials/Error/ErrorCodes+POSIX.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
@preconcurrency import Android
#elseif canImport(Glibc)
@preconcurrency import Glibc
#elseif canImport(Musl)
@preconcurrency import Musl
#elseif canImport(Darwin)
@preconcurrency import Darwin
#elseif os(Windows)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import Darwin
import Android
#elseif canImport(Glibc)
import Glibc
#elseif canImport(Musl)
import Musl
#elseif os(Windows)
import CRT
import WinSDK
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import Android
import unistd
#elseif canImport(Glibc)
import Glibc
#elseif canImport(Musl)
import Musl
#elseif os(Windows)
import CRT
import WinSDK
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ import posix_filesystem
#elseif canImport(Glibc)
import Glibc
internal import _FoundationCShims
#elseif canImport(Musl)
import Musl
internal import _FoundationCShims
#elseif os(Windows)
import CRT
import WinSDK
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import Android
import unistd
#elseif canImport(Glibc)
import Glibc
#elseif canImport(Musl)
import Musl
#elseif os(Windows)
import CRT
import WinSDK
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ import Android
#elseif canImport(Glibc)
import Glibc
internal import _FoundationCShims
#elseif canImport(Musl)
import Musl
internal import _FoundationCShims
#elseif os(Windows)
import CRT
import WinSDK
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ import posix_filesystem.dirent
#elseif canImport(Glibc)
import Glibc
internal import _FoundationCShims
#elseif canImport(Musl)
import Musl
#elseif os(WASI)
import WASILibc
internal import _FoundationCShims
Expand Down Expand Up @@ -326,7 +328,7 @@ extension Sequence<_FTSSequence.Element> {
struct _POSIXDirectoryContentsSequence: Sequence {
#if canImport(Darwin)
typealias DirectoryEntryPtr = UnsafeMutablePointer<DIR>
#elseif os(Android) || canImport(Glibc) || os(WASI)
#elseif os(Android) || canImport(Glibc) || canImport(Musl) || os(WASI)
typealias DirectoryEntryPtr = OpaquePointer
#endif

Expand Down
2 changes: 2 additions & 0 deletions Sources/FoundationEssentials/FileManager/FileOperations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import Darwin
import Android
#elseif canImport(Glibc)
import Glibc
#elseif canImport(Musl)
import Musl
#elseif os(Windows)
import CRT
import WinSDK
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import Darwin
import Android
#elseif canImport(Glibc)
import Glibc
#elseif canImport(Musl)
import Musl
#elseif os(Windows)
import CRT
#elseif os(WASI)
Expand Down
4 changes: 3 additions & 1 deletion Sources/FoundationEssentials/LockedState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ internal import C.os.lock
import Bionic
#elseif canImport(Glibc)
import Glibc
#elseif canImport(Musl)
import Musl
#elseif canImport(WinSDK)
import WinSDK
#endif
Expand All @@ -29,7 +31,7 @@ package struct LockedState<State> {
private struct _Lock {
#if canImport(os)
typealias Primitive = os_unfair_lock
#elseif os(Android) || canImport(Glibc)
#elseif os(Android) || canImport(Glibc) || canImport(Musl)
typealias Primitive = pthread_mutex_t
#elseif canImport(WinSDK)
typealias Primitive = SRWLOCK
Expand Down
3 changes: 3 additions & 0 deletions Sources/FoundationEssentials/Platform.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ fileprivate let _pageSize: Int = Int(getpagesize())
#elseif canImport(Glibc)
import Glibc
fileprivate let _pageSize: Int = Int(getpagesize())
#elseif canImport(Musl)
import Musl
fileprivate let _pageSize: Int = Int(getpagesize())
#elseif canImport(C)
fileprivate let _pageSize: Int = Int(getpagesize())
#endif // canImport(Darwin)
Expand Down
6 changes: 4 additions & 2 deletions Sources/FoundationEssentials/ProcessInfo/ProcessInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import Bionic
import unistd
#elseif canImport(Glibc)
import Glibc
#elseif canImport(Musl)
import Musl
#elseif os(Windows)
import WinSDK
#elseif os(WASI)
Expand Down Expand Up @@ -163,7 +165,7 @@ final class _ProcessInfo: Sendable {
}

var userName: String {
#if canImport(Darwin) || os(Android) || canImport(Glibc)
#if canImport(Darwin) || os(Android) || canImport(Glibc) || canImport(Musl)
// Darwin and Linux
let (euid, _) = Platform.getUGIDs()
if let upwd = getpwuid(euid),
Expand Down Expand Up @@ -201,7 +203,7 @@ final class _ProcessInfo: Sendable {
#if os(Android) && (arch(i386) || arch(arm))
// On LP32 Android, pw_gecos doesn't exist and is presumed to be NULL.
return ""
#elseif canImport(Darwin) || os(Android) || canImport(Glibc)
#elseif canImport(Darwin) || os(Android) || canImport(Glibc) || canImport(Musl)
let (euid, _) = Platform.getUGIDs()
if let upwd = getpwuid(euid),
let fullname = upwd.pointee.pw_gecos {
Expand Down
2 changes: 2 additions & 0 deletions Sources/FoundationEssentials/PropertyList/OpenStepPlist.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import Darwin
import Bionic
#elseif canImport(Glibc)
import Glibc
#elseif canImport(Musl)
import Musl
#elseif os(WASI)
import WASILibc
#endif
Expand Down
2 changes: 2 additions & 0 deletions Sources/FoundationEssentials/String/String+Path.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ internal import os
import Android
#elseif canImport(Glibc)
import Glibc
#elseif canImport(Musl)
import Musl
#elseif os(Windows)
import WinSDK
#elseif os(WASI)
Expand Down
2 changes: 2 additions & 0 deletions Sources/FoundationEssentials/TimeZone/TimeZone_Cache.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import Darwin
import unistd
#elseif canImport(Glibc)
import Glibc
#elseif canImport(Musl)
import Musl
#elseif canImport(ucrt)
import ucrt
#endif
Expand Down
10 changes: 6 additions & 4 deletions Sources/FoundationEssentials/_ThreadLocal.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import Darwin
import Bionic
#elseif canImport(Glibc)
import Glibc
#elseif canImport(Musl)
import Musl
#elseif canImport(WinSDK)
import WinSDK
#elseif canImport(threads_h)
Expand All @@ -24,7 +26,7 @@ internal import threads
#endif

struct _ThreadLocal {
#if canImport(Darwin) || os(Android) || canImport(Glibc)
#if canImport(Darwin) || os(Android) || canImport(Glibc) || canImport(Musl)
fileprivate typealias PlatformKey = pthread_key_t
#elseif USE_TSS
fileprivate typealias PlatformKey = tss_t
Expand All @@ -38,7 +40,7 @@ struct _ThreadLocal {
fileprivate let key: PlatformKey

init() {
#if canImport(Darwin) || os(Android) || canImport(Glibc)
#if canImport(Darwin) || os(Android) || canImport(Glibc) || canImport(Musl)
var key = PlatformKey()
pthread_key_create(&key, nil)
self.key = key
Expand All @@ -56,7 +58,7 @@ struct _ThreadLocal {

private static subscript(_ key: PlatformKey) -> UnsafeMutableRawPointer? {
get {
#if canImport(Darwin) || os(Android) || canImport(Glibc)
#if canImport(Darwin) || os(Android) || canImport(Glibc) || canImport(Musl)
pthread_getspecific(key)
#elseif USE_TSS
tss_get(key)
Expand All @@ -68,7 +70,7 @@ struct _ThreadLocal {
}

set {
#if canImport(Darwin) || os(Android) || canImport(Glibc)
#if canImport(Darwin) || os(Android) || canImport(Glibc) || canImport(Musl)
pthread_setspecific(key, newValue)
#elseif USE_TSS
tss_set(key, newValue)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import FoundationEssentials
import Android
#elseif canImport(Glibc)
import Glibc
#elseif canImport(Musl)
import Musl
#elseif canImport(CRT)
import CRT
#elseif canImport(Darwin)
Expand Down
2 changes: 2 additions & 0 deletions Sources/FoundationInternationalization/Date+ICU.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ internal import _FoundationICU
import Android
#elseif canImport(Glibc)
import Glibc
#elseif canImport(Musl)
import Musl
#elseif canImport(Darwin)
import Darwin
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import Darwin
import Android
#elseif canImport(Glibc)
import Glibc
#elseif canImport(Musl)
import Musl
#endif

typealias UChar = UInt16
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import Darwin
import Android
#elseif canImport(Glibc)
import Glibc
#elseif canImport(Musl)
import Musl
#elseif os(Windows)
import CRT
#elseif os(WASI)
Expand Down