Here is a fairly minimal example that uses raylib with the zig package manager.
I might add some more links/resources or maybe other examples as branches some other time.
Currently it is created with only a few modifications from the default zig init-exe project,
to make it easier to see what steps were required.
Thanks for that! A great starting point when wanting to use raylib indeed.
One remark would be that, on an actual project, I would keep the .optimize flag as is for raylib. You might want to build to ReleaseSmall for example. I tried BTW and got to 800K, so not bad.
As a zig noob I tried experimenting and got a weird error. I tried to compile with -Dtarget=x86_64-linux-gnu. Don’t ask me why, just playing around. And I got a failure:
raylib.zig build-lib raylib Debug x86_64-linux-gnu: error: error: unable to find Dynamic system library 'GL' using strategy 'paths_first'. searched paths:
/usr/lib/libGL.so
/usr/lib/libGL.a
error: unable to find Dynamic system library 'X11' using strategy 'paths_first'. searched paths:
/usr/lib/libX11.so
/usr/lib/libX11.a
I could be wrong but I believe that by default Zig only looks for system headers/libraries when compiling for native targets. It won’t look for them when you specify a target like -Dtarget=x86_64-linux-gnu even if your machine happens to be the same target.
If the raylib build.zig wants to look for system headers/libs when targeting any Linux target it might want to try to replicate how std.zig.system.NativePaths.detect does it.
I removed the hard coded raylib override with comments and instead replaced it with options and some hints printed to console on exit.
Now you can use zig build -Doptimize=ReleaseSmall -Dstrip=true for a small stripped build like you did, or you can use zig build -Draylib-optimize=ReleaseFast for a debug build of your own app that uses a release build of raylib (if you aren’t debugging raylib). The raylib-optimize defaults to the value of optimize when its not provided.