Summary
In swift-system 1.8.0, compiling for WebAssembly target (wasm32-unknown-wasi) on Swift 6.1+ fails with scope resolution errors for POSIX pthread APIs (pthread_setspecific, pthread_getspecific, pthread_key_create).
Details
In Sources/System/Internals/Exports.swift, TLS storage for WASI is gated on:
#elseif os(WASI) && (swift(<6.1) || !_runtime(_multithreaded))
When compiling with Swift 6.1+ on a standard WASI SDK (wasm32-unknown-wasi):
swift(<6.1) evaluates to false.
- The compiler falls into the
#else branch which assumes POSIX pthread_key_t, pthread_key_create, pthread_setspecific, and pthread_getspecific exist.
- Standard WASI libc does not expose POSIX pthread functions in scope for non-threaded WASI target toolchains.
Compilation Errors
Sources/System/Internals/Exports.swift:221:14: error: cannot find 'pthread_key_create' in scope
Sources/System/Internals/Exports.swift:233:14: error: cannot find 'pthread_setspecific' in scope
Sources/System/Internals/Exports.swift:242:10: error: cannot find 'pthread_getspecific' in scope
Expected Behavior
swift-system should continue using the single-threaded WASI TLS fallback when POSIX pthread APIs are not available in scope for WASI targets.
Summary
In
swift-system1.8.0, compiling for WebAssembly target (wasm32-unknown-wasi) on Swift 6.1+ fails with scope resolution errors for POSIX pthread APIs (pthread_setspecific,pthread_getspecific,pthread_key_create).Details
In
Sources/System/Internals/Exports.swift, TLS storage for WASI is gated on:#elseif os(WASI) && (swift(<6.1) || !_runtime(_multithreaded))When compiling with Swift 6.1+ on a standard WASI SDK (
wasm32-unknown-wasi):swift(<6.1)evaluates tofalse.#elsebranch which assumes POSIXpthread_key_t,pthread_key_create,pthread_setspecific, andpthread_getspecificexist.Compilation Errors
Expected Behavior
swift-systemshould continue using the single-threaded WASI TLS fallback when POSIX pthread APIs are not available in scope for WASI targets.