cargo install wasm-toolsnpm install -g @bytecodealliance/jco- rust_counter
- go_counter
- python_counter
- dotnet_counter
- moonbit_counter
cd examples/[example]Compile the example
cargo build --release --target wasm32-unknown-unknown
wasm-tools component new ./target/wasm32-unknown-unknown/release/[example].wasm -o ./component.wasmInstall tiny-go
Generate types from wit
go get go.bytecodealliance.org/cmd/wit-bindgen-go
go run go.bytecodealliance.org/cmd/wit-bindgen-go generate -o internal/ ./witCompile the example
tinygo build --target=wasip2 --no-debug -o component.wasm --wit-package ./wit --wit-world go-example-world main.goGenerate types from wit
componentize-py --wit-path ../../wit --world browser bindings .Compile the example
componentize-py --wit-path ../../wit --world browser componentize app -o component.wasmCompile the example
dotnet build --configuration Release
cp bin/Release/net10.0/wasi-wasm/native/dotnet_counter.wasm ./component.wasmGenerate types from wit
Note: this will override the existing example code.
wit-bindgen moonbit ../../wit --world browserCompile the example
moon build --target wasm
wasm-tools component embed ../../wit target/wasm/release/build/gen/gen.wasm -o target/gen.wasm --world browser --encoding utf16
wasm-tools component new target/gen.wasm -o component.wasmjco transpile --async-mode jspi --no-nodejs-compat ./component.wasm -o static --async-exports "start" --async-wasi-imports --async-wasi-exports --map 'wasi:io/poll=../../poll.js#poll' --map 'webidl:browser/global=../../webidl.js#idlProxy' --map 'wasi:filesystem/*=https://cdn.jsdelivr.net/npm/@bytecodealliance/preview2-shim/lib/browser/filesystem.js#*' --map 'wasi:clocks/*=https://cdn.jsdelivr.net/npm/@bytecodealliance/preview2-shim/lib/browser/clocks.js#*' --map 'wasi:io/*=https://cdn.jsdelivr.net/npm/@bytecodealliance/preview2-shim/lib/browser/io.js#*' --map 'wasi:random/*=https://cdn.jsdelivr.net/npm/@bytecodealliance/preview2-shim/lib/browser/random.js#*' --map 'wasi:cli/*=https://cdn.jsdelivr.net/npm/@bytecodealliance/preview2-shim/lib/browser/cli.js#*' --map 'wasi:sockets/*=https://cdn.jsdelivr.net/npm/@bytecodealliance/preview2-shim/lib/browser/sockets.js#*'Then serve the examples directory with an http server.
E.g. the python http server:
cd ../
python -m http.serverPoint your browser to http://localhost:[PORT]/?example=[example]