5 ms·
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/WA
by jedisct1 4y ago
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.
- dave84 4y agoWhat do you mean by “outside the browser”?
- clpm4j 4y agohttps://www.infoq.com/presentations/wasm-server-api/ https://www.infoq.com/presentations/wasm-server-api/
- syrusakbary 4y agoShameless plug :P https://www.youtube.com/watch?v=OHmycSgFAUs https://www.youtube.com/watch?v=OHmycSgFAUs
- pjmlp 4y agoThe most common tool is Emscriptem, even the Rust toolchain depends on it.
- jsheard 4y agoRusts 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.
- azakai 4y agowasm32-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++.
- pjmlp 4y agoPity that not all tutorials have been updated, as I recently hit that bump, unfortunely I don't have the tutorial link any longer.
- jsheard 4y agoIf 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/ 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/ https://blog.cloudflare.com/announcing-wasi-on-workers/
- pjmlp 4y agoThanks for the links.
- jedisct1 4y agoFor modules to be run in a web browser, yes. Not outside the browser, with WASI instead of a Javascript context.
- pjmlp 4y agoA rounding error in market share.
- defen 4y agoWhenever 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.
- pjmlp 4y agoHad 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.