Skip to content

Commit 0ec3473

Browse files
[5.10] Fix test runner build on WASI (#7351)
🍒 #7341 * **Explanation**: `swift build --build-tests` fails on WASI after the experimental summary output, which is introduced in 5.10. This affects not only experimental-summary mode but also the default output mode. * **Scope**: Test build targeting WebAssembly * **Risk**: Low, only affects to WebAssembly targets * **Testing**: Integration test with WebAssembly Swift SDK on CI is infeasible, so I manually tested. We can ensure there is no breakage on other platforms on CI. * **Reviewer**: @MaxDesiatov * **Main branch PR**: #7341
1 parent 82e3974 commit 0ec3473

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

Sources/Build/TestObservation.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ public func generateTestObservationCode(buildParameters: BuildParameters) -> Str
130130
#elseif os(Windows)
131131
@_exported import CRT
132132
@_exported import WinSDK
133+
#elseif os(WASI)
134+
@_exported import WASILibc
133135
#else
134136
@_exported import Darwin.C
135137
#endif
@@ -176,6 +178,8 @@ public func generateTestObservationCode(buildParameters: BuildParameters) -> Str
176178
UInt32.max, UInt32.max, &overlapped) {
177179
throw ProcessLockError.unableToAquireLock(errno: Int32(GetLastError()))
178180
}
181+
#elseif os(WASI)
182+
// WASI doesn't support flock
179183
#else
180184
if fileDescriptor == nil {
181185
let fd = open(lockFile.path, O_WRONLY | O_CREAT | O_CLOEXEC, 0o666)
@@ -201,6 +205,8 @@ public func generateTestObservationCode(buildParameters: BuildParameters) -> Str
201205
overlapped.OffsetHigh = 0
202206
overlapped.hEvent = nil
203207
UnlockFileEx(handle, 0, UInt32.max, UInt32.max, &overlapped)
208+
#elseif os(WASI)
209+
// WASI doesn't support flock
204210
#else
205211
guard let fd = fileDescriptor else { return }
206212
flock(fd, LOCK_UN)
@@ -211,6 +217,8 @@ public func generateTestObservationCode(buildParameters: BuildParameters) -> Str
211217
#if os(Windows)
212218
guard let handle = handle else { return }
213219
CloseHandle(handle)
220+
#elseif os(WASI)
221+
// WASI doesn't support flock
214222
#else
215223
guard let fd = fileDescriptor else { return }
216224
close(fd)

0 commit comments

Comments
 (0)