Hacker News new | ask | show | jobs
by jedisct1 1046 days ago
For WebAssembly, Zig really excels.

It's very memory efficient, everything compiles of the box to WebAssembly (freestanding or wasi), the resulting code is compact and fast, and it can take advantage of the latest WebAssembly extensions (threads, SIMD, ...) without any code changes. If you are using a webassembly-powered cloud service and not using Zig to write your functions, you are wasting money. Seriously.

Unsurprisingly, this is the most popular language to write games running on WebAssembly: https://wasm4.org/blog/jam-2-results/

Beyond the language, Zig is also a toolchain to compile C code to WebAssembly. When targeting WASI, it will seamlessly optimize the C library for size, performance or runtime features. I used it to port OpenSSL, BoringSSL and ffmpeg to WebAssembly. Works well.

Also, Zig can generate WebAssembly libraries that can then be included in other languages that support WebAssembly. Most of my Rust crates for WebAssembly are now actually written in Zig.

It's also supported by Extism, so can be used to easily write safe plugins for applications written in other languages.

2 comments

If you don't mind, since you have experience targetting WASM with both Rust & Zig, what advantages does Zig have over Rust in this particular use case?

Are the memory safety guarantees that Rust offers over Zig not as important or critical when targeting WASM?

I've been interested in checking out Zig for a while now.

Your link is really interesting, but it shows that Zig was the most popular language for writing games for a WebAssembly-based fantasy console with constrained resources, not that it's the most popular language for WebAssembly-based games overall.