#Raylib but more about build.zig and run

1 messages · Page 1 of 1 (latest)

lime willow
#

So I have raylib running via simple zon dependency, with all the great work done to have dependencies arrive and the raylib build work. This is in 0.12.0 release and raylib current.

If I do zig build it builds, and zig build run makes it run, perfectly.

However, if I just try a zig run src/main.zig then it complains:

src\main.zig:2:16: error: C import failed
const raylib = @cImport(@cInclude("raylib.h"));
               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src\main.zig:2:16: note: libc headers not available; compilation does not link against libc
...AppData\Local\zig\o\a3003dadc96a33bc65606add55ab48f4\cimport.h:1:10: error: 'raylib.h' file not found
#include <raylib.h>
         ^

I know the exe built just fine, so am I expecting too much ? I understand that perhaps zig run doesn't have all the benefits of the build system, so perhaps this is to be expected ?

Alongside this, how do I specify any additional options to raylib ? The dependency is added via the following:

    const raylib_dep = b.dependency("raylib", .{
        .target = target,
        .optimize = optimize,
    });

and I note in the build.zig for raylib that there are many options, but I can't figure out how to set them (for example, enabling raygui).

Thanks for any pointers.

foggy rapids
#

zig run requires a lot more work to get the command you want, since it doesnt use your build.zig at all. ie passing flags, include paths, module paths, etc.
to pass options to raylib you can just do

    const raylib_dep = b.dependency("raylib", .{
        .target = target,
        .optimize = optimize,
.linux_display_backend = .X11,
        .platform_drm = true,
        .opengl_version = .auto,
    });
#

to add raygui you have to do this:

const raygui_dep = b.dependency("raygui", .{});
@import("raylib").addRaygui(b, raylib_dep.artifact("raylib"), raygui_dep);