authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-06-23 23:32:29-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-06-29 23:50:19-07:00
logc8dad46ced6afcf08dfac2b8d4ae0c3a062983be
tree9fa770c345acba6ff1faea16f75a5603b94915bc
parent9add673f584a514b2e519f679fb0f6baf71daab7

Maker: add configure file system inputs to configuration cache

also wire up progress node to child

4 files changed, 37 insertions(+), 17 deletions(-)

lib/compiler/Maker.zig+7
......@@ -573,11 +573,17 @@ pub fn main(init: process.Init.Minimal) !void {
573573 .manifest_dir = try graph.local_cache_root.handle.createDirPathOpen(io, "h", .{}),
574574 .cwd = cwd_path,
575575 };
576
576577 graph.cache.addPrefix(.{ .path = null, .handle = cwd });
577578 graph.cache.addPrefix(zig_lib_directory);
578579 graph.cache.addPrefix(graph.local_cache_root);
579580 graph.cache.addPrefix(global_cache_directory);
580581 graph.cache.addPrefix(graph.build_root_directory);
582 comptime assert(0 == @intFromEnum(std.zig.Server.Message.PathPrefix.cwd));
583 comptime assert(1 == @intFromEnum(std.zig.Server.Message.PathPrefix.zig_lib));
584 comptime assert(2 == @intFromEnum(std.zig.Server.Message.PathPrefix.local_cache));
585 comptime assert(3 == @intFromEnum(std.zig.Server.Message.PathPrefix.global_cache));
586
581587 graph.cache.hash.addBytes(builtin.zig_version_string);
582588
583589 const NO_COLOR = EnvVar.NO_COLOR.isSet(&graph.environ_map);
......@@ -940,6 +946,7 @@ pub fn main(init: process.Init.Minimal) !void {
940946 .environ_map = &graph.environ_map,
941947 .cache_manifest = &config_man,
942948 .arch_os_abi = target_arch_os_abi,
949 .progress_node = compile_prog_node,
943950 })) |p| p else |err| switch (err) {
944951 error.AlreadyReported => process.exit(1),
945952 // If the file system inputs are populated, we can
lib/compiler/Maker/WebServer.zig+4
......@@ -622,12 +622,16 @@ fn buildClientWasm(ws: *WebServer, arena: Allocator, optimize: std.builtin.Optim
622622 "--listen=-",
623623 });
624624
625 const compile_prog_node = ws.root_prog_node.start("Compile WebAssembly Component", 0);
626 defer compile_prog_node.end();
627
625628 return std.zig.buildExeSubprocess(gpa, io, .{
626629 .argv = argv.items,
627630 .cache_root = graph.global_cache_root,
628631 .root_name = root_name,
629632 .arch_os_abi = arch_os_abi,
630633 .cpu_features = cpu_features,
634 .progress_node = compile_prog_node,
631635 });
632636}
633637
lib/std/Build/Cache.zig+2-2
......@@ -91,13 +91,13 @@ fn findPrefixResolved(cache: *const Cache, resolved_path: []u8) !PrefixedPath {
9191 };
9292 // Free the resolved path since we're not going to return it
9393 gpa.free(resolved_path);
94 return PrefixedPath{
94 return .{
9595 .prefix = i,
9696 .sub_path = sub_path,
9797 };
9898 }
9999
100 return PrefixedPath{
100 return .{
101101 .prefix = 0,
102102 .sub_path = resolved_path,
103103 };
lib/std/zig.zig+24-15
......@@ -1250,7 +1250,7 @@ pub const SubprocessCommand = struct {
12501250 for (child_env.keys(), child_env.values()) |key, value| {
12511251 if (sc.parent_env) |parent_env| {
12521252 if (parent_env.get(key)) |process_value| {
1253 if (std.mem.eql(u8, value, process_value)) continue;
1253 if (mem.eql(u8, value, process_value)) continue;
12541254 }
12551255 }
12561256 try w.print("{s}=", .{key});
......@@ -1364,10 +1364,10 @@ pub const Directories = struct {
13641364
13651365 const local_cache = getLocalCacheDirectory(arena, io, cwd, global_cache, local_cache_strat);
13661366
1367 if (std.mem.eql(u8, zig_lib.path orelse "", global_cache.path orelse "")) {
1367 if (mem.eql(u8, zig_lib.path orelse "", global_cache.path orelse "")) {
13681368 fatal("zig lib directory '{f}' cannot be equal to global cache directory '{f}'", .{ zig_lib, global_cache });
13691369 }
1370 if (std.mem.eql(u8, zig_lib.path orelse "", local_cache.path orelse "")) {
1370 if (mem.eql(u8, zig_lib.path orelse "", local_cache.path orelse "")) {
13711371 fatal("zig lib directory '{f}' cannot be equal to local cache directory '{f}'", .{ zig_lib, local_cache });
13721372 }
13731373
......@@ -1400,7 +1400,7 @@ pub const Directories = struct {
14001400
14011401 fn getPreopen(preopens: std.process.Preopens, name: []const u8) Cache.Directory {
14021402 return .{
1403 .path = if (std.mem.eql(u8, name, ".")) null else name,
1403 .path = if (mem.eql(u8, name, ".")) null else name,
14041404 .handle = switch (preopens.get(name) orelse fatal("preopen not found: {q}", .{name})) {
14051405 .file => fatal("preopen {q} is not a directory", .{name}),
14061406 .dir => |d| d,
......@@ -1607,7 +1607,7 @@ pub fn resolvePath(
16071607 assert(Dir.path.isAbsolute(path_resolved));
16081608 assert(Dir.path.isAbsolute(cwd_resolved));
16091609
1610 if (!std.mem.startsWith(u8, path_resolved, cwd_resolved)) return path_resolved; // not in cwd
1610 if (!mem.startsWith(u8, path_resolved, cwd_resolved)) return path_resolved; // not in cwd
16111611 if (path_resolved.len == cwd_resolved.len) {
16121612 // equal to cwd
16131613 gpa.free(path_resolved);
......@@ -1634,6 +1634,7 @@ pub const BuildExeSubprocessOptions = struct {
16341634 cache_manifest: ?*Cache.Manifest = null,
16351635 arch_os_abi: ?[]const u8 = null,
16361636 cpu_features: ?[]const u8 = null,
1637 progress_node: std.Progress.Node = .none,
16371638};
16381639
16391640pub const BuildExeSubprocessError = error{
......@@ -1655,6 +1656,7 @@ pub fn buildExeSubprocess(gpa: Allocator, io: Io, options: BuildExeSubprocessOpt
16551656 .stdin = .pipe,
16561657 .stdout = .pipe,
16571658 .stderr = .pipe,
1659 .progress_node = options.progress_node,
16581660 }) catch |err| {
16591661 log.err("spawning command {t}: {f}", .{ err, cmd });
16601662 return error.AlreadyReported;
......@@ -1722,7 +1724,7 @@ pub fn buildExeSubprocess(gpa: Allocator, io: Io, options: BuildExeSubprocessOpt
17221724
17231725 switch (header.tag) {
17241726 .zig_version => {
1725 if (!std.mem.eql(u8, builtin.zig_version_string, body)) {
1727 if (!mem.eql(u8, builtin.zig_version_string, body)) {
17261728 log.err("zig protocol version mismatch from command: {f}", .{cmd});
17271729 return error.AlreadyReported;
17281730 }
......@@ -1747,16 +1749,23 @@ pub fn buildExeSubprocess(gpa: Allocator, io: Io, options: BuildExeSubprocessOpt
17471749 .sub_path = try Dir.path.join(gpa, &.{ "o", &Cache.binToHex(digest.*) }),
17481750 };
17491751 },
1750 .file_system_inputs => {
1752 .file_system_inputs => if (options.cache_manifest) |man| {
17511753 received_fs_inputs = true;
1752 @panic("TODO");
1753 //var it = mem.splitScalar(u8, file_system_inputs.items, 0);
1754 //while (it.next()) |input| {
1755 // _ = try config_man.addPrefixedPathPost(.{
1756 // .prefix = input[0],
1757 // .sub_path = input[1..],
1758 // });
1759 //}
1754 var it = mem.splitScalar(u8, body, 0);
1755 while (it.next()) |prefixed_path| {
1756 const prefix: Server.Message.PathPrefix = @enumFromInt(prefixed_path[0] - 1);
1757 const sub_path = prefixed_path[1..];
1758 _ = man.addPrefixedPathPost(.{
1759 .prefix = @intFromEnum(prefix),
1760 .sub_path = sub_path,
1761 }) catch |err| switch (err) {
1762 error.Canceled, error.OutOfMemory => |e| return e,
1763 else => |e| {
1764 log.err("adding {t} {s} to cache failed: {t}", .{ prefix, sub_path, e });
1765 return error.AlreadyReported;
1766 },
1767 };
1768 }
17601769 },
17611770 else => {}, // ignore other messages
17621771 }