Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add diagnostics for CMake ConfigHeader errors #20538

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

MrDmitry
Copy link
Contributor

@MrDmitry MrDmitry commented Jul 8, 2024

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 MrDmitry marked this pull request as ready for review July 8, 2024 13:36
@MrDmitry MrDmitry force-pushed the feat/cmake_config_diagnostics branch from 8167b48 to 533b9ef Compare September 9, 2024 06:09
@MrDmitry MrDmitry force-pushed the feat/cmake_config_diagnostics branch from 6a26941 to 9a7ea22 Compare October 22, 2024 05:57
@MrDmitry MrDmitry force-pushed the feat/cmake_config_diagnostics branch from 9a7ea22 to fb350dc Compare November 8, 2024 06:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ConfigHeader silently swallows invalid values
1 participant