diff --git a/lib/compiler/Maker.zig b/lib/compiler/Maker.zig index 78da7c5d74111927f2947392d6fa161daf3b379c..74a7f4d4a37b6b244c27b1e876cfb83c2715bf6c 100644 --- a/lib/compiler/Maker.zig +++ b/lib/compiler/Maker.zig @@ -573,11 +573,17 @@ pub fn main(init: process.Init.Minimal) !void { .manifest_dir = try graph.local_cache_root.handle.createDirPathOpen(io, "h", .{}), .cwd = cwd_path, }; + graph.cache.addPrefix(.{ .path = null, .handle = cwd }); graph.cache.addPrefix(zig_lib_directory); graph.cache.addPrefix(graph.local_cache_root); graph.cache.addPrefix(global_cache_directory); graph.cache.addPrefix(graph.build_root_directory); + comptime assert(0 == @intFromEnum(std.zig.Server.Message.PathPrefix.cwd)); + comptime assert(1 == @intFromEnum(std.zig.Server.Message.PathPrefix.zig_lib)); + comptime assert(2 == @intFromEnum(std.zig.Server.Message.PathPrefix.local_cache)); + comptime assert(3 == @intFromEnum(std.zig.Server.Message.PathPrefix.global_cache)); + graph.cache.hash.addBytes(builtin.zig_version_string); const NO_COLOR = EnvVar.NO_COLOR.isSet(&graph.environ_map); @@ -940,6 +946,7 @@ pub fn main(init: process.Init.Minimal) !void { .environ_map = &graph.environ_map, .cache_manifest = &config_man, .arch_os_abi = target_arch_os_abi, + .progress_node = compile_prog_node, })) |p| p else |err| switch (err) { error.AlreadyReported => process.exit(1), // If the file system inputs are populated, we can diff --git a/lib/compiler/Maker/WebServer.zig b/lib/compiler/Maker/WebServer.zig index 1245b99b9cf9f75f27dd7c83b819dde9f7ab77ac..dddea1600beef0e0187162584349c5c0cd1df84d 100644 --- a/lib/compiler/Maker/WebServer.zig +++ b/lib/compiler/Maker/WebServer.zig @@ -622,12 +622,16 @@ fn buildClientWasm(ws: *WebServer, arena: Allocator, optimize: std.builtin.Optim "--listen=-", }); + const compile_prog_node = ws.root_prog_node.start("Compile WebAssembly Component", 0); + defer compile_prog_node.end(); + return std.zig.buildExeSubprocess(gpa, io, .{ .argv = argv.items, .cache_root = graph.global_cache_root, .root_name = root_name, .arch_os_abi = arch_os_abi, .cpu_features = cpu_features, + .progress_node = compile_prog_node, }); } diff --git a/lib/std/Build/Cache.zig b/lib/std/Build/Cache.zig index 724c1fc4322c7761583b6125c6d16146613790da..b3283856d9e64339cbaf153601aa80a0265bcefb 100644 --- a/lib/std/Build/Cache.zig +++ b/lib/std/Build/Cache.zig @@ -91,13 +91,13 @@ fn findPrefixResolved(cache: *const Cache, resolved_path: []u8) !PrefixedPath { }; // Free the resolved path since we're not going to return it gpa.free(resolved_path); - return PrefixedPath{ + return .{ .prefix = i, .sub_path = sub_path, }; } - return PrefixedPath{ + return .{ .prefix = 0, .sub_path = resolved_path, }; diff --git a/lib/std/zig.zig b/lib/std/zig.zig index 28bc16a02f91abc8f1a9626bfb8fdc6feb688cd4..6efe0cc7431e367f19add7b142db99641e6728b7 100644 --- a/lib/std/zig.zig +++ b/lib/std/zig.zig @@ -1250,7 +1250,7 @@ pub const SubprocessCommand = struct { for (child_env.keys(), child_env.values()) |key, value| { if (sc.parent_env) |parent_env| { if (parent_env.get(key)) |process_value| { - if (std.mem.eql(u8, value, process_value)) continue; + if (mem.eql(u8, value, process_value)) continue; } } try w.print("{s}=", .{key}); @@ -1364,10 +1364,10 @@ pub const Directories = struct { const local_cache = getLocalCacheDirectory(arena, io, cwd, global_cache, local_cache_strat); - if (std.mem.eql(u8, zig_lib.path orelse "", global_cache.path orelse "")) { + if (mem.eql(u8, zig_lib.path orelse "", global_cache.path orelse "")) { fatal("zig lib directory '{f}' cannot be equal to global cache directory '{f}'", .{ zig_lib, global_cache }); } - if (std.mem.eql(u8, zig_lib.path orelse "", local_cache.path orelse "")) { + if (mem.eql(u8, zig_lib.path orelse "", local_cache.path orelse "")) { fatal("zig lib directory '{f}' cannot be equal to local cache directory '{f}'", .{ zig_lib, local_cache }); } @@ -1400,7 +1400,7 @@ pub const Directories = struct { fn getPreopen(preopens: std.process.Preopens, name: []const u8) Cache.Directory { return .{ - .path = if (std.mem.eql(u8, name, ".")) null else name, + .path = if (mem.eql(u8, name, ".")) null else name, .handle = switch (preopens.get(name) orelse fatal("preopen not found: {q}", .{name})) { .file => fatal("preopen {q} is not a directory", .{name}), .dir => |d| d, @@ -1607,7 +1607,7 @@ pub fn resolvePath( assert(Dir.path.isAbsolute(path_resolved)); assert(Dir.path.isAbsolute(cwd_resolved)); - if (!std.mem.startsWith(u8, path_resolved, cwd_resolved)) return path_resolved; // not in cwd + if (!mem.startsWith(u8, path_resolved, cwd_resolved)) return path_resolved; // not in cwd if (path_resolved.len == cwd_resolved.len) { // equal to cwd gpa.free(path_resolved); @@ -1634,6 +1634,7 @@ pub const BuildExeSubprocessOptions = struct { cache_manifest: ?*Cache.Manifest = null, arch_os_abi: ?[]const u8 = null, cpu_features: ?[]const u8 = null, + progress_node: std.Progress.Node = .none, }; pub const BuildExeSubprocessError = error{ @@ -1655,6 +1656,7 @@ pub fn buildExeSubprocess(gpa: Allocator, io: Io, options: BuildExeSubprocessOpt .stdin = .pipe, .stdout = .pipe, .stderr = .pipe, + .progress_node = options.progress_node, }) catch |err| { log.err("spawning command {t}: {f}", .{ err, cmd }); return error.AlreadyReported; @@ -1722,7 +1724,7 @@ pub fn buildExeSubprocess(gpa: Allocator, io: Io, options: BuildExeSubprocessOpt switch (header.tag) { .zig_version => { - if (!std.mem.eql(u8, builtin.zig_version_string, body)) { + if (!mem.eql(u8, builtin.zig_version_string, body)) { log.err("zig protocol version mismatch from command: {f}", .{cmd}); return error.AlreadyReported; } @@ -1747,16 +1749,23 @@ pub fn buildExeSubprocess(gpa: Allocator, io: Io, options: BuildExeSubprocessOpt .sub_path = try Dir.path.join(gpa, &.{ "o", &Cache.binToHex(digest.*) }), }; }, - .file_system_inputs => { + .file_system_inputs => if (options.cache_manifest) |man| { received_fs_inputs = true; - @panic("TODO"); - //var it = mem.splitScalar(u8, file_system_inputs.items, 0); - //while (it.next()) |input| { - // _ = try config_man.addPrefixedPathPost(.{ - // .prefix = input[0], - // .sub_path = input[1..], - // }); - //} + var it = mem.splitScalar(u8, body, 0); + while (it.next()) |prefixed_path| { + const prefix: Server.Message.PathPrefix = @enumFromInt(prefixed_path[0] - 1); + const sub_path = prefixed_path[1..]; + _ = man.addPrefixedPathPost(.{ + .prefix = @intFromEnum(prefix), + .sub_path = sub_path, + }) catch |err| switch (err) { + error.Canceled, error.OutOfMemory => |e| return e, + else => |e| { + log.err("adding {t} {s} to cache failed: {t}", .{ prefix, sub_path, e }); + return error.AlreadyReported; + }, + }; + } }, else => {}, // ignore other messages }