Zig version: 0.14.0-dev.1210+54e48f7b7
Personal minimal template for raylib projects. There is no set list of what I intend to include, I'm just unlikely to make something before needing it in practice first. While this is made entirely for personal purposes, I am open to questions and suggestions if you somehow ended up here.
- Code and asset hotreloading
- Web export
Update to your raylib commit of choice:
zig fetch https://github.com/raysan5/raylib/archive/<hash>.tar.gz --save=raylibzig build [run] # Build for hotreloading
zig build [run] -Dstatic -Dstrip -Doptimize=Release-Fast # Build standalone executable
zig build reload # Rebuild game dll, game will try to reload it
zig build -Dstrip -Doptimize=ReleaseSmall -Dtarget=wasm32-emscripten --sysroot "%EMSDK%/upstream/emscripten" # Build for web (Windows)
zig build web # Build for web
zig build host # Host default web build directory (requires python)All variables should be strictly part of the Game struct. Container variables (globals) will break code hotreloading, as there will exist one copy of the variable in the executable and one in the library.
If we keep game state in the main process but keep the update function in a dll, we can swap out the update function without reseting state. This means restarting is still needed if you change the game struct variable definitions.
In dynamic (hotreloadable) builds, F2 restarts the game and F3 forces the game dll to reload. These keys are modifiable in main.zig. The init function is reloadable as well.
Dynamic builds need to be launched from the project root directory, as they need to see the asset directory.
Follow emscripten installation instructions from here.
To test web builds locally, run py -m http.server 8080 in zig-out/web/ or
py -m http.server 8080 --directory zig-out/web/ in the root folder, then
visit localhost:8080. zig build host is a shorthand for the latter.
Hotreloading is not supported for web builds.
- Remove raylib.zig in anticipation of usingnamespace getting removed.
- Include emsdk as build dependency.
- Hotreloading is very much Windows-only.
- Static exe can be launched from anywhere which currently requires a setAsCwd call. Can we do without it?
- Changing the installation prefix is far from working.
- Is
b.addSystemCommand(&.{ "zig", "build", ...})really a healthy way to make preset steps. - Documentation, general cleanup.