Hello, WASI

#programming #rust 2019-05-23

A quick tutorial on how you can get started with WASI - The WebAssembly System Interface - in four simple steps.

First, you're going to make sure you have Rust installed on your system:

curl https://sh.rustup.rs -sSf | sh

Second, you're going to get Rust nightly version and add the wasm32-wasi target on your toolchain.

rustup update;
rustup toolchain install nightly;
rustup target add wasm32-wasi --toolchain nightly;

Third, you're going set up a WASI runtime in which you can run your WASI-targeting applications. wasmtime is one of your options:

git clone --recurse-submodules https://github.com/CraneStation/wasmtime.git;
cd wasmtime;
cargo build --release;
cp target/release/wasmtime ~/.bin/;
# ^ Or another directory that is in your executable $PATH
cd ..;

Fourth, you're going to create a WASI project and run it:

cargo init hello-wasi;
cd hello-wasi;
sed -i -e 's/world/WASI/' src/main.rs;
cargo +nightly build --target wasm32-wasi;
wasmtime target/wasm32-wasi/debug/hello-wasi.wasm;

Hello, WASI!

That's it!