seyhajin/webgpu-wasm-zig
🚀 A minimal WebGPU example written in Zig, compiled to WebAssembly (wasm). 🛠️ Ideal for experimenting and preparing for native development without i...
A minimal WebGPU example written in Zig, compiled to WebAssembly (wasm).
git clone https://github.com/seyhajin/webgpu-wasm-zig.git
Alternatively, download zip from Github repository and extract wherever you want.
Build the example with zig build
command, which will generate 3 new files (.html
, .js
, .wasm
).
zig build --sysroot [path/to/emsdk]/upstream/emscripten/cache/sysroot
Example with Emscripten installed with Homebrew (brew install emscripten
, v4.0.8) on macOS :
zig build --sysroot /usr/local/Cellar/emscripten/4.0.8/libexec/cache/sysroot
Or automatically search for the active version :
zig build --sysroot `readlink -f $(brew --prefix emscripten)`/libexec/cache/sysroot
NOTE
build.zig
is preconfigured to build towasm32-emscripten
target only.
CAUTION Must provide Emscripten sysroot via
--sysroot
argument.
Launch a web server to run example before open it to WebGPU compatible web browser (Chrome Canary, Brave Nightly, etc.).
e.g. : launch python3 -m http.server
and open web browser to localhost:8000
.
[!TIP] Use Live Server extension in Visual Studio Code to open the HTML file. This extension will update automatically page in real-time when you rebuild the example.