diff --git a/docs/contributing-implementing-wasm-proposals.md b/docs/contributing-implementing-wasm-proposals.md index ce42e7e8fbb1..13fc927be173 100644 --- a/docs/contributing-implementing-wasm-proposals.md +++ b/docs/contributing-implementing-wasm-proposals.md @@ -124,3 +124,31 @@ default in Wasmtime, and can be used as a review checklist. [phases]: https://github.com/WebAssembly/meetings/blob/master/process/phases.md [WABT]: https://github.com/WebAssembly/wabt/ + +## Adding component functionality to WASI +The [cap-std](https://github.com/bytecodealliance/cap-std) repository contains +crates which implement the capability-based version of the Rust standard library +and extensions to that functionality. Once the functionality has been added to +the relevant crates of that repository, they can be added into wasmtime by +including them in the preview2 directory of the [wasi crate](https://github.com/bytecodealliance/wasmtime/tree/main/crates/wasi). + +Currently, WebAssembly modules which rely on preview2 ABI cannot be directly +executed by the wasmtime command. The following steps allow for testing such +changes. + +1. Build wasmtime with the changes `cargo build --release` + +2. Create a simple Webassembly module to test the new component functionality by +compiling your test code to the `wasm32-wasi` build target. + +3. Build the [wasi-preview1-component-adapter](https://github.com/bytecodealliance/wasmtime/tree/main/crates/wasi-preview1-component-adapter) +as a command adapter. `cargo build -p wasi-preview1-component-adapter --target +wasm32-wasi --release --features command --no-default-features` + +4. Use [wasm-tools](https://github.com/bytecodealliance/wasm-tools) to convert +the test module to a component. `wasm-tools component new --adapt +wasi_snapshot_preview1=wasi_snapshot_preview1.command.wasm -o component.wasm +path/to/test/module` + +5. Run the test component created in the previous step with the locally built +wasmtime. `wasmtime -W component-model=y -S preview2=y component.wasm`