Skip to content

🟪 Rust library compiled to WASM and distributed as a WASM component

License

Notifications You must be signed in to change notification settings

jcbhmr/hello-world-rust-wasm-component-lib

Repository files navigation

"Hello world!" Rust WebAssembly component library

🟪 Rust library compiled to WASM and distributed as a WASM component

Download WASM | View WIT | JavaScript bindings

🦀 Written in Rust
🟪 Modern WebAssembly Component example
🌎 Runs on any WebAssembly Component Runtime
📥 Imports some host functions
📤 Exports some functions
👩‍⚖️ 0BSD licensed template

Usage

WebAssembly

To get started just download the latest WASM artifact and use it in your favorite WebAssembly Component Runtime! Make sure you provide any required imports! 😉

Development

Rust WebAssembly

./just build

ℹ You'll need wasm-tools installed which you can get via cargo install wasm-tools.

You can inspect the output component WASM using something like this:

wasm-tools component wit target/wasm32-wasi/debug/*.wasm
#=> world my-component {
#  import print: func(msg: string)
#  export run: func()
# }

The wasi_snapshot_preview1.reactor.wasm is the adapter module to shim the component API over top of the existing WASI API. Keep it updated from bytecodealliance/wasmtime releases. Since this is a library we want the "reactor" version.

🚚 To create a new release, don't use the GitHub UI directly; use the draft release GitHub Actions workflow to create the initial draft release with the compiled WASM artifact. Then you can edit that release and publish it as normal. Make sure the version fields are correct before drafting the release; it's used to choose the v${version} tag name for the release and in publishing. Also try not to change the artifacts attached to the draft release; they are generated by GitHub Actions.