Skip to content

Commit 29b8fd2

Browse files
marcpruxkateinoigakukun
authored andcommitted
Android support
1 parent f13f592 commit 29b8fd2

File tree

21 files changed

+83
-20
lines changed

21 files changed

+83
-20
lines changed

.github/workflows/main.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,13 @@ jobs:
189189
- name: Build (aarch64-swift-linux-musl)
190190
run: ./build-exec swift build --swift-sdk aarch64-swift-linux-musl
191191

192+
build-android:
193+
runs-on: ubuntu-24.04
194+
steps:
195+
- uses: actions/checkout@v4
196+
- name: Run Tests on Android emulator
197+
uses: skiptools/swift-android-action@v2
198+
192199
build-windows:
193200
runs-on: windows-latest
194201
steps:

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ let package = Package(
127127
if ProcessInfo.processInfo.environment["SWIFTCI_USE_LOCAL_DEPS"] == nil {
128128
package.dependencies += [
129129
.package(url: "https://github.com/apple/swift-argument-parser", from: "1.2.2"),
130-
.package(url: "https://github.com/apple/swift-system", .upToNextMinor(from: "1.3.0")),
130+
.package(url: "https://github.com/apple/swift-system", .upToNextMinor(from: "1.5.0")),
131131
]
132132
} else {
133133
package.dependencies += [

Sources/SystemExtras/Clock.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import Glibc
66
#elseif canImport(Musl)
77
import CSystem
88
import Musl
9+
#elseif canImport(Android)
10+
import CSystem
11+
import Android
912
#elseif os(Windows)
1013
import CSystem
1114
import ucrt
@@ -28,7 +31,7 @@ public struct Clock: RawRepresentable {
2831
}
2932

3033
extension Clock {
31-
#if os(Linux)
34+
#if os(Linux) || os(Android)
3235
@_alwaysEmitIntoClient
3336
public static var boottime: Clock { Clock(rawValue: CLOCK_BOOTTIME) }
3437
#endif
@@ -38,7 +41,7 @@ extension Clock {
3841
public static var rawMonotonic: Clock { Clock(rawValue: _CLOCK_MONOTONIC_RAW) }
3942
#endif
4043

41-
#if SYSTEM_PACKAGE_DARWIN || os(Linux) || os(OpenBSD) || os(FreeBSD) || os(WASI)
44+
#if SYSTEM_PACKAGE_DARWIN || os(Linux) || os(Android) || os(OpenBSD) || os(FreeBSD) || os(WASI)
4245
@_alwaysEmitIntoClient
4346
public static var monotonic: Clock { Clock(rawValue: _CLOCK_MONOTONIC) }
4447
#endif

Sources/SystemExtras/Constants.swift

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import Glibc
66
#elseif canImport(Musl)
77
import CSystem
88
import Musl
9+
#elseif canImport(Android)
10+
import CSystem
11+
import Android
912
#elseif os(Windows)
1013
import CSystem
1114
import ucrt
@@ -34,7 +37,7 @@ internal var _AT_FDONLY: CInt { AT_FDONLY }
3437
internal var _AT_SYMLINK_NOFOLLOW_ANY: CInt { AT_SYMLINK_NOFOLLOW_ANY }
3538
#endif
3639
/* FIXME: Disabled until CSystem will include "linux/fcntl.h"
37-
#if os(Linux)
40+
#if os(Linux) || os(Android)
3841
@_alwaysEmitIntoClient
3942
internal var _AT_NO_AUTOMOUNT: CInt { AT_NO_AUTOMOUNT }
4043
#endif
@@ -45,9 +48,14 @@ internal var _AT_NO_AUTOMOUNT: CInt { AT_NO_AUTOMOUNT }
4548
internal var _F_GETFL: CInt { F_GETFL }
4649
@_alwaysEmitIntoClient
4750
internal var _O_DSYNC: CInt { O_DSYNC }
51+
#if os(Android)
52+
@_alwaysEmitIntoClient
53+
internal var _O_SYNC: CInt { __O_SYNC | O_DSYNC }
54+
#else
4855
@_alwaysEmitIntoClient
4956
internal var _O_SYNC: CInt { O_SYNC }
5057
#endif
58+
#endif
5159
#if os(Linux)
5260
@_alwaysEmitIntoClient
5361
internal var _O_RSYNC: CInt { O_RSYNC }
@@ -56,7 +64,7 @@ internal var _O_RSYNC: CInt { O_RSYNC }
5664
#if !os(Windows)
5765
@_alwaysEmitIntoClient
5866
internal var _UTIME_NOW: CInt {
59-
#if os(Linux)
67+
#if os(Linux) || os(Android)
6068
// Hard-code constants because it's defined in glibc in a form that
6169
// ClangImporter cannot interpret as constants.
6270
// https://github.com/torvalds/linux/blob/92901222f83d988617aee37680cb29e1a743b5e4/include/linux/stat.h#L15
@@ -67,7 +75,7 @@ internal var _UTIME_NOW: CInt {
6775
}
6876
@_alwaysEmitIntoClient
6977
internal var _UTIME_OMIT: CInt {
70-
#if os(Linux)
78+
#if os(Linux) || os(Android)
7179
// Hard-code constants because it's defined in glibc in a form that
7280
// ClangImporter cannot interpret as constants.
7381
// https://github.com/torvalds/linux/blob/92901222f83d988617aee37680cb29e1a743b5e4/include/linux/stat.h#L16
@@ -116,15 +124,15 @@ internal var _S_IFLNK: CInterop.Mode { S_IFLNK }
116124
internal var _S_IFSOCK: CInterop.Mode { S_IFSOCK }
117125
#endif
118126

119-
#if os(Linux)
127+
#if os(Linux) || os(Android)
120128
@_alwaysEmitIntoClient
121129
internal var _CLOCK_BOOTTIME: CInterop.ClockId { CLOCK_BOOTTIME }
122130
#endif
123131
#if SYSTEM_PACKAGE_DARWIN
124132
@_alwaysEmitIntoClient
125133
internal var _CLOCK_MONOTONIC_RAW: CInterop.ClockId { CLOCK_MONOTONIC_RAW }
126134
#endif
127-
#if SYSTEM_PACKAGE_DARWIN || os(Linux) || os(OpenBSD) || os(FreeBSD) || os(WASI)
135+
#if SYSTEM_PACKAGE_DARWIN || os(Linux) || os(Android) || os(OpenBSD) || os(FreeBSD) || os(WASI)
128136
@_alwaysEmitIntoClient
129137
internal var _CLOCK_MONOTONIC: CInterop.ClockId { CLOCK_MONOTONIC }
130138
#endif

Sources/SystemExtras/FileAtOperations.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import Glibc
66
#elseif canImport(Musl)
77
import CSystem
88
import Musl
9+
#elseif canImport(Android)
10+
import CSystem
11+
import Android
912
#elseif os(Windows)
1013
import ucrt
1114
import WinSDK
@@ -44,7 +47,7 @@ extension FileDescriptor {
4447
#endif
4548

4649
/* FIXME: Disabled until CSystem will include "linux/fcntl.h"
47-
#if os(Linux)
50+
#if os(Linux) || os(Android)
4851
/// Indicates the operation does't mount the basename component automatically
4952
///
5053
/// If you specify this option and the file you pass to

Sources/SystemExtras/FileOperations.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import Glibc
66
#elseif canImport(Musl)
77
import CSystem
88
import Musl
9+
#elseif canImport(Android)
10+
import CSystem
11+
import Android
912
#elseif os(Windows)
1013
import ucrt
1114
import WinSDK
@@ -50,7 +53,7 @@ extension FileDescriptor {
5053
@_alwaysEmitIntoClient
5154
public init(rawValue: CInt) { self.rawValue = rawValue }
5255

53-
#if os(Linux)
56+
#if os(Linux) || os(Android)
5457
/// Access the specified data in the near future.
5558
///
5659
/// The corresponding C constant is `POSIX_FADV_WILLNEED`.
@@ -59,7 +62,7 @@ extension FileDescriptor {
5962
#endif
6063
}
6164

62-
#if os(Linux)
65+
#if os(Linux) || os(Android)
6366
/// Announces an intention to access specific region of file data.
6467
///
6568
/// - Parameters:

Sources/SystemExtras/Syscalls.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import Glibc
66
#elseif canImport(Musl)
77
import CSystem
88
import Musl
9+
#elseif canImport(Android)
10+
import CSystem
11+
import Android
912
#elseif os(Windows)
1013
import ucrt
1114
import WinSDK
@@ -61,12 +64,12 @@ internal func system_fdatasync(_ fd: Int32) -> CInt {
6164
}
6265
#endif
6366

64-
#if os(Linux)
67+
#if os(Linux) || os(Android)
6568
// posix_fadvise
6669
internal func system_posix_fadvise(
6770
_ fd: Int32, _ offset: Int, _ length: Int, _ advice: CInt
6871
) -> CInt {
69-
return posix_fadvise(fd, offset, length, advice)
72+
return posix_fadvise(fd, .init(offset), .init(length), advice)
7073
}
7174
#endif
7275

@@ -116,7 +119,7 @@ internal func system_symlinkat(
116119
extension CInterop {
117120
#if SYSTEM_PACKAGE_DARWIN
118121
public typealias DirP = UnsafeMutablePointer<DIR>
119-
#elseif os(Linux)
122+
#elseif os(Linux) || os(Android)
120123
public typealias DirP = OpaquePointer
121124
#else
122125
#error("Unsupported Platform")

Sources/SystemExtras/Vendor/Exports.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ import Glibc
2323
#elseif canImport(Musl)
2424
import CSystem
2525
import Musl
26-
#elseif canImport(WASILibc)
27-
import WASILibc
2826
#elseif canImport(Android)
2927
import CSystem
3028
import Android
29+
#elseif canImport(WASILibc)
30+
import WASILibc
3131
#else
3232
#error("Unsupported Platform")
3333
#endif

Sources/WASI/Clock.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public protocol MonotonicClock {
9292
/// A monotonic clock that uses the system's monotonic clock.
9393
public struct SystemMonotonicClock: MonotonicClock {
9494
private var underlying: SystemExtras.Clock {
95-
#if os(Linux)
95+
#if os(Linux) || os(Android)
9696
return .monotonic
9797
#elseif os(macOS) || os(iOS) || os(watchOS) || os(tvOS) || os(visionOS)
9898
return .rawUptime
@@ -125,7 +125,7 @@ public protocol MonotonicClock {
125125
/// A wall clock that uses the system's wall clock.
126126
public struct SystemWallClock: WallClock {
127127
private var underlying: SystemExtras.Clock {
128-
#if os(Linux)
128+
#if os(Linux) || os(Android)
129129
return .boottime
130130
#elseif os(macOS) || os(iOS) || os(watchOS) || os(tvOS) || os(visionOS)
131131
return .rawMonotonic

Sources/WASI/Platform/Entry.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ extension FdWASIEntry {
2323
try WASIAbi.Errno.translatingPlatformErrno {
2424
try self.fd.adviseRead(offset: offset, length: length)
2525
}
26-
#elseif os(Linux)
26+
#elseif os(Linux) || os(Android)
2727
guard let offset = Int(exactly: offset),
2828
let length = Int(exactly: length)
2929
else {

0 commit comments

Comments
 (0)