Skip to content

Get Swift-Foundation building for Musl/Static SDK #838

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 16, 2024
Merged
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
@@ -16,6 +16,8 @@ internal import os
import Android
#elseif canImport(Glibc)
import Glibc
#elseif canImport(Musl)
import Musl
#elseif canImport(CRT)
import CRT
#endif
Original file line number Diff line number Diff line change
@@ -16,6 +16,8 @@ internal import os
import Android
#elseif canImport(Glibc)
import Glibc
#elseif canImport(Musl)
import Musl
#elseif canImport(CRT)
import CRT
#endif
4 changes: 3 additions & 1 deletion Sources/FoundationEssentials/Data/Data+Reading.swift
Original file line number Diff line number Diff line change
@@ -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
@@ -30,7 +32,7 @@ import WinSDK
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
4 changes: 3 additions & 1 deletion Sources/FoundationEssentials/Data/Data+Writing.swift
Original file line number Diff line number Diff line change
@@ -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
@@ -623,7 +625,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
}
2 changes: 2 additions & 0 deletions Sources/FoundationEssentials/Date.swift
Original file line number Diff line number Diff line change
@@ -16,6 +16,8 @@ import Darwin
import Bionic
#elseif canImport(Glibc)
import Glibc
#elseif canImport(Musl)
import Musl
#elseif canImport(WinSDK)
import WinSDK
#endif
2 changes: 2 additions & 0 deletions Sources/FoundationEssentials/Decimal/Decimal+Math.swift
Original file line number Diff line number Diff line change
@@ -16,6 +16,8 @@ import Darwin
import Android
#elseif canImport(Glibc)
import Glibc
#elseif canImport(Musl)
import Musl
#elseif canImport(CRT)
import CRT
#endif
2 changes: 2 additions & 0 deletions Sources/FoundationEssentials/Error/CocoaError+FilePath.swift
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions Sources/FoundationEssentials/Error/ErrorCodes+POSIX.swift
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -115,6 +115,9 @@ import posix_filesystem.dirent
#elseif canImport(Glibc)
import Glibc
internal import _FoundationCShims
#elseif canImport(Musl)
import Musl
internal import _FoundationCShims
#endif

// MARK: Directory Iteration
@@ -318,7 +321,7 @@ extension Sequence<_FTSSequence.Element> {
struct _POSIXDirectoryContentsSequence: Sequence {
#if canImport(Darwin)
typealias DirectoryEntryPtr = UnsafeMutablePointer<DIR>
#elseif os(Android) || canImport(Glibc)
#elseif os(Android) || canImport(Glibc) || canImport(Musl)
typealias DirectoryEntryPtr = OpaquePointer
#endif

2 changes: 2 additions & 0 deletions Sources/FoundationEssentials/FileManager/FileOperations.swift
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -16,6 +16,8 @@ import Darwin
import Android
#elseif canImport(Glibc)
import Glibc
#elseif canImport(Musl)
import Musl
#elseif os(Windows)
import CRT
#endif
4 changes: 3 additions & 1 deletion Sources/FoundationEssentials/LockedState.swift
Original file line number Diff line number Diff line change
@@ -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
@@ -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
3 changes: 3 additions & 0 deletions Sources/FoundationEssentials/Platform.swift
Original file line number Diff line number Diff line change
@@ -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)
6 changes: 4 additions & 2 deletions Sources/FoundationEssentials/ProcessInfo/ProcessInfo.swift
Original file line number Diff line number Diff line change
@@ -19,6 +19,8 @@ import Bionic
import unistd
#elseif canImport(Glibc)
import Glibc
#elseif canImport(Musl)
import Musl
#elseif os(Windows)
import WinSDK
#endif
@@ -161,7 +163,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),
@@ -196,7 +198,7 @@ final class _ProcessInfo: Sendable {
}

var fullUserName: String {
#if canImport(Darwin) || os(Android) || canImport(Glibc)
#if canImport(Darwin) || os(Android) || canImport(Glibc) || canImport(Musl)
let (euid, _) = Platform.getUGIDs()
if let upwd = getpwuid(euid),
let fullname = upwd.pointee.pw_gecos {
2 changes: 2 additions & 0 deletions Sources/FoundationEssentials/PropertyList/OpenStepPlist.swift
Original file line number Diff line number Diff line change
@@ -16,6 +16,8 @@ import Darwin
import Bionic
#elseif canImport(Glibc)
import Glibc
#elseif canImport(Musl)
import Musl
#endif

#if canImport(CRT)
2 changes: 2 additions & 0 deletions Sources/FoundationEssentials/String/String+Path.swift
Original file line number Diff line number Diff line change
@@ -16,6 +16,8 @@ internal import os
import Android
#elseif canImport(Glibc)
import Glibc
#elseif canImport(Musl)
import Musl
#elseif os(Windows)
import WinSDK
#endif
2 changes: 2 additions & 0 deletions Sources/FoundationEssentials/TimeZone/TimeZone_Cache.swift
Original file line number Diff line number Diff line change
@@ -16,6 +16,8 @@ import Darwin
import unistd
#elseif canImport(Glibc)
import Glibc
#elseif canImport(Musl)
import Musl
#elseif canImport(ucrt)
import ucrt
#endif
10 changes: 6 additions & 4 deletions Sources/FoundationEssentials/_ThreadLocal.swift
Original file line number Diff line number Diff line change
@@ -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)
@@ -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
@@ -36,7 +38,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
@@ -52,7 +54,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)
@@ -62,7 +64,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)
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 2 additions & 0 deletions Sources/FoundationInternationalization/Date+ICU.swift
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -22,6 +22,8 @@ import Darwin
import Android
#elseif canImport(Glibc)
import Glibc
#elseif canImport(Musl)
import Musl
#endif

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