Skip to content

Add WASI platform conditions for libc imports and word size #776

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 3 commits into from
Aug 2, 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 @@ -18,6 +18,8 @@ import Android
import Glibc
#elseif canImport(CRT)
import CRT
#elseif os(WASI)
import WASILibc
#endif

#if FOUNDATION_FRAMEWORK
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import Android
import Glibc
#elseif canImport(CRT)
import CRT
#elseif os(WASI)
import WASILibc
#endif


Expand Down
2 changes: 2 additions & 0 deletions Sources/FoundationEssentials/Data/Data+Reading.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import Glibc
#elseif os(Windows)
import CRT
import WinSDK
#elseif os(WASI)
import WASILibc
#endif

func _fgetxattr(_ fd: Int32, _ name: UnsafePointer<CChar>!, _ value: UnsafeMutableRawPointer!, _ size: Int, _ position: UInt32, _ options: Int32) -> Int {
Expand Down
2 changes: 2 additions & 0 deletions Sources/FoundationEssentials/Data/Data+Writing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import Glibc
#elseif os(Windows)
import CRT
import WinSDK
#elseif os(WASI)
import WASILibc
#endif

#if !NO_FILESYSTEM
Expand Down
14 changes: 8 additions & 6 deletions Sources/FoundationEssentials/Data/Data.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ import Glibc
import Musl
#elseif canImport(ucrt)
import ucrt
#elseif canImport(WASILibc)
import WASILibc
#endif

#if os(Windows)
Expand Down Expand Up @@ -580,11 +582,11 @@ public struct Data : Equatable, Hashable, RandomAccessCollection, MutableCollect
@usableFromInline
@frozen
internal struct InlineData : Sendable {
#if arch(x86_64) || arch(arm64) || arch(s390x) || arch(powerpc64) || arch(powerpc64le)
#if _pointerBitWidth(_64)
@usableFromInline typealias Buffer = (UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8,
UInt8, UInt8, UInt8, UInt8, UInt8, UInt8) //len //enum
@usableFromInline var bytes: Buffer
#elseif arch(i386) || arch(arm) || arch(arm64_32)
#elseif _pointerBitWidth(_32)
@usableFromInline typealias Buffer = (UInt8, UInt8, UInt8, UInt8,
UInt8, UInt8) //len //enum
@usableFromInline var bytes: Buffer
Expand Down Expand Up @@ -615,9 +617,9 @@ public struct Data : Equatable, Hashable, RandomAccessCollection, MutableCollect
@inlinable // This is @inlinable as a trivial initializer.
init(count: Int = 0) {
assert(count <= MemoryLayout<Buffer>.size)
#if arch(x86_64) || arch(arm64) || arch(s390x) || arch(powerpc64) || arch(powerpc64le)
#if _pointerBitWidth(_64)
bytes = (UInt8(0), UInt8(0), UInt8(0), UInt8(0), UInt8(0), UInt8(0), UInt8(0), UInt8(0), UInt8(0), UInt8(0), UInt8(0), UInt8(0), UInt8(0), UInt8(0))
#elseif arch(i386) || arch(arm) || arch(arm64_32)
#elseif _pointerBitWidth(_32)
bytes = (UInt8(0), UInt8(0), UInt8(0), UInt8(0), UInt8(0), UInt8(0))
#else
#error ("Unsupported architecture: initialization for Buffer is required for this architecture")
Expand Down Expand Up @@ -802,9 +804,9 @@ public struct Data : Equatable, Hashable, RandomAccessCollection, MutableCollect
}
}

#if arch(x86_64) || arch(arm64) || arch(s390x) || arch(powerpc64) || arch(powerpc64le)
#if _pointerBitWidth(_64)
@usableFromInline internal typealias HalfInt = Int32
#elseif arch(i386) || arch(arm) || arch(arm64_32)
#elseif _pointerBitWidth(_32)
@usableFromInline internal typealias HalfInt = Int16
#else
#error ("Unsupported architecture: a definition of half of the pointer sized Int needs to be defined for this architecture")
Expand Down
2 changes: 2 additions & 0 deletions Sources/FoundationEssentials/Date.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import Bionic
import Glibc
#elseif canImport(WinSDK)
import WinSDK
#elseif os(WASI)
import WASILibc
#endif

#if !FOUNDATION_FRAMEWORK
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 @@ -18,6 +18,8 @@ import Android
import Glibc
#elseif canImport(CRT)
import CRT
#elseif os(WASI)
import WASILibc
#endif

private let powerOfTen: [Decimal.VariableLengthInteger] = [
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 @@ -22,6 +22,8 @@ import Glibc
#elseif os(Windows)
import CRT
import WinSDK
#elseif os(WASI)
import WASILibc
#endif

extension CocoaError.Code {
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 @@ -19,6 +19,8 @@
#elseif os(Windows)
import CRT
import WinSDK
#elseif os(WASI)
import WASILibc
#endif

#if FOUNDATION_FRAMEWORK
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import Glibc
#elseif os(Windows)
import CRT
import WinSDK
#elseif os(WASI)
import WASILibc
#endif

#if os(Windows)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import Glibc
#elseif os(Windows)
import CRT
import WinSDK
#elseif os(WASI)
import WASILibc
#endif

internal import _FoundationCShims
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ internal import _FoundationCShims
#elseif os(Windows)
import CRT
import WinSDK
#elseif os(WASI)
internal import _FoundationCShims
import WASILibc
#endif

extension Date {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import Glibc
import CRT
import WinSDK
internal import _FoundationCShims
#elseif os(WASI)
import WASILibc
#endif

extension _FileManagerImpl {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ internal import _FoundationCShims
#elseif os(Windows)
import CRT
import WinSDK
#elseif os(WASI)
import WASILibc
#endif

#if os(Windows)
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 @@ -19,6 +19,8 @@ import Glibc
#elseif os(Windows)
import CRT
import WinSDK
#elseif os(WASI)
import WASILibc
#endif

#if FOUNDATION_FRAMEWORK
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import Android
import Glibc
#elseif os(Windows)
import CRT
#elseif os(WASI)
import WASILibc
#endif

// MARK: - BinaryInteger + Numeric string representation
Expand Down
2 changes: 2 additions & 0 deletions Sources/FoundationEssentials/ProcessInfo/ProcessInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import unistd
import Glibc
#elseif os(Windows)
import WinSDK
#elseif os(WASI)
import WASILibc
#endif

#if !NO_PROCESS
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 os(WASI)
import WASILibc
#endif

#if canImport(CRT)
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 @@ -18,6 +18,8 @@ import Android
import Glibc
#elseif os(Windows)
import WinSDK
#elseif os(WASI)
import WASILibc
#endif

internal import _FoundationCShims
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import Glibc
import CRT
#elseif canImport(Darwin)
import Darwin
#elseif os(WASI)
import WASILibc
#endif

internal import _FoundationICU
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import Android
import Glibc
#elseif os(Windows)
import CRT
#elseif os(WASI)
import WASILibc
#endif

@available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
Expand Down