Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kubkon/zig-wasi-tutorial
Zig version of WASI tutorial https://github.com/bytecodealliance/wasmtime/blob/master/docs/WASI-tutorial.md
https://github.com/kubkon/zig-wasi-tutorial
Last synced: 11 days ago
JSON representation
Zig version of WASI tutorial https://github.com/bytecodealliance/wasmtime/blob/master/docs/WASI-tutorial.md
- Host: GitHub
- URL: https://github.com/kubkon/zig-wasi-tutorial
- Owner: kubkon
- License: mit
- Created: 2020-05-19T06:55:07.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2022-11-24T14:01:33.000Z (almost 2 years ago)
- Last Synced: 2024-10-15T02:43:29.678Z (25 days ago)
- Language: Zig
- Size: 5.86 KB
- Stars: 25
- Watchers: 4
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-wasi - zig-wasi-tutorial
README
# 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.[WASI tutorial]: https://github.com/bytecodealliance/wasmtime/blob/master/docs/WASI-tutorial.md
## 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](https://ziglang.org/download/).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`.
[Zig's official repo]: https://github.com/ziglang/zig
## Running
If you haven't already, go and get yourself a fresh copy of [`wasmtime`].
[`wasmtime`]: https://github.com/bytecodealliance/wasmtime/releases
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`.