| 1 | # Starting your raylib project with Zig (0.16.0) |
| 2 | |
| 3 | ## How to compile and run it |
| 4 | |
| 5 | To compile the project: |
| 6 | |
| 7 | ```sh |
| 8 | zig build |
| 9 | ``` |
| 10 | |
| 11 | To run the project: |
| 12 | |
| 13 | ```sh |
| 14 | zig build run |
| 15 | ``` |
| 16 | |
| 17 | ## Compile with different optimization |
| 18 | |
| 19 | To change from debug to release build you can do it with the `-Doptimze=` flag. |
| 20 | |
| 21 | ``` |
| 22 | Debug |
| 23 | ReleaseSafe |
| 24 | ReleaseFast |
| 25 | ReleaseSmall |
| 26 | ``` |
| 27 | |
| 28 | ## Choose a different platform |
| 29 | |
| 30 | To compile with a different platform you can use the `-Dplatform=` flag. |
| 31 | Here all the options: |
| 32 | |
| 33 | ``` |
| 34 | glfw |
| 35 | rgfw |
| 36 | sdl |
| 37 | sdl2 |
| 38 | sdl3 |
| 39 | memory |
| 40 | win32 |
| 41 | drm |
| 42 | android |
| 43 | ``` |
| 44 | |
| 45 | In this example the platform `sdl` and `sdl2` are not supported |
| 46 | |
| 47 | Important for the android platform you also have to compile for the right target |
| 48 | |
| 49 | ## Compile for a different target |
| 50 | |
| 51 | To compile for a different [target](https://ziglang.org/download/0.16.0/release-notes.html#Support-Table) you can use the `-Dtarget=` flag. |
| 52 | Not all targets are supported |
| 53 | |
| 54 | ## Example: Compile for web and run it |
| 55 | |
| 56 | To compile for the web we use emscripten and you run it like that: |
| 57 | |
| 58 | ```sh |
| 59 | zig build -Dtarget=wasm32-emscripten |
| 60 | ``` |
| 61 | |
| 62 | To run it we do: |
| 63 | |
| 64 | ```sh |
| 65 | zig build run -Dtarget=wasm32-emscripten |
| 66 | ``` |
| 67 | |
| 68 | And to make a relase build we do: |
| 69 | |
| 70 | ```sh |
| 71 | zig build -Dtarget=wasm32-emscripten -Doptimize=ReleaseFast |
| 72 | ``` |
| 73 | |
| 74 | If we want to use rgfw for the web build we could do: |
| 75 | |
| 76 | ```sh |
| 77 | zig build -Dplatform=rgfw -Dtarget=wasm32-emscripten -Doptimize=ReleaseFast |
| 78 | ``` |
| 79 | |
| 80 | ## Compiling the Zig code? Just add `-Dzig` and try out zig ;) |
| 81 | |
| 82 | ## More Resources |
| 83 | |
| 84 | See [Zig Build System](https://ziglang.org/learn/build-system/) |