1313import SwiftPrivate
1414#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
1515import Darwin
16- #elseif os(Linux) || os(FreeBSD) || os(PS4) || os(Android) || os(Cygwin) || os(Haiku)
16+ #elseif os(Linux) || os(FreeBSD) || os(PS4) || os(Android) || os(Cygwin) || os(Haiku) || os(WASI)
1717import Glibc
1818#elseif os(Windows)
1919import MSVCRT
2020import WinSDK
2121#endif
2222
23+ #if !os(WASI)
24+ // No signals support on WASI yet, see https://github.com/WebAssembly/WASI/issues/166.
2325internal func _signalToString( _ signal: Int ) -> String {
2426 switch CInt ( signal) {
2527 case SIGILL: return " SIGILL "
@@ -34,6 +36,7 @@ internal func _signalToString(_ signal: Int) -> String {
3436 default : return " SIG???? ( \( signal) ) "
3537 }
3638}
39+ #endif
3740
3841public enum ProcessTerminationStatus : CustomStringConvertible {
3942 case exit( Int )
@@ -44,7 +47,12 @@ public enum ProcessTerminationStatus : CustomStringConvertible {
4447 case . exit( let status) :
4548 return " Exit( \( status) ) "
4649 case . signal( let signal) :
50+ #if os(WASI)
51+ // No signals support on WASI yet, see https://github.com/WebAssembly/WASI/issues/166.
52+ fatalError ( " Signals are not supported on WebAssembly/WASI " )
53+ #else
4754 return " Signal( \( _signalToString ( signal) ) ) "
55+ #endif
4856 }
4957 }
5058}
@@ -141,6 +149,15 @@ public func waitProcess(_ process: HANDLE) -> ProcessTerminationStatus {
141149 }
142150 return . exit( Int ( status) )
143151}
152+ #elseif os(WASI)
153+ // WASI doesn't support child processes
154+ public func spawnChild( _ args: [ String ] )
155+ -> ( pid: pid_t , stdinFD: CInt , stdoutFD: CInt , stderrFD: CInt ) {
156+ fatalError ( " \( #function) is not supported on WebAssembly/WASI " )
157+ }
158+ public func posixWaitpid( _ pid: pid_t ) -> ProcessTerminationStatus {
159+ fatalError ( " \( #function) is not supported on WebAssembly/WASI " )
160+ }
144161#else
145162// posix_spawn is not available on Android.
146163// posix_spawn is not available on Haiku.
0 commit comments