Skip to content

Add WASI Threads thread-spawn support - #423

Merged
kateinoigakukun merged 16 commits into
mainfrom
feature/wasi-threads-thread-spawn
Sep 7, 2026
Merged

kateinoigakukun merged 16 commits into
mainfrom
feature/wasi-threads-thread-spawn

Conversation

@kateinoigakukun

@kateinoigakukun kateinoigakukun commented Sep 1, 2026 •

Copy link
Copy Markdown
Member

Summary

Rework #386

  • add the WasmKitWASIThreads product, public shared-memory backing, and detached pthread worker startup
  • add CLI WASI Threads opt-in with explicit --feature threads proposal gating
  • add unit, shared-memory, option, and subprocess lifecycle coverage
  • address review feedback on resource limiting, documentation, feature configuration, and test ownership

Validation

  • swift build --product wasmkit-cli
  • swift test --filter RunOptionsTests
  • swift test --filter WASIThreadsTests
  • swift test --filter WASIThreadsSubprocessTests

Comment thread README.md Outdated
|---------|--------|-----------------|
| [WASI 0.1](https://github.com/WebAssembly/WASI/tree/wasi-0.1) | 🚧 [Majority of syscalls implemented](https://github.com/swiftwasm/WasmKit/blob/d9b56a7b3f979a72682c0d37f6cc71b3493dae65/Tests/WASITests/IntegrationTests.swift#L31) | [0.0.2] |
| [WASI Threads](https://github.com/WebAssembly/wasi-threads) | ❌ Not implemented | |
| [WASI Threads](https://github.com/WebAssembly/wasi-threads) | ✅ Implemented | `wasmkit-cli run --feature threads --wasi-threads` |

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think that passing both should be required? I feel like --feature threads should be enough, and we can detect that it's WASIp1 threads from the list of imports?

Comment thread Documentation/WASIThreads.md Resolved
Comment thread Sources/CLICommands/Run.swift Outdated
Comment on lines +56 to +57
@Flag(name: .customLong("wasi-threads"), help: "Enable WASI Threads")
var wasiThreads = false

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as README.md comment below: I feel this is redundant, we can auto-detect if from imports when --feature threads is passed.

Suggested change
@Flag(name: .customLong("wasi-threads"), help: "Enable WASI Threads")
var wasiThreads = false

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think auto-enabling --feature threads based on --wasi-threads makes sense but not the opposite side, because wasi-threads depends on core threads proposal but not the other way.

name: .customLong("feature"),
help: "Enable a WebAssembly proposal feature (memory64, reference-types, threads, tail-call, simd, exception-handling)"
)
var features: [Feature] = []

@MaxDesiatov MaxDesiatov Sep 3, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did we not have any of these enabled by default previously? It would be confusing if CLI supported EH or SIMD by default, and in the new release we'd start requiring explicit options for it.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. We should keep the default feature set consistent with the one in WasmParser.

Co-authored-by: Max Desiatov <[email protected]>
Comment thread Sources/CLICommands/Run.swift Outdated
}
}

private func terminateProcess(_ code: Int32) -> Never {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fatalError("WASI Threads is unavailable on this platform") in this body makes this function specific to the threads implementation, which IMO should be reflected in its name. The current name seems too general.

Suggested change
private func terminateProcess(_ code: Int32) -> Never {
private func wasiThreadsTerminateProcess(_ code: Int32) -> Never {

wasi-threads depends on the core threads proposal, so opting into the
former now enables the latter instead of erroring out. Also rename the
CLI-local exit helper to reflect that it is WASI-Threads specific.
The valid values are already rendered by ArgumentParser from CaseIterable,
and the default-enabled subset is now computed from WasmFeatureSet.default
instead of being spelled out again in the help string.
WasmFeatureSet now enumerates its proposals as cases, and its flags and
`all` are derived from them. The CLI no longer keeps a parallel list; it
only spells each proposal for the command line in an exhaustive switch,
so a new proposal fails to build until it is named.
@kateinoigakukun
kateinoigakukun merged commit 716cde6 into main Sep 7, 2026
19 checks passed
@kateinoigakukun
kateinoigakukun deleted the feature/wasi-threads-thread-spawn branch September 7, 2026 12:48
MaxDesiatov added a commit to MaxDesiatov/swift that referenced this pull request Sep 8, 2026
Start distributing the `wasip1-threads` triple in Swift SDKs for evaluation in
`main` development snapshots.

WasmKit gained WASI Threads thread-spawn support in swiftwasm/WasmKit#423, so
the TODO deferring this no longer applies.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants