authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2026-10-18 21:16:17+01:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2026-10-19 18:30:35+01:00
logf67c5e92fc010b4fd43638d9ff9c996de014155d
treec0d84c732e28203a76f9890c09e6b5179290424f
parent067f8dcb375aae6cfe1fdc66cf70372067382c49
signature Commit is signed but in an unrecognized format.

build.zig: add file/directory dependencies searching for config.h


1 files changed, 13 insertions(+), 8 deletions(-)

build.zig+13-8
......@@ -352,8 +352,9 @@ pub fn build(b: *std.Build) !void {
352352 const cmake_cfg = if (static_llvm) null else blk: {
353353 const io = b.graph.io;
354354 const cwd: Io.Dir = .cwd();
355 if (findConfigH(b, config_h_path_option)) |config_h_path| {
356 const file_contents = cwd.readFileAlloc(io, config_h_path, arena, .limited(max_config_h_bytes)) catch unreachable;
355 if (try findConfigH(b, config_h_path_option)) |config_h_path| {
356 b.dependOnFileContents(b.graph.cwdRelativePath(config_h_path));
357 const file_contents = try cwd.readFileAlloc(io, config_h_path, arena, .limited(max_config_h_bytes));
357358 break :blk parseConfigH(b, file_contents);
358359 } else {
359360 std.log.warn("config.h could not be located automatically", .{});
......@@ -1187,7 +1188,7 @@ const CMakeConfig = struct {
11871188
11881189const max_config_h_bytes = 1 * 1024 * 1024;
11891190
1190fn findConfigH(b: *std.Build, config_h_path_option: ?[]const u8) ?[]const u8 {
1191fn findConfigH(b: *std.Build, config_h_path_option: ?[]const u8) std.mem.Allocator.Error!?[]const u8 {
11911192 const arena = b.graph.arena;
11921193 const io = b.graph.io;
11931194 const cwd: Io.Dir = .cwd();
......@@ -1205,22 +1206,26 @@ fn findConfigH(b: *std.Build, config_h_path_option: ?[]const u8) ?[]const u8 {
12051206
12061207 var check_dir = fs.path.dirname(b.graph.zig_exe).?;
12071208 while (true) {
1208 var dir = cwd.openDir(io, check_dir, .{}) catch unreachable;
1209 var dir = cwd.openDir(io, check_dir, .{}) catch |err| {
1210 std.debug.panic("failed to open {q}: {t}", .{ check_dir, err });
1211 };
12091212 defer dir.close(io);
12101213
12111214 // Check if config.h is present in dir
12121215 var config_h_or_err = dir.openFile(io, "config.h", .{});
12131216 if (config_h_or_err) |*file| {
12141217 file.close(io);
1215 return fs.path.join(
1218 return try fs.path.join(
12161219 arena,
12171220 &[_][]const u8{ check_dir, "config.h" },
1218 ) catch unreachable;
1219 } else |e| switch (e) {
1221 );
1222 } else |err| switch (err) {
12201223 error.FileNotFound => {},
1221 else => unreachable,
1224 else => |e| std.debug.panic("failed to check for config.h in {q}: {t}", .{ check_dir, e }),
12221225 }
12231226
1227 b.dependOnFileMetadata(b.graph.cwdRelativePath(check_dir).path(b, "config.h"));
1228
12241229 // Check if we reached the source root by looking for .git, and bail if so
12251230 var git_dir_or_err = dir.openDir(io, ".git", .{});
12261231 if (git_dir_or_err) |*git_dir| {