zig icon indicating copy to clipboard operation
zig copied to clipboard

Add diagnostics for CMake ConfigHeader errors

Open MrDmitry opened this issue 1 year ago • 0 comments

Follow-up to #20234

Closes #17263 by adding an error message about unused variables

> ls
build.zig  foo.h.in

> cat foo.h.in
#define a @b@
#define b ${#}
#define c ${}

> cat build.zig
const std = @import("std");

pub fn build(b: *std.Build) void {
    const out_h = b.addConfigHeader(.{
        .style = .{ .cmake = b.path("foo.h.in") },
    }, .{ .unused = .undef, .also_unused = "" });
    const install_file = b.addInstallFileWithDir(out_h.getOutput(), .header, "foo.h");
    b.getInstallStep().dependOn(&install_file.step);
}

> zig build
install
└─ install generated to foo.h
   └─ configure cmake header foo.h.in to foo.h failure
error: /home/dmitry/zig/17263/foo.h.in:1:11: unable to substitute variable: UndefinedVariable: b
error: /home/dmitry/zig/17263/foo.h.in:2:13: unable to substitute variable: InvalidCharacter: #
error: /home/dmitry/zig/17263/foo.h.in:3:11: unable to substitute variable: MissingName: 
error: /home/dmitry/zig/17263/foo.h.in: error: unused variables: { unused, also_unused }
error: HeaderConfigFailed
Build Summary: 0/3 steps succeeded; 1 failed (disable with --summary none)
install transitive failure
└─ install generated to foo.h transitive failure
   └─ configure cmake header foo.h.in to foo.h failure
error: the following build command failed with exit code 1:
...

MrDmitry avatar Jul 08 '24 08:07 MrDmitry