2024 is drawing its last breath and just in time for the new year, I’ve completed my port of SDL3 to the Zig build system. SDL3 is still in preview (current version: 3.1.6), but its ABI is stable as of 3.1.3 and it has been used in production by Valve for some time now.
The goal for this package was an SDL build that Just Works™ with as few prerequisites and caveats as possible. To my knowledge, this is the first port of SDL that
- simultaneously supports Zig
0.12.1
,0.13.0
and0.14.0-dev
, - builds SDL with no modifications to the upstream SDL source code,
- supports cross-compiling for Windows and Linux from any host system (macOS is unfortunately out of scope because of Xcode license terms),
- supports all Linux feature backends, for example both Wayland and X11 for video, and
- declares all license information upfront (if you’re someone who thinks that’s important).
(Note that this package was developed from scratch by carefully observing and replicating the behavior of the upstream SDL CMake build scripts. It was not based on any pre-existing SDL port.)
To demonstrate how simple and painless this package makes using SDL3, I’ve prepared two example games:
Breakout
Simple Breakout clone using SDL3 for video, audio, input, etc. Demonstrates how to @cImport
, initialize and use SDL3 from Zig code.
git clone https://github.com/castholm/zig-examples.git
cd zig-examples/breakout
zig build run
Snake
SDL’s example Snake game, written in C, built using the Zig build system. Demonstrates how to swap out an existing C project’s build system for zig build
.
git clone https://github.com/castholm/zig-examples.git
cd zig-examples/snake
zig build run
Please let me know if you find this package useful, or if you run into any issues when using it. The timing of this announcement holds a bit of a special meaning to me, because I wrote my first line of Zig code on the evening of December 31 2022 (shoutouts to Ziglings!)
My goal is to keep this package maintained and in sync with future SDL3 releases, and to incrementally add support for more targets (for example, I am looking into wasm32-emscripten-none
).