Skip to content

Commit a769223

Browse files
authored
FoundationEssentials: initial pass to add Android support (#704)
This adds the necessary guards and includes for the Android modules. While the module does not compile currently due to nullability differences (and in some cases missing declarations), this at least brings the module to a point where we can start working on the errors and differences to create a maintainable codebase for Android.
1 parent c39fe2d commit a769223

24 files changed

+81
-15
lines changed

Sources/FoundationEssentials/Calendar/Calendar.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
#if canImport(Darwin)
1414
internal import os
15+
#elseif os(Android)
16+
import Android
1517
#elseif canImport(Glibc)
1618
import Glibc
1719
#elseif canImport(CRT)

Sources/FoundationEssentials/Calendar/Calendar_Gregorian.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
#if canImport(os)
1414
internal import os
15+
#elseif os(Android)
16+
import Android
1517
#elseif canImport(Glibc)
1618
import Glibc
1719
#elseif canImport(CRT)

Sources/FoundationEssentials/CodableUtilities.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
#if canImport(Darwin)
1414
import Darwin
15+
#elseif os(Android)
16+
import Bionic
1517
#elseif canImport(Glibc)
1618
import Glibc
1719
#endif

Sources/FoundationEssentials/Data/Data+Reading.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ internal import _FoundationCShims
1818

1919
#if canImport(Darwin)
2020
import Darwin
21+
#elseif os(Android)
22+
import Android
2123
#elseif canImport(Glibc)
2224
import Glibc
2325
#elseif os(Windows)

Sources/FoundationEssentials/Data/Data+Writing.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ internal import _FoundationCShims
1919

2020
#if canImport(Darwin)
2121
import Darwin
22+
#elseif os(Android)
23+
import Android
24+
import unistd
2225
#elseif canImport(Glibc)
2326
import Glibc
2427
#elseif os(Windows)

Sources/FoundationEssentials/Data/Data.swift

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,15 @@
1717
@usableFromInline let memset = ucrt.memset
1818
@usableFromInline let memcpy = ucrt.memcpy
1919
@usableFromInline let memcmp = ucrt.memcmp
20-
#endif
21-
#if canImport(Glibc)
20+
#elseif os(Android)
21+
import Bionic
22+
@usableFromInline let calloc = Bionic.calloc
23+
@usableFromInline let malloc = Bionic.malloc
24+
@usableFromInline let free = Bionic.free
25+
@usableFromInline let memset = Bionic.memset
26+
@usableFromInline let memcpy = Bionic.memcpy
27+
@usableFromInline let memcmp = Bionic.memcmp
28+
#elseif canImport(Glibc)
2229
@usableFromInline let calloc = Glibc.calloc
2330
@usableFromInline let malloc = Glibc.malloc
2431
@usableFromInline let free = Glibc.free

Sources/FoundationEssentials/Date.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
#if canImport(Darwin)
1414
import Darwin
15+
#elseif os(Android)
16+
import Bionic
1517
#elseif canImport(Glibc)
1618
import Glibc
1719
#elseif canImport(WinSDK)

Sources/FoundationEssentials/Error/CocoaError+FilePath.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ internal import _ForSwiftFoundation
1515

1616
#if canImport(Darwin)
1717
import Darwin
18+
#elseif os(Android)
19+
import Bionic
1820
#elseif canImport(Glibc)
1921
import Glibc
2022
#elseif os(Windows)

Sources/FoundationEssentials/Error/ErrorCodes+POSIX.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
//===----------------------------------------------------------------------===//
1111

1212
// Import for POSIXErrorCode
13-
#if canImport(Glibc)
13+
#if os(Android)
14+
import Android
15+
#elseif canImport(Glibc)
1416
@preconcurrency import Glibc
1517
#elseif canImport(Darwin)
1618
@preconcurrency import Darwin

Sources/FoundationEssentials/FileManager/FileManager+Basics.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
#if canImport(Darwin)
1414
import Darwin
15+
#elseif os(Android)
16+
import Android
1517
#elseif canImport(Glibc)
1618
import Glibc
1719
#elseif os(Windows)

0 commit comments

Comments
 (0)