3 ms·
How is the compilation to WASM/WebGL realized here? Asking out of curiosity, but don't have a lot of time to research.
by jstimpfle 8y ago
How is the compilation to WASM/WebGL realized here? Asking out of curiosity, but don't have a lot of time to research.
- flohofwoe 8y agoAs far as I can see: Compilation to WebAssembly bytecode is done via the new WASM backend in LLVM (the Zig compiler sits on top of LLVM). The whole interfacing with WebGL and WebAudio is actually quite interesting. It's not done through a runtime provided by the compiler SDK (as it is usually done with emscripten), but instead the Zig-to-JS binding is all done "manually" in the project itself. There are 2 small "shim files" for WebGL/WebAudio and DOM access written in JS here: https://github.com/raulgrell/tetris/blob/master/env.js https://github.com/raulgrell/tetris/blob/master/env.js and here: https://github.com/raulgrell/tetris/blob/master/dom.js https://github.com/raulgrell/tetris/blob/master/dom.js ...and associated Zig interop files here: https://github.com/raulgrell/tetris/blob/master/src/webgl.zig https://github.com/raulgrell/tetris/blob/master/src/webgl.zi... and here: https://github.com/raulgrell/tetris/blob/master/src/dom.zig https://github.com/raulgrell/tetris/blob/master/src/dom.zig It's really surprisingly little (and clean) code for doing that sort of thing IMHO.
- fengb 8y agoZig has wasm as a built-in compile target — derived from LLVM 8 so Clang has the same functionality. The link to Dom/OpenGL is still a manual process but there’s some efforts generating the necessary JavaScript helpers.