Our great sponsors
-
InfluxDB
Power Real-Time Data Analytics at Scale. Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.
-
WorkOS
The modern identity platform for B2B SaaS. The APIs are flexible and easy-to-use, supporting authentication, user identity, and complex enterprise features like SSO and SCIM provisioning.
-
minimal-zig-wasm-canvas
A minimal example showing how HTML5's canvas, wasm memory and zig can interact.
We use WASM to provide in-browser Scrabble-like analysis at https://woogles.io at the end of games. The original analyzer was built in Rust and the speed is close to native.
If you're targeting browsers then the Rust WASM book goes over using the wasm32-unknown target and wasm_bindgen to auto-generate the JS glue
https://rustwasm.github.io/docs/book/
If you're targeting some WASI-based platform then it's more straightforward, as there's no need to generate glue code. CF have a quick example
https://blog.cloudflare.com/announcing-wasi-on-workers/
For a somewhat more complete example which runs in browsers, check out my little pacman.zig toy project [0]. This is cheating a bit by using Emscripten toolchain as 'sysroot' (needed for the Emscripten headers), and the Emscripten linker to create the html+js+wasm output file, but the actual code is all compiled with the Zig compiler.
The interesting part is that the platform abstraction is provided by the sokol headers [1], with auto-generated Zig bindings [2]. It's interesting because the C headers use "Emscripten magic" (mainly embedding Javascript snippets in the C sources via the EM_JS() macro), and the Zig compiler is able to compile this (when it has access to the Emscripten headers).
It would be nice if the "Emscripten platform" could get the same type of cross-compilation support as the desktop platforms eventually, but apart from bundling the Emscripten headers, this would also require to implement some of the "Emscripten magic" in the linker step.
Maybe projects like WaJIC can help with this (this basically implements the "Emscripten magic" of embedding Javascript snippets in C/C++ source code, but without Emscripten (only the wasm-opt tool is needed AFAIK).
Anyway... it's a lot of fun to tinker around with this stuff in Zig, and watch how it's all taking shape :)
[0] https://github.com/floooh/pacman.zig
Wow, this just straight rips off my (not very great) example I've been maintaining for a while:
https://github.com/meheleventyone/zig-wasm-test
Thanks for the credit yurivish! :(