Skip to content
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
7 changes: 7 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,13 @@ jobs:
- name: Build (aarch64-swift-linux-musl)
run: ./build-exec swift build --swift-sdk aarch64-swift-linux-musl

build-android:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- name: Run Tests on Android emulator
uses: skiptools/swift-android-action@v2

build-windows:
runs-on: windows-latest
steps:
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ let package = Package(
if ProcessInfo.processInfo.environment["SWIFTCI_USE_LOCAL_DEPS"] == nil {
package.dependencies += [
.package(url: "https://github.com/apple/swift-argument-parser", from: "1.2.2"),
.package(url: "https://github.com/apple/swift-system", .upToNextMinor(from: "1.3.0")),
.package(url: "https://github.com/apple/swift-system", from: "1.3.0"),
]
} else {
package.dependencies += [
Expand Down
7 changes: 5 additions & 2 deletions Sources/SystemExtras/Clock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import Glibc
#elseif canImport(Musl)
import CSystem
import Musl
#elseif canImport(Android)
import CSystem
import Android
#elseif os(Windows)
import CSystem
import ucrt
Expand All @@ -28,7 +31,7 @@ public struct Clock: RawRepresentable {
}

extension Clock {
#if os(Linux)
#if os(Linux) || os(Android)
@_alwaysEmitIntoClient
public static var boottime: Clock { Clock(rawValue: CLOCK_BOOTTIME) }
#endif
Expand All @@ -38,7 +41,7 @@ extension Clock {
public static var rawMonotonic: Clock { Clock(rawValue: _CLOCK_MONOTONIC_RAW) }
#endif

#if SYSTEM_PACKAGE_DARWIN || os(Linux) || os(OpenBSD) || os(FreeBSD) || os(WASI)
#if SYSTEM_PACKAGE_DARWIN || os(Linux) || os(Android) || os(OpenBSD) || os(FreeBSD) || os(WASI)
@_alwaysEmitIntoClient
public static var monotonic: Clock { Clock(rawValue: _CLOCK_MONOTONIC) }
#endif
Expand Down
18 changes: 13 additions & 5 deletions Sources/SystemExtras/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import Glibc
#elseif canImport(Musl)
import CSystem
import Musl
#elseif canImport(Android)
import CSystem
import Android
#elseif os(Windows)
import CSystem
import ucrt
Expand Down Expand Up @@ -34,7 +37,7 @@ internal var _AT_FDONLY: CInt { AT_FDONLY }
internal var _AT_SYMLINK_NOFOLLOW_ANY: CInt { AT_SYMLINK_NOFOLLOW_ANY }
#endif
/* FIXME: Disabled until CSystem will include "linux/fcntl.h"
#if os(Linux)
#if os(Linux) || os(Android)
@_alwaysEmitIntoClient
internal var _AT_NO_AUTOMOUNT: CInt { AT_NO_AUTOMOUNT }
#endif
Expand All @@ -45,9 +48,14 @@ internal var _AT_NO_AUTOMOUNT: CInt { AT_NO_AUTOMOUNT }
internal var _F_GETFL: CInt { F_GETFL }
@_alwaysEmitIntoClient
internal var _O_DSYNC: CInt { O_DSYNC }
#if os(Android)
@_alwaysEmitIntoClient
internal var _O_SYNC: CInt { __O_SYNC | O_DSYNC }
#else
@_alwaysEmitIntoClient
internal var _O_SYNC: CInt { O_SYNC }
#endif
#endif
#if os(Linux)
@_alwaysEmitIntoClient
internal var _O_RSYNC: CInt { O_RSYNC }
Expand All @@ -56,7 +64,7 @@ internal var _O_RSYNC: CInt { O_RSYNC }
#if !os(Windows)
@_alwaysEmitIntoClient
internal var _UTIME_NOW: CInt {
#if os(Linux)
#if os(Linux) || os(Android)
// Hard-code constants because it's defined in glibc in a form that
// ClangImporter cannot interpret as constants.
// https://github.com/torvalds/linux/blob/92901222f83d988617aee37680cb29e1a743b5e4/include/linux/stat.h#L15
Expand All @@ -67,7 +75,7 @@ internal var _UTIME_NOW: CInt {
}
@_alwaysEmitIntoClient
internal var _UTIME_OMIT: CInt {
#if os(Linux)
#if os(Linux) || os(Android)
// Hard-code constants because it's defined in glibc in a form that
// ClangImporter cannot interpret as constants.
// https://github.com/torvalds/linux/blob/92901222f83d988617aee37680cb29e1a743b5e4/include/linux/stat.h#L16
Expand Down Expand Up @@ -116,15 +124,15 @@ internal var _S_IFLNK: CInterop.Mode { S_IFLNK }
internal var _S_IFSOCK: CInterop.Mode { S_IFSOCK }
#endif

#if os(Linux)
#if os(Linux) || os(Android)
@_alwaysEmitIntoClient
internal var _CLOCK_BOOTTIME: CInterop.ClockId { CLOCK_BOOTTIME }
#endif
#if SYSTEM_PACKAGE_DARWIN
@_alwaysEmitIntoClient
internal var _CLOCK_MONOTONIC_RAW: CInterop.ClockId { CLOCK_MONOTONIC_RAW }
#endif
#if SYSTEM_PACKAGE_DARWIN || os(Linux) || os(OpenBSD) || os(FreeBSD) || os(WASI)
#if SYSTEM_PACKAGE_DARWIN || os(Linux) || os(Android) || os(OpenBSD) || os(FreeBSD) || os(WASI)
@_alwaysEmitIntoClient
internal var _CLOCK_MONOTONIC: CInterop.ClockId { CLOCK_MONOTONIC }
#endif
Expand Down
5 changes: 4 additions & 1 deletion Sources/SystemExtras/FileAtOperations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import Glibc
#elseif canImport(Musl)
import CSystem
import Musl
#elseif canImport(Android)
import CSystem
import Android
#elseif os(Windows)
import ucrt
import WinSDK
Expand Down Expand Up @@ -44,7 +47,7 @@ extension FileDescriptor {
#endif

/* FIXME: Disabled until CSystem will include "linux/fcntl.h"
#if os(Linux)
#if os(Linux) || os(Android)
/// Indicates the operation does't mount the basename component automatically
///
/// If you specify this option and the file you pass to
Expand Down
7 changes: 5 additions & 2 deletions Sources/SystemExtras/FileOperations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import Glibc
#elseif canImport(Musl)
import CSystem
import Musl
#elseif canImport(Android)
import CSystem
import Android
#elseif os(Windows)
import ucrt
import WinSDK
Expand Down Expand Up @@ -50,7 +53,7 @@ extension FileDescriptor {
@_alwaysEmitIntoClient
public init(rawValue: CInt) { self.rawValue = rawValue }

#if os(Linux)
#if os(Linux) || os(Android)
/// Access the specified data in the near future.
///
/// The corresponding C constant is `POSIX_FADV_WILLNEED`.
Expand All @@ -59,7 +62,7 @@ extension FileDescriptor {
#endif
}

#if os(Linux)
#if os(Linux) || os(Android)
/// Announces an intention to access specific region of file data.
///
/// - Parameters:
Expand Down
9 changes: 6 additions & 3 deletions Sources/SystemExtras/Syscalls.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import Glibc
#elseif canImport(Musl)
import CSystem
import Musl
#elseif canImport(Android)
import CSystem
import Android
#elseif os(Windows)
import ucrt
import WinSDK
Expand Down Expand Up @@ -61,12 +64,12 @@ internal func system_fdatasync(_ fd: Int32) -> CInt {
}
#endif

#if os(Linux)
#if os(Linux) || os(Android)
// posix_fadvise
internal func system_posix_fadvise(
_ fd: Int32, _ offset: Int, _ length: Int, _ advice: CInt
) -> CInt {
return posix_fadvise(fd, offset, length, advice)
return posix_fadvise(fd, .init(offset), .init(length), advice)
}
#endif

Expand Down Expand Up @@ -116,7 +119,7 @@ internal func system_symlinkat(
extension CInterop {
#if SYSTEM_PACKAGE_DARWIN
public typealias DirP = UnsafeMutablePointer<DIR>
#elseif os(Linux)
#elseif os(Linux) || os(Android)
public typealias DirP = OpaquePointer
#else
#error("Unsupported Platform")
Expand Down
4 changes: 2 additions & 2 deletions Sources/SystemExtras/Vendor/Exports.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ import Glibc
#elseif canImport(Musl)
import CSystem
import Musl
#elseif canImport(WASILibc)
import WASILibc
#elseif canImport(Android)
import CSystem
import Android
#elseif canImport(WASILibc)
import WASILibc
#else
#error("Unsupported Platform")
#endif
Expand Down
4 changes: 2 additions & 2 deletions Sources/WASI/Clock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public protocol MonotonicClock {
/// A monotonic clock that uses the system's monotonic clock.
public struct SystemMonotonicClock: MonotonicClock {
private var underlying: SystemExtras.Clock {
#if os(Linux)
#if os(Linux) || os(Android)
return .monotonic
#elseif os(macOS) || os(iOS) || os(watchOS) || os(tvOS) || os(visionOS)
return .rawUptime
Expand Down Expand Up @@ -125,7 +125,7 @@ public protocol MonotonicClock {
/// A wall clock that uses the system's wall clock.
public struct SystemWallClock: WallClock {
private var underlying: SystemExtras.Clock {
#if os(Linux)
#if os(Linux) || os(Android)
return .boottime
#elseif os(macOS) || os(iOS) || os(watchOS) || os(tvOS) || os(visionOS)
return .rawMonotonic
Expand Down
2 changes: 1 addition & 1 deletion Sources/WASI/Platform/Entry.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ extension FdWASIEntry {
try WASIAbi.Errno.translatingPlatformErrno {
try self.fd.adviseRead(offset: offset, length: length)
}
#elseif os(Linux)
#elseif os(Linux) || os(Android)
guard let offset = Int(exactly: offset),
let length = Int(exactly: length)
else {
Expand Down
3 changes: 3 additions & 0 deletions Sources/WASI/Platform/SandboxPrimitives/Open.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import SystemPackage
#elseif canImport(Musl)
import CSystem
import Musl
#elseif canImport(Android)
import CSystem
import Android
#elseif os(Windows)
import CSystem
import ucrt
Expand Down
2 changes: 2 additions & 0 deletions Sources/WASI/WASI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import WasmTypes
import Glibc
#elseif canImport(Musl)
import Musl
#elseif canImport(Android)
import Android
#elseif os(Windows)
import ucrt
#else
Expand Down
2 changes: 1 addition & 1 deletion Sources/WasmKit/Execution/Profiler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class GuestTimeProfiler: EngineInterceptor {

private static func getTimestamp() -> UInt64 {
let clock: SystemExtras.Clock
#if os(Linux)
#if os(Linux) || os(Android)
clock = .boottime
#elseif os(macOS) || os(iOS) || os(watchOS) || os(tvOS) || os(visionOS)
clock = .rawMonotonic
Expand Down
3 changes: 3 additions & 0 deletions Tests/WASITests/IntegrationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import XCTest

final class IntegrationTests: XCTestCase {
func testRunAll() throws {
#if os(Android)
throw XCTSkip("unable to run spectest on Android due to missing files on emulator")
#endif
let testDir = URL(fileURLWithPath: #filePath)
.deletingLastPathComponent().deletingLastPathComponent().deletingLastPathComponent()
.appendingPathComponent("Vendor/wasi-testsuite")
Expand Down
6 changes: 5 additions & 1 deletion Tests/WASITests/TestSupport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ enum TestSupport {
}
#else
if mkdtemp(&template) == nil {
throw Error(errno: errno)
#if os(Android)
throw Error(errno: __errno().pointee)
#else
throw Error(errno: errno)
#endif
}
#endif

Expand Down
6 changes: 5 additions & 1 deletion Tests/WATTests/TestSupport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ enum TestSupport {
}
#else
if mkdtemp(&template) == nil {
throw Error(errno: errno)
#if os(Android)
throw Error(errno: __errno().pointee)
#else
throw Error(errno: errno)
#endif
}
#endif

Expand Down
6 changes: 5 additions & 1 deletion Tests/WITExtractorPluginTests/TestSupport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ struct TestSupport {
var template = [UInt8](templatePath.path.utf8).map({ Int8($0) }) + [Int8(0)]

if mkdtemp(&template) == nil {
throw Error(errno: errno)
#if os(Android)
throw Error(errno: __errno().pointee)
#else
throw Error(errno: errno)
#endif
}

let path = String(cString: template)
Expand Down
6 changes: 5 additions & 1 deletion Tests/WITExtractorTests/TestSupport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ struct TestSupport {
}
#else
if mkdtemp(&template) == nil {
throw Error(errno: errno)
#if os(Android)
throw Error(errno: __errno().pointee)
#else
throw Error(errno: errno)
#endif
}
#endif

Expand Down
3 changes: 3 additions & 0 deletions Tests/WITOverlayGeneratorTests/HostGeneratorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ class HostGeneratorTests: XCTestCase {
// Host generators are already executed before running this test suite by SwiftPM build tool plugin,
// but execute again here to collect coverage data.
func testGenerateFromFixtures() throws {
#if os(Android)
throw XCTSkip("unable to run spectest on Android due to missing files on emulator")
#endif
let fixturesDir = RuntimeTestHarness.testsDirectory.appendingPathComponent("Fixtures")
for fixture in try FileManager.default.contentsOfDirectory(atPath: fixturesDir.path) {
let inputFileDir = fixturesDir.appendingPathComponent(fixture).appendingPathComponent("wit")
Expand Down
3 changes: 3 additions & 0 deletions Tests/WasmKitTests/FuzzTranslatorRegressionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import XCTest

final class FuzzTranslatorRegressionTests: XCTestCase {
func testRunAll() throws {
#if os(Android)
throw XCTSkip("Test skipped due to absolute path #filePath unavailable on emulator")
#endif
let sourceRoot = URL(fileURLWithPath: #filePath)
.deletingLastPathComponent().deletingLastPathComponent().deletingLastPathComponent()
let failCasesDir =
Expand Down
6 changes: 6 additions & 0 deletions Tests/WasmKitTests/SpectestTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ final class SpectestTests: XCTestCase {

/// Run all the tests in the spectest suite.
func testRunAll() async throws {
#if os(Android)
throw XCTSkip("unable to run spectest on Android due to missing files on emulator")
#endif
let defaultConfig = EngineConfiguration()
let ok = try await spectest(
path: Self.testPaths,
Expand All @@ -31,6 +34,9 @@ final class SpectestTests: XCTestCase {
}

func testRunAllWithTokenThreading() async throws {
#if os(Android)
throw XCTSkip("unable to run spectest on Android due to missing files on emulator")
#endif
let defaultConfig = EngineConfiguration()
guard defaultConfig.threadingModel != .token else { return }
// Sanity check that non-default threading models work.
Expand Down