1

Based on my research *LibExeObjStep's defineCMacro allows me to #define just like I would in C but it's not getting included in the package output:

--pkg-begin raygui C:\git\raylib-zig-experiments\lib\raygui-zig.zig --pkg-end -D RAYGUI_IMPLEMENTATION (Note: it comes after --pkg-end)

This is the relevant snippet of my build.zig file where I'm attempting to include a c library:

pub fn addRaygui(exe: *LibExeObjStep, target: std.zig.CrossTarget) *std.build.LibExeObjStep {
    const b = exe.builder;
    // Standard release options allow the person running `zig build` to select
    // between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall.
    const mode = b.standardReleaseOptions();

    const raygui = b.addStaticLibrary("raygui", srcdir ++ "/raygui.h");
    exe.defineCMacro("RAYGUI_IMPLEMENTATION", null);
    raygui.setTarget(target);
    raygui.setBuildMode(mode);
    // Make raylib.h available for import to raygui.h
    raygui.addIncludePath("raylib/src");
    raygui.linkLibC();

    const raylib_flags = &[_][]const u8{
        "-std=gnu99",
        "-DPLATFORM_DESKTOP",
        "-DGL_SILENCE_DEPRECATION=199309L",
        "-fno-sanitize=undefined", // https://github.com/raysan5/raylib/issues/1891
    };
    raygui.addCSourceFiles(&.{
        srcdir ++ "/raygui.c",
    }, raylib_flags);

    return raygui;
}

How do I structure my build.zig file so that the defineCMacro is invoked INSIDE of the package?

Jordan
  • 3,813
  • 4
  • 24
  • 33

1 Answers1

1

Turns out I had to call raygui.defineCMacroRaw("RAYGUI_IMPLEMENTATION"); on the raygui variable instead of on exe.

Jordan
  • 3,813
  • 4
  • 24
  • 33