Skip to content

Commit

Permalink
Describe workflow for testing preview2 components (#7292)
Browse files Browse the repository at this point in the history
* Describe workflow for testing preview2 components

* format text
  • Loading branch information
cdmurph32 authored Oct 25, 2023
1 parent 205a5d2 commit 038ddfe
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions docs/contributing-implementing-wasm-proposals.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`

0 comments on commit 038ddfe

Please sign in to comment.