Skip to content

Latest commit

 

History

History
 
 

examples

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

Examples need to be compiled to wasm components and published to the runtime.

Prerequisites

Building wasi_snapshot_preview1 adapter

At the time of writing, the adapater can be compiled from the bytecodealliance/preview2-prototyping repository.

git clone https://github.com/bytecodealliance/preview2-prototyping.git
cd preview2-prototyping

The wasi_snapshot_preview1.wasm module needs to be built to the wasm32-unknown-unknown target.

cargo build --target wasm32-unknown-unknown --release

This will build a wasm file in target/wasm32-unknown-unknown/release/wasi_snapshot_preview1.wasm. This can be used as the adapater to convert the wasm module to a component with the wasm-tools cli.

Building an example

Modules need to be built to wasm32-wasi, and converted to a wasm component.

Start by building the counter example.

cargo build -p counter --release --target wasm32-wasi

Then you can use the wasm-tools cli to convert this to a wasm component using the wasi_snapshot_preview1.wasm adapter.

wasm-tools component new \
  ./target/wasm32-wasi/release/counter.wasm \
  --adapt ../../bytecodealliance/preview2-prototyping/target/wasm32-unknown-unknown/release/wasi_snapshot_preview1.wasm \
  -o ./counter.component.wasm

You should be left with a counter.component.wasm file. You can publish this to the runtime using thalo-cli.

cargo run -p thalo_cli -- --url "http://localhost:4433" publish ./examples/counter/counter.esdl ./counter.component.wasm

Once published, you can finally execute a command.

cargo run -p thalo_cli -- --url "http://localhost:4433" execute Counter counter-1 increment '{"amount":1}'