Skip to content

Commit 67c4256

Browse files
committed
build.zig: Try harder to find "config.h"
Now that we're building stage3 frequently, I noticed that stage2 can't auto-locate config.h because it's not in its own (or a parent) directory. This change makes `build.zig` try a little harder to find the `config.h` from CMake: It will check for "build"/"stage1" directories that might contain the file. More importantly, it will warn the user if it could not be located.
1 parent e867127 commit 67c4256

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

build.zig

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -683,17 +683,24 @@ fn findAndParseConfigH(b: *Builder, config_h_path_option: ?[]const u8) ?CMakeCon
683683
var dir = fs.cwd().openDir(check_dir, .{}) catch unreachable;
684684
defer dir.close();
685685

686-
break :blk dir.readFileAlloc(b.allocator, "config.h", max_config_h_bytes) catch |err| switch (err) {
687-
error.FileNotFound => {
688-
const new_check_dir = fs.path.dirname(check_dir);
689-
if (new_check_dir == null or mem.eql(u8, new_check_dir.?, check_dir)) {
690-
return null;
691-
}
692-
check_dir = new_check_dir.?;
693-
continue;
694-
},
695-
else => unreachable,
696-
};
686+
for ([_]?[]const u8{ null, "build", "stage1" }) |build_dir| {
687+
var sub_dir = dir;
688+
if (build_dir) |d|
689+
sub_dir = dir.openDir(d, .{}) catch continue;
690+
691+
break :blk sub_dir.readFileAlloc(b.allocator, "config.h", max_config_h_bytes) catch |err| switch (err) {
692+
error.FileNotFound => continue,
693+
else => unreachable,
694+
};
695+
} else {
696+
const new_check_dir = fs.path.dirname(check_dir);
697+
if (new_check_dir == null or mem.eql(u8, new_check_dir.?, check_dir)) {
698+
std.log.warn("config.h could not be located automatically. Consider providing it explicitly via \"-Dconfig_h\"", .{});
699+
return null;
700+
}
701+
check_dir = new_check_dir.?;
702+
continue;
703+
}
697704
} else unreachable; // TODO should not need `else unreachable`.
698705
};
699706

0 commit comments

Comments
 (0)