Skip to content

Commit 58d1012

Browse files
kateinoigakukunrunner
authored andcommitted
[wasm][test] Fix build of StdlibUnittest on WASI
WASI platform doesn't support crash interception and spawning threads/processes. So this patch disables interception support and subprocess spawning. The later patch will disable crash tests in each test case.
1 parent 98817f6 commit 58d1012

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

stdlib/private/StdlibUnittest/InterceptTraps.cpp

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,10 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
// No signals support on WASI yet, see https://github.com/WebAssembly/WASI/issues/166.
14-
#if !defined(__wasi__)
1513
#include <stdio.h>
1614
#include <signal.h>
1715
#include <string.h>
18-
#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
16+
#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) || defined(__wasi__)
1917
#include <unistd.h>
2018
#endif
2119
#if defined(_WIN32)
@@ -50,8 +48,6 @@ static void CrashCatcher(int Sig) {
5048
_exit(0);
5149
}
5250

53-
#endif // __wasi__
54-
5551
#if defined(_WIN32)
5652
static LONG WINAPI
5753
VectoredCrashHandler(PEXCEPTION_POINTERS ExceptionInfo) {
@@ -74,9 +70,6 @@ void installTrapInterceptor() {
7470
// Disable buffering on stdout so that everything is printed before crashing.
7571
setbuf(stdout, 0);
7672

77-
// No signals support on WASI yet, see https://github.com/WebAssembly/WASI/issues/166.
78-
#if !defined(__wasi__)
79-
8073
#if defined(_WIN32)
8174
_set_abort_behavior(0, _WRITE_ABORT_MSG);
8275
#endif
@@ -92,6 +85,5 @@ void installTrapInterceptor() {
9285
signal(SIGBUS, CrashCatcher);
9386
signal(SIGSYS, CrashCatcher);
9487
#endif
95-
}
9688

97-
#endif // !defined(__wasi__)
89+
}

stdlib/private/StdlibUnittest/StdlibUnittest.swift

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import Darwin
2424
import Glibc
2525
#elseif canImport(Musl)
2626
import Musl
27+
#elseif os(WASI)
28+
import WASILibc
2729
#elseif os(Windows)
2830
import CRT
2931
import WinSDK
@@ -37,6 +39,12 @@ import ObjectiveC
3739
import _Concurrency
3840
#endif
3941

42+
#if os(WASI)
43+
let platformSupportSpawnChild = false
44+
#else
45+
let platformSupportSpawnChild = true
46+
#endif
47+
4048
extension String {
4149
/// Returns the lines in `self`.
4250
public var _lines : [String] {
@@ -1726,7 +1734,7 @@ public func runAllTests() {
17261734
if _isChildProcess {
17271735
_childProcess()
17281736
} else {
1729-
var runTestsInProcess: Bool = false
1737+
var runTestsInProcess: Bool = !platformSupportSpawnChild
17301738
var filter: String?
17311739
var args = [String]()
17321740
var i = 0
@@ -1796,7 +1804,7 @@ public func runAllTestsAsync() async {
17961804
if _isChildProcess {
17971805
await _childProcessAsync()
17981806
} else {
1799-
var runTestsInProcess: Bool = false
1807+
var runTestsInProcess: Bool = !platformSupportSpawnChild
18001808
var filter: String?
18011809
var args = [String]()
18021810
var i = 0

0 commit comments

Comments
 (0)