From 34c83e18434ca66dbb8646656cb3ab3dfe949783 Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Fri, 16 Feb 2024 22:43:38 +0900 Subject: [PATCH] Fix test runner build on WASI (#7341) The test runner build was failing on WASI after the introduction of the experimental summary output. This PR fixes several minor issues to pass `--build-tests` build on WASI: * Missing `WASILibc` import * The use of `flock` which is not available on WASI. * Signature incompatibility of `XCTMain` on WASI. `swift build --build-tests --triple wasm32-unknown-wasi` will pass when compiler supports the target. --- Sources/Build/TestObservation.swift | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Sources/Build/TestObservation.swift b/Sources/Build/TestObservation.swift index 30001761c70..d128f4f0170 100644 --- a/Sources/Build/TestObservation.swift +++ b/Sources/Build/TestObservation.swift @@ -130,6 +130,8 @@ public func generateTestObservationCode(buildParameters: BuildParameters) -> Str #elseif os(Windows) @_exported import CRT @_exported import WinSDK + #elseif os(WASI) + @_exported import WASILibc #else @_exported import Darwin.C #endif @@ -176,6 +178,8 @@ public func generateTestObservationCode(buildParameters: BuildParameters) -> Str UInt32.max, UInt32.max, &overlapped) { throw ProcessLockError.unableToAquireLock(errno: Int32(GetLastError())) } + #elseif os(WASI) + // WASI doesn't support flock #else if fileDescriptor == nil { let fd = open(lockFile.path, O_WRONLY | O_CREAT | O_CLOEXEC, 0o666) @@ -201,6 +205,8 @@ public func generateTestObservationCode(buildParameters: BuildParameters) -> Str overlapped.OffsetHigh = 0 overlapped.hEvent = nil UnlockFileEx(handle, 0, UInt32.max, UInt32.max, &overlapped) + #elseif os(WASI) + // WASI doesn't support flock #else guard let fd = fileDescriptor else { return } flock(fd, LOCK_UN) @@ -211,6 +217,8 @@ public func generateTestObservationCode(buildParameters: BuildParameters) -> Str #if os(Windows) guard let handle = handle else { return } CloseHandle(handle) + #elseif os(WASI) + // WASI doesn't support flock #else guard let fd = fileDescriptor else { return } close(fd)