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