Skip to content

[WASI] Compilation failure on Swift 6.1+ due to missing pthread symbols in WASI toolchains #370

Description

@tayloraswift

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):

  1. swift(<6.1) evaluates to false.
  2. The compiler falls into the #else branch which assumes POSIX pthread_key_t, pthread_key_create, pthread_setspecific, and pthread_getspecific exist.
  3. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions