How to debug log values out of a build.zig

Hi! I’m trying to debug a build.zig and failing. Is there a way to debug “printf debugging” with build.zigs, IOW, is there a way I could log what values declarations inside my build.zig take? For example, something like this:

    const libsokol = dep_sokol.artifact("sokol_clib");
    for (libsokol.root_module.include_dirs.items) |include_dir| {
        const p = include_dir.path.join(b.allocator, "src/sokol/c") catch unreachable;
        std.debug.print("p = {any}\n", .{p});
        step.addIncludePath(p);
    }

But I can’t seem to find the output of the above print in any logs.

maybe

std.log.debug("p = {any}\n", .{p});

or

std.log.info("p = {any}\n", .{p});

Printing to stderr using std.debug.print to printf debug should work. Is it possible that the problem is as simple as that libsokol.root_module.include_dirs is empty and that that’s why none of your print statements are getting hit?

Hah, yeah, that was the problem. Thanks @castholm! And thanks @recombinant too, that probably works too.

What I’m trying to do is I’m linking in the sokol gfx zig package and in addition to using its Zig parts, I’d also like to include some of my C code that uses sokol_gfx.h that I know is included in the sokol package. I just don’t know exactly how to set up include dirs into my own project that’d point to Sokol’s include dirs. I also don’t know if the Sokol package should do something to register all of the .h files somehow in its own build.zig.

Assuming it’s GitHub - floooh/sokol-zig: Zig bindings for the sokol headers (https://github.com/floooh/sokol) we’re looking at, it doesn’t look like it exposes the headers (by for example using sokol_clib.installHeadersDirectory, which would make them automatically appear in the include path of any artifact that links with it).

But you might be able to include them by manually doing your_exe.root_module.addIncludePath(dep_sokol.path("src/sokol/c")). Try it and let us know if it works.

Correctly assumed! I found another by modifying sokol-zig but this :point_down: is better than what I had:

It works, indeed. Thank you very much for the help!

I was in fact studying your SDL package and just noticed the use of installHeadersDirectory but I hadn’t yet made the connection.

1 Like