Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Zig is probably the most common tool to compile C/C++ to WebAssembly outside the browser, but the Zig language itself has first-class support for WebAssembly/WASI.

The resulting modules are small and very optimized.



The most common tool is Emscriptem, even the Rust toolchain depends on it.


Rusts wasm32-wasi and wasm32-unknown-unknown targets don't depend on Emscripten and they've been the preferred ways of targeting wasm for years now.

There is a wasm32-unknown-emscripten target but I think that's basically on life support if not outright deprecated. It was only really a stop-gap until native tooling like wasm_bindgen got fleshed out.


wasm32-unknown-emscripten is useful if you want to build a Rust program using SDL2 and GL for the Web, for example. But yes, as you said, it's much less used. Most Rust code on the Web is not a port of existing applications (which is what Emscripten focuses on), unlike C++.


Pity that not all tutorials have been updated, as I recently hit that bump, unfortunely I don't have the tutorial link any longer.


If you're targeting browsers then the Rust WASM book goes over using wasm32-unknown-unknown with 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, since no JS glue is needed. CF have a quick example

https://blog.cloudflare.com/announcing-wasi-on-workers/


Thanks for the links.


For modules to be run in a web browser, yes.

Not outside the browser, with WASI instead of a Javascript context.


A rounding error in market share.


Whenever there is a post relating to Zig, I can always rely on you to post negative comments for no real reason. I can understand not liking the language, but this is about the C/C++ compilation toolchain, which uses clang under the hood. Even if you think Zig is the worst language in the world, you can still use the toolchain without having to deal with the language at all.

I guess my fundamental question is, what does your comment add to the conversation? It seems like you're not even disagreeing with the fundamental premise; you just felt the need to diminish Zig simply because someone tried to acknowledge that it was useful for something.


Had the OP not stated that "Zig is probably the most common tool to compile C/C++ to WebAssembly outside the browser,...", I wouldn't have said anything.

You say it yourself, this is about the C and C++ toolchain offered by clang, ergo not Zig.

I only reply on hype regarding Zig, like the previous remark, or it being "safe", when it is as safe as Modula-2 already was in 1978.

Which while miles beyond C, it wasn't without flaws.

As for what adds to the conversation, I guess taming a bit the hype, regardless of the language.

If you are so attentive, you will have remarked that I spare no language, all get their share.

Finally, if you don't like my comments, page down is your friend.


What do you mean by “outside the browser”?






Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: