From 133416630710764798078e8893fd45be17cc0b48 Mon Sep 17 00:00:00 2001 From: Evan Wilde Date: Wed, 7 Aug 2024 11:22:13 -0700 Subject: [PATCH 1/2] 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. --- Sources/FoundationEssentials/Calendar/Calendar.swift | 2 ++ .../Calendar/Calendar_Gregorian.swift | 2 ++ Sources/FoundationEssentials/Data/Data+Reading.swift | 4 +++- Sources/FoundationEssentials/Data/Data+Writing.swift | 4 +++- Sources/FoundationEssentials/Date.swift | 2 ++ .../FoundationEssentials/Decimal/Decimal+Math.swift | 2 ++ .../Error/CocoaError+FilePath.swift | 2 ++ .../FoundationEssentials/Error/ErrorCodes+POSIX.swift | 2 ++ .../FileManager/FileManager+Basics.swift | 2 ++ .../FileManager/FileManager+Directories.swift | 2 ++ .../FileManager/FileManager+Files.swift | 3 +++ .../FileManager/FileManager+SymbolicLinks.swift | 2 ++ .../FileManager/FileManager+Utilities.swift | 3 +++ .../FileManager/FileOperations+Enumeration.swift | 5 ++++- .../FileManager/FileOperations.swift | 2 ++ .../BinaryInteger+NumericStringRepresentation.swift | 2 ++ Sources/FoundationEssentials/LockedState.swift | 4 +++- Sources/FoundationEssentials/Platform.swift | 3 +++ .../FoundationEssentials/ProcessInfo/ProcessInfo.swift | 6 ++++-- .../PropertyList/OpenStepPlist.swift | 2 ++ Sources/FoundationEssentials/String/String+Path.swift | 2 ++ .../FoundationEssentials/TimeZone/TimeZone_Cache.swift | 2 ++ Sources/FoundationEssentials/_ThreadLocal.swift | 10 ++++++---- 23 files changed, 60 insertions(+), 10 deletions(-) diff --git a/Sources/FoundationEssentials/Calendar/Calendar.swift b/Sources/FoundationEssentials/Calendar/Calendar.swift index 99d72e161..9de55b372 100644 --- a/Sources/FoundationEssentials/Calendar/Calendar.swift +++ b/Sources/FoundationEssentials/Calendar/Calendar.swift @@ -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 diff --git a/Sources/FoundationEssentials/Calendar/Calendar_Gregorian.swift b/Sources/FoundationEssentials/Calendar/Calendar_Gregorian.swift index fd863cef8..797a8e8b7 100644 --- a/Sources/FoundationEssentials/Calendar/Calendar_Gregorian.swift +++ b/Sources/FoundationEssentials/Calendar/Calendar_Gregorian.swift @@ -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 diff --git a/Sources/FoundationEssentials/Data/Data+Reading.swift b/Sources/FoundationEssentials/Data/Data+Reading.swift index eb66e3f7c..2540b14eb 100644 --- a/Sources/FoundationEssentials/Data/Data+Reading.swift +++ b/Sources/FoundationEssentials/Data/Data+Reading.swift @@ -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!, _ 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 diff --git a/Sources/FoundationEssentials/Data/Data+Writing.swift b/Sources/FoundationEssentials/Data/Data+Writing.swift index 4f92cb1a6..1e75b43cf 100644 --- a/Sources/FoundationEssentials/Data/Data+Writing.swift +++ b/Sources/FoundationEssentials/Data/Data+Writing.swift @@ -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 } diff --git a/Sources/FoundationEssentials/Date.swift b/Sources/FoundationEssentials/Date.swift index 8811aa433..b65066f14 100644 --- a/Sources/FoundationEssentials/Date.swift +++ b/Sources/FoundationEssentials/Date.swift @@ -16,6 +16,8 @@ import Darwin import Bionic #elseif canImport(Glibc) import Glibc +#elseif canImport(Musl) +import Musl #elseif canImport(WinSDK) import WinSDK #endif diff --git a/Sources/FoundationEssentials/Decimal/Decimal+Math.swift b/Sources/FoundationEssentials/Decimal/Decimal+Math.swift index 172454463..c06be7abd 100644 --- a/Sources/FoundationEssentials/Decimal/Decimal+Math.swift +++ b/Sources/FoundationEssentials/Decimal/Decimal+Math.swift @@ -16,6 +16,8 @@ import Darwin import Android #elseif canImport(Glibc) import Glibc +#elseif canImport(Musl) +import Musl #elseif canImport(CRT) import CRT #endif diff --git a/Sources/FoundationEssentials/Error/CocoaError+FilePath.swift b/Sources/FoundationEssentials/Error/CocoaError+FilePath.swift index fbce0f6f8..d9b249761 100644 --- a/Sources/FoundationEssentials/Error/CocoaError+FilePath.swift +++ b/Sources/FoundationEssentials/Error/CocoaError+FilePath.swift @@ -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 diff --git a/Sources/FoundationEssentials/Error/ErrorCodes+POSIX.swift b/Sources/FoundationEssentials/Error/ErrorCodes+POSIX.swift index a7e01952c..048cd29b2 100644 --- a/Sources/FoundationEssentials/Error/ErrorCodes+POSIX.swift +++ b/Sources/FoundationEssentials/Error/ErrorCodes+POSIX.swift @@ -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) diff --git a/Sources/FoundationEssentials/FileManager/FileManager+Basics.swift b/Sources/FoundationEssentials/FileManager/FileManager+Basics.swift index 03ca025a2..b49821b1a 100644 --- a/Sources/FoundationEssentials/FileManager/FileManager+Basics.swift +++ b/Sources/FoundationEssentials/FileManager/FileManager+Basics.swift @@ -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 diff --git a/Sources/FoundationEssentials/FileManager/FileManager+Directories.swift b/Sources/FoundationEssentials/FileManager/FileManager+Directories.swift index 89e3f1f97..0941e5186 100644 --- a/Sources/FoundationEssentials/FileManager/FileManager+Directories.swift +++ b/Sources/FoundationEssentials/FileManager/FileManager+Directories.swift @@ -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 diff --git a/Sources/FoundationEssentials/FileManager/FileManager+Files.swift b/Sources/FoundationEssentials/FileManager/FileManager+Files.swift index b1cdba24a..fdd601020 100644 --- a/Sources/FoundationEssentials/FileManager/FileManager+Files.swift +++ b/Sources/FoundationEssentials/FileManager/FileManager+Files.swift @@ -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 diff --git a/Sources/FoundationEssentials/FileManager/FileManager+SymbolicLinks.swift b/Sources/FoundationEssentials/FileManager/FileManager+SymbolicLinks.swift index fc9b8f70e..a1355e78d 100644 --- a/Sources/FoundationEssentials/FileManager/FileManager+SymbolicLinks.swift +++ b/Sources/FoundationEssentials/FileManager/FileManager+SymbolicLinks.swift @@ -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 diff --git a/Sources/FoundationEssentials/FileManager/FileManager+Utilities.swift b/Sources/FoundationEssentials/FileManager/FileManager+Utilities.swift index bba8ed5c9..9bac9676f 100644 --- a/Sources/FoundationEssentials/FileManager/FileManager+Utilities.swift +++ b/Sources/FoundationEssentials/FileManager/FileManager+Utilities.swift @@ -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 diff --git a/Sources/FoundationEssentials/FileManager/FileOperations+Enumeration.swift b/Sources/FoundationEssentials/FileManager/FileOperations+Enumeration.swift index 22111f52c..2c9a02f6c 100644 --- a/Sources/FoundationEssentials/FileManager/FileOperations+Enumeration.swift +++ b/Sources/FoundationEssentials/FileManager/FileOperations+Enumeration.swift @@ -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 - #elseif os(Android) || canImport(Glibc) + #elseif os(Android) || canImport(Glibc) || canImport(Musl) typealias DirectoryEntryPtr = OpaquePointer #endif diff --git a/Sources/FoundationEssentials/FileManager/FileOperations.swift b/Sources/FoundationEssentials/FileManager/FileOperations.swift index 8e67a771f..f7f77b44d 100644 --- a/Sources/FoundationEssentials/FileManager/FileOperations.swift +++ b/Sources/FoundationEssentials/FileManager/FileOperations.swift @@ -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 diff --git a/Sources/FoundationEssentials/Formatting/BinaryInteger+NumericStringRepresentation.swift b/Sources/FoundationEssentials/Formatting/BinaryInteger+NumericStringRepresentation.swift index db02789e2..43e9fcdaa 100644 --- a/Sources/FoundationEssentials/Formatting/BinaryInteger+NumericStringRepresentation.swift +++ b/Sources/FoundationEssentials/Formatting/BinaryInteger+NumericStringRepresentation.swift @@ -16,6 +16,8 @@ import Darwin import Android #elseif canImport(Glibc) import Glibc +#elseif canImport(Musl) +import Musl #elseif os(Windows) import CRT #endif diff --git a/Sources/FoundationEssentials/LockedState.swift b/Sources/FoundationEssentials/LockedState.swift index ad432c704..6eb9ad840 100644 --- a/Sources/FoundationEssentials/LockedState.swift +++ b/Sources/FoundationEssentials/LockedState.swift @@ -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 { 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 diff --git a/Sources/FoundationEssentials/Platform.swift b/Sources/FoundationEssentials/Platform.swift index 65b3449ef..9c3f2d7a3 100644 --- a/Sources/FoundationEssentials/Platform.swift +++ b/Sources/FoundationEssentials/Platform.swift @@ -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) diff --git a/Sources/FoundationEssentials/ProcessInfo/ProcessInfo.swift b/Sources/FoundationEssentials/ProcessInfo/ProcessInfo.swift index 6f8b2b00a..2e809fa70 100644 --- a/Sources/FoundationEssentials/ProcessInfo/ProcessInfo.swift +++ b/Sources/FoundationEssentials/ProcessInfo/ProcessInfo.swift @@ -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 { diff --git a/Sources/FoundationEssentials/PropertyList/OpenStepPlist.swift b/Sources/FoundationEssentials/PropertyList/OpenStepPlist.swift index 174a6edda..c0428202d 100644 --- a/Sources/FoundationEssentials/PropertyList/OpenStepPlist.swift +++ b/Sources/FoundationEssentials/PropertyList/OpenStepPlist.swift @@ -16,6 +16,8 @@ import Darwin import Bionic #elseif canImport(Glibc) import Glibc +#elseif canImport(Musl) +import Musl #endif #if canImport(CRT) diff --git a/Sources/FoundationEssentials/String/String+Path.swift b/Sources/FoundationEssentials/String/String+Path.swift index b51625ee5..37cc43f25 100644 --- a/Sources/FoundationEssentials/String/String+Path.swift +++ b/Sources/FoundationEssentials/String/String+Path.swift @@ -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 diff --git a/Sources/FoundationEssentials/TimeZone/TimeZone_Cache.swift b/Sources/FoundationEssentials/TimeZone/TimeZone_Cache.swift index 1243def34..744d77b3b 100644 --- a/Sources/FoundationEssentials/TimeZone/TimeZone_Cache.swift +++ b/Sources/FoundationEssentials/TimeZone/TimeZone_Cache.swift @@ -16,6 +16,8 @@ import Darwin import unistd #elseif canImport(Glibc) import Glibc +#elseif canImport(Musl) +import Musl #elseif canImport(ucrt) import ucrt #endif diff --git a/Sources/FoundationEssentials/_ThreadLocal.swift b/Sources/FoundationEssentials/_ThreadLocal.swift index 67f5dfaae..aea9c4116 100644 --- a/Sources/FoundationEssentials/_ThreadLocal.swift +++ b/Sources/FoundationEssentials/_ThreadLocal.swift @@ -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) From 062c4155b034b62bb7dae150d2894077df95f63f Mon Sep 17 00:00:00 2001 From: Evan Wilde Date: Thu, 8 Aug 2024 15:44:50 -0700 Subject: [PATCH 2/2] Get FoundationInternationalization building Adding the missing Musl imports to get FoundationInternationalization building for the static SDK. --- .../FoundationInternationalization/Calendar/Calendar_ICU.swift | 2 ++ Sources/FoundationInternationalization/Date+ICU.swift | 2 ++ .../Formatting/Date/ICUDateFormatter.swift | 2 ++ .../Formatting/Duration+Formatting.swift | 2 ++ 4 files changed, 8 insertions(+) diff --git a/Sources/FoundationInternationalization/Calendar/Calendar_ICU.swift b/Sources/FoundationInternationalization/Calendar/Calendar_ICU.swift index 0f0b97386..0d3c3710a 100644 --- a/Sources/FoundationInternationalization/Calendar/Calendar_ICU.swift +++ b/Sources/FoundationInternationalization/Calendar/Calendar_ICU.swift @@ -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) diff --git a/Sources/FoundationInternationalization/Date+ICU.swift b/Sources/FoundationInternationalization/Date+ICU.swift index 3895915ea..b91cd98b6 100644 --- a/Sources/FoundationInternationalization/Date+ICU.swift +++ b/Sources/FoundationInternationalization/Date+ICU.swift @@ -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 diff --git a/Sources/FoundationInternationalization/Formatting/Date/ICUDateFormatter.swift b/Sources/FoundationInternationalization/Formatting/Date/ICUDateFormatter.swift index d6ce6cf0a..1cd3bde72 100644 --- a/Sources/FoundationInternationalization/Formatting/Date/ICUDateFormatter.swift +++ b/Sources/FoundationInternationalization/Formatting/Date/ICUDateFormatter.swift @@ -22,6 +22,8 @@ import Darwin import Android #elseif canImport(Glibc) import Glibc +#elseif canImport(Musl) +import Musl #endif typealias UChar = UInt16 diff --git a/Sources/FoundationInternationalization/Formatting/Duration+Formatting.swift b/Sources/FoundationInternationalization/Formatting/Duration+Formatting.swift index ccfea7873..a94f57161 100644 --- a/Sources/FoundationInternationalization/Formatting/Duration+Formatting.swift +++ b/Sources/FoundationInternationalization/Formatting/Duration+Formatting.swift @@ -20,6 +20,8 @@ import Darwin import Android #elseif canImport(Glibc) import Glibc +#elseif canImport(Musl) +import Musl #elseif os(Windows) import CRT #endif