enhancement: support WASI 0.2 and 0.3 via the Component Model
- Lenguaje dominante
- Rust
- Estrellas
- 48
- Forks
- 4
- Merge medio
- 20 h 13 min
- PR fusionados (30 d)
- 11
Descripción
## Summary
Today wasmrun only supports **WASI 0.1** (`wasi_snapshot_preview1`). This issue tracks adding **WASI 0.2** and **WASI 0.3** support so that 0.1, 0.2, and 0.3 modules can all run, selected by auto-detection rather than user configuration.
WASI 0.3.0 was ratified on 2026-06-11. 0.2 and 0.3 are both built on the WebAssembly **Component Model**, a different binary format and type system from the core-module ABI we implement now, so this is a substantial new subsystem, not an extension of the current WASI layer.
## Current state
- The host is hard-bound to a single import module: `const WASI_MODULE = "wasi_snapshot_preview1"` in [`src/runtime/wasi/mod.rs`](https://github.com/anistark/wasmrun/blob/d3b760c/src/runtime/wasi/mod.rs#L306).
- The interpreter's value type is numeric-only (`I32/I64/F32/F64`) with no reference types, in [`src/runtime/core/values.rs`](https://github.com/anistark/wasmrun/blob/d3b760c/src/runtime/core/values.rs#L4).
- The module parser validates the magic bytes but ignores the version/layer field, so it cannot yet distinguish a core module from a component: [`src/runtime/core/module.rs`](https://github.com/anistark/wasmrun/blob/d3b760c/src/runtime/core/module.rs#L158).
- The manifest `wasi` field exists but is cosmetic, set to `"wasip1"` and only copied around, never used to select behavior: [`src/runtime/runtime_cache.rs`](https://github.com/anistark/wasmrun/blob/d3b760c/src/runtime/runtime_cache.rs#L37).
## Design decisions
**Version is fixed in the binary at compile time, not chosen at run time.** A `.wasm` targets a specific WASI version via its build target (`wasm32-wasip1` → core module/0.1; `wasm32-wasip2`/`wasip3` → component). A 0.2 binary cannot run "as 0.1"; its imports won't link.
- **Selection:** wasmrun **auto-detects and dispatches**, it does not ask the user. Read header bytes 4 to 7 (`01 00 00 00` = core module → 0.1 engine; `0d 00 01 00` = component → Component Model engine), then read the imported interface version strings (`@0.2.x` vs `@0.3.x`) to pick 0.2 vs 0.3.
- **The user's only lever** is the compile target when building their own source through wasmrun (a build-time concern, not a `run` flag).
- **Default:** auto-detect when running an arbitrary module (the binary dictates it). Where wasmrun controls the build, default to the most mature version (0.1 → 0.2 over time). **0.3 stays opt-in** until language toolchains catch up (currently Wasmtime 43+ / jco only).
- Keep 0.1 working: this is additive and should **not** be a breaking change. 0.2 may be supported directly or polyfilled on top of 0.3.
## What needs implementing (high level)
1. **Reference types** in the interpreter value model: the gating prerequisite for anything Component-Model-based (also unblocks WasmGC).
2. **Component Model parser**: component sections, embedded core modules, type/instantiation/canon sections.
3. **Canonical ABI**: lifting/lowering between core values and high-level WIT types (`string`, `list`, `record`, `variant`, `resource`).
4. **WASI 0.2 worlds**: `wasi:cli`, `wasi:filesystem`, `wasi:clocks`, `wasi:random`, `wasi:io`, `wasi:sockets`, etc.
5. **WASI 0.3 async**: `async` funcs, `stream`, `future`, and a host-managed shared event loop.
## Other surfaces to update
- `src/runtime/core/module.rs`: read version/layer bytes; branch module vs component (detection seam).
- `src/utils/wasm_analysis.rs` + `src/commands/module_display.rs`: recognize components and report the detected WASI version (both assume a core module today).
- Language plugins (`src/plugin/languages/*.rs`): add component build targets to *produce* 0.2/0.3 output (Rust is currently `wasm32-unknown-unknown`, Go uses `wasi`/`wasm`).
- `src/runtime/runtime_cache.rs`: manifest can emit `wasip2`/`wasip3` (the field is already free-form); optionally list multiple WASI variants per language.
- `src/agent/*`: decide whether the agent executor may run components.
- `src/cli.rs`: the long_about advertises "full WASI support"; add an optional build-time `--wasi-version` override.
- Docs, README, and example projects.
## Proposed phasing
- [ ] Phase 0: reference types in the interpreter
- [ ] Phase 1: component detection + Component Model parser
- [ ] Phase 2: canonical ABI
- [ ] Phase 3: WASI 0.2 worlds
- [ ] Phase 4: WASI 0.3 async
## References
- [Bytecode Alliance: WASI 0.3 Launched](https://bytecodealliance.org/articles/WASI-0.3)
- [WebAssembly/WASI v0.3.0 release](https://github.com/WebAssembly/WASI/releases/tag/v0.3.0)
- [WASI.dev roadmap](https://wasi.dev/roadmap)
- [The Road to Component Model 1.0](https://bytecodealliance.org/articles/the-road-to-component-model-1-0)
Guía de contribución
Evaluación
Este issue todavía no se ha evaluado.