Skip to content

kubkon/zig-wasi-tutorial

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 

Repository files navigation

zig-wasi-tutorial

Zig's take on the official WASI tutorial. Hopefully, this tutorial will serve as a decent intro to WASI from Zig lang.

Building

At the time of writing (May 19th, 2020), WASI support in Zig has only just been merged into upstream. Therefore, to build the tutorial you'll need to get your hands on the nightly Zig which can be found here.

After you've successfully installed nightly Zig, simply run

$ zig build

Note that for your convenience, I've made wasm32-wasi target the default in build.zig, so there's no need to specify the target manually.

You should now have the compiled WASI module in zig-cache/bin/main.wasm.

Running

If you haven't already, go and get yourself a fresh copy of wasmtime.

Next, create some sample input

$ echo "WASI is really cool!" > in.txt

Run it using wasmtime

$ wasmtime --dir=. zig-cache/bin/main.wasm in.txt out.txt

As a result, you should now have out.txt file created with the same contents as in.txt.