Can you locate and copy dependency files specified in .zon files?

I took a closer look at your project and I think the way you are handling that C file is not really a good solution. Currently you are generating a new file and passing that to the addStaticLibrary command:

-    const generate_raygui_c = b.addWriteFiles();
-    const generated_file = generate_raygui_c.add("src/raygui.c", "#define RAYGUI_IMPLEMENTATION\n#define RAYGUI_STANDALONE\n#include \"raygui.h\"\n");
     // Since this repo doesn't have a build.zig, we will add it as a static library to link to the exe
     const raygui_lib = b.addStaticLibrary(.{
         .name = "raygui",
-        .root_source_file = generated_file,
         .link_libc = true,
         .optimize = optimize,
         .target = target,
     });
-    raygui_lib.step.dependOn(&generate_raygui_c.step);

But a better solution would to use addCSourceFile, passing the defines as command line arguments:

     raygui_lib.addIncludePath(raygui_package.path("src/"));
     raygui_lib.addIncludePath(raylib_package.path("src/"));
+    raygui_lib.addCSourceFile(.{ .file = raygui_package.path("src/raygui.h"), .flags = &[_][]const u8 {"-DRAYGUI_IMPLEMENTATION"}});
     raygui_lib.linkLibrary(raylib_artifact); // raygui depends on raylib

Note that I removed the RAYGUI_STANDALONE flag, which may have been the root issue.
That flag prevents raygui.h from including raylib.h which was probably the cause for the missing symbols.

Apart from that you also need to add the include path to the executable:

+    exe.addIncludePath(raygui_package.path("src/"));
+    exe.addIncludePath(raylib_package.path("src/"));

And you need to change the cImport, given that raygui automatically include raylib:

const rl = @cImport({
    @cInclude("raygui.h");
    @cInclude("raymath.h");
    @cInclude("rlgl.h");
});

Oh and you also messed up the capitalization of all raylib functions in your main.zig.

6 Likes