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 {...@@ -352,8 +352,9 @@ pub fn build(b: *std.Build) !void {
352 const cmake_cfg = if (static_llvm) null else blk: {352 const cmake_cfg = if (static_llvm) null else blk: {
353 const io = b.graph.io;353 const io = b.graph.io;
354 const cwd: Io.Dir = .cwd();354 const cwd: Io.Dir = .cwd();
355 if (findConfigH(b, config_h_path_option)) |config_h_path| {355 if (try 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;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));
357 break :blk parseConfigH(b, file_contents);358 break :blk parseConfigH(b, file_contents);
358 } else {359 } else {
359 std.log.warn("config.h could not be located automatically", .{});360 std.log.warn("config.h could not be located automatically", .{});
...@@ -1187,7 +1188,7 @@ const CMakeConfig = struct {...@@ -1187,7 +1188,7 @@ const CMakeConfig = struct {
11871188
1188const max_config_h_bytes = 1 * 1024 * 1024;1189const 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 {
1191 const arena = b.graph.arena;1192 const arena = b.graph.arena;
1192 const io = b.graph.io;1193 const io = b.graph.io;
1193 const cwd: Io.Dir = .cwd();1194 const cwd: Io.Dir = .cwd();
...@@ -1205,22 +1206,26 @@ fn findConfigH(b: *std.Build, config_h_path_option: ?[]const u8) ?[]const u8 {...@@ -1205,22 +1206,26 @@ fn findConfigH(b: *std.Build, config_h_path_option: ?[]const u8) ?[]const u8 {
12051206
1206 var check_dir = fs.path.dirname(b.graph.zig_exe).?;1207 var check_dir = fs.path.dirname(b.graph.zig_exe).?;
1207 while (true) {1208 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 };
1209 defer dir.close(io);1212 defer dir.close(io);
12101213
1211 // Check if config.h is present in dir1214 // Check if config.h is present in dir
1212 var config_h_or_err = dir.openFile(io, "config.h", .{});1215 var config_h_or_err = dir.openFile(io, "config.h", .{});
1213 if (config_h_or_err) |*file| {1216 if (config_h_or_err) |*file| {
1214 file.close(io);1217 file.close(io);
1215 return fs.path.join(1218 return try fs.path.join(
1216 arena,1219 arena,
1217 &[_][]const u8{ check_dir, "config.h" },1220 &[_][]const u8{ check_dir, "config.h" },
1218 ) catch unreachable;1221 );
1219 } else |e| switch (e) {1222 } else |err| switch (err) {
1220 error.FileNotFound => {},1223 error.FileNotFound => {},
1221 else => unreachable,1224 else => |e| std.debug.panic("failed to check for config.h in {q}: {t}", .{ check_dir, e }),
1222 }1225 }
12231226
1227 b.dependOnFileMetadata(b.graph.cwdRelativePath(check_dir).path(b, "config.h"));
1228
1224 // Check if we reached the source root by looking for .git, and bail if so1229 // Check if we reached the source root by looking for .git, and bail if so
1225 var git_dir_or_err = dir.openDir(io, ".git", .{});1230 var git_dir_or_err = dir.openDir(io, ".git", .{});
1226 if (git_dir_or_err) |*git_dir| {1231 if (git_dir_or_err) |*git_dir| {