mirror of
https://codeberg.org/ziglang/zig.git
synced 2026-10-28 10:45:48 +08:00
build.zig: add file/directory dependencies searching for config.h
This commit is contained in:
1 file changed
+13
-8
@@ -352,8 +352,9 @@ pub fn build(b: *std.Build) !void {
|
||||
const cmake_cfg = if (static_llvm) null else blk: {
|
||||
const io = b.graph.io;
|
||||
const cwd: Io.Dir = .cwd();
|
||||
if (findConfigH(b, config_h_path_option)) |config_h_path| {
|
||||
const file_contents = cwd.readFileAlloc(io, config_h_path, arena, .limited(max_config_h_bytes)) catch unreachable;
|
||||
if (try findConfigH(b, config_h_path_option)) |config_h_path| {
|
||||
b.dependOnFileContents(b.graph.cwdRelativePath(config_h_path));
|
||||
const file_contents = try cwd.readFileAlloc(io, config_h_path, arena, .limited(max_config_h_bytes));
|
||||
break :blk parseConfigH(b, file_contents);
|
||||
} else {
|
||||
std.log.warn("config.h could not be located automatically", .{});
|
||||
@@ -1187,7 +1188,7 @@ const CMakeConfig = struct {
|
||||
|
||||
const max_config_h_bytes = 1 * 1024 * 1024;
|
||||
|
||||
fn findConfigH(b: *std.Build, config_h_path_option: ?[]const u8) ?[]const u8 {
|
||||
fn findConfigH(b: *std.Build, config_h_path_option: ?[]const u8) std.mem.Allocator.Error!?[]const u8 {
|
||||
const arena = b.graph.arena;
|
||||
const io = b.graph.io;
|
||||
const cwd: Io.Dir = .cwd();
|
||||
@@ -1205,22 +1206,26 @@ fn findConfigH(b: *std.Build, config_h_path_option: ?[]const u8) ?[]const u8 {
|
||||
|
||||
var check_dir = fs.path.dirname(b.graph.zig_exe).?;
|
||||
while (true) {
|
||||
var dir = cwd.openDir(io, check_dir, .{}) catch unreachable;
|
||||
var dir = cwd.openDir(io, check_dir, .{}) catch |err| {
|
||||
std.debug.panic("failed to open {q}: {t}", .{ check_dir, err });
|
||||
};
|
||||
defer dir.close(io);
|
||||
|
||||
// Check if config.h is present in dir
|
||||
var config_h_or_err = dir.openFile(io, "config.h", .{});
|
||||
if (config_h_or_err) |*file| {
|
||||
file.close(io);
|
||||
return fs.path.join(
|
||||
return try fs.path.join(
|
||||
arena,
|
||||
&[_][]const u8{ check_dir, "config.h" },
|
||||
) catch unreachable;
|
||||
} else |e| switch (e) {
|
||||
);
|
||||
} else |err| switch (err) {
|
||||
error.FileNotFound => {},
|
||||
else => unreachable,
|
||||
else => |e| std.debug.panic("failed to check for config.h in {q}: {t}", .{ check_dir, e }),
|
||||
}
|
||||
|
||||
b.dependOnFileMetadata(b.graph.cwdRelativePath(check_dir).path(b, "config.h"));
|
||||
|
||||
// Check if we reached the source root by looking for .git, and bail if so
|
||||
var git_dir_or_err = dir.openDir(io, ".git", .{});
|
||||
if (git_dir_or_err) |*git_dir| {
|
||||
|
||||
Reference in new issue
Block a user