zig icon indicating copy to clipboard operation
zig copied to clipboard

Incremental compilation doesn't update build after changes to global struct with default value

Open Zirunis opened this issue 1 month ago • 0 comments

Zig Version

0.16.0-dev.1246+4b593a6c2

Steps to Reproduce and Observed Behavior

I observed this in my codebase and tried to reproduce it with a tiny example. The title may be too specific and this may actually happen differently as well, I just haven't investigated further.

  1. zig init
  2. Replace contents of main.zig with this:
const std = @import("std");

const CONFIG = struct {
    number: u8 = 42,
};

pub fn main() void {
    const cfg = CONFIG{};
    std.debug.print("All your {d} are belong to us.\n", .{cfg.number});
}
  1. zig build --watch -fincremental
  2. Run the executable. Output: All your 42 are belong to us.
  3. Change the number to something else. Example main.zig:
const std = @import("std");

const CONFIG = struct {
    number: u8 = 69,
};

pub fn main() void {
    const cfg = CONFIG{};
    std.debug.print("All your {d} are belong to us.\n", .{cfg.number});
}
  1. We can observe in the terminal window with the incremental compiler running that it detected the change and went through the build steps: Build Summary: 3/3 steps succeeded
  2. However: The executable actually isn't replaced (probably no difference found) and therefore obviously the output doesn't change: All your 42 are belong to us.

Optional: 8. zig build 9. Run the new executable. Output: All your 69 are belong to us.

Expected Behavior

Incremental compilation should detect the change and correctly rebuild the executable. The executable after completing the build steps should be the same as if on was running zig build again.

Zirunis avatar Nov 09 '25 00:11 Zirunis