diff --git a/lib/compiler/Maker.zig b/lib/compiler/Maker.zig index 32d065ede20a52a4d2d3ba89f89c2dfe7402e91d..71e8c7c9faa5be0ea2efed337d40f41f93030b24 100644 --- a/lib/compiler/Maker.zig +++ b/lib/compiler/Maker.zig @@ -965,7 +965,7 @@ pub fn main(init: process.Init.Minimal) !void { .cache_manifest = &config_man, .arch_os_abi = target_arch_os_abi, .progress_node = compile_prog_node, - })) |p| p else |err| switch (err) { + })) |r| r.path else |err| switch (err) { error.AlreadyReported => process.exit(1), // If the file system inputs are populated, we can // still watch for changes and try again. diff --git a/lib/compiler/Maker/WebServer.zig b/lib/compiler/Maker/WebServer.zig index dddea1600beef0e0187162584349c5c0cd1df84d..7a8c5013611c196ede9c3e6390e2fa9989c41eab 100644 --- a/lib/compiler/Maker/WebServer.zig +++ b/lib/compiler/Maker/WebServer.zig @@ -625,7 +625,7 @@ fn buildClientWasm(ws: *WebServer, arena: Allocator, optimize: std.builtin.Optim const compile_prog_node = ws.root_prog_node.start("Compile WebAssembly Component", 0); defer compile_prog_node.end(); - return std.zig.buildExeSubprocess(gpa, io, .{ + const result = try std.zig.buildExeSubprocess(gpa, io, .{ .argv = argv.items, .cache_root = graph.global_cache_root, .root_name = root_name, @@ -633,6 +633,8 @@ fn buildClientWasm(ws: *WebServer, arena: Allocator, optimize: std.builtin.Optim .cpu_features = cpu_features, .progress_node = compile_prog_node, }); + if (!result.cache_hit) log.info("source changes detected; rebuilt wasm component", .{}); + return result.path; } pub fn updateTimeReportCompile(ws: *WebServer, opts: struct { diff --git a/lib/std/zig.zig b/lib/std/zig.zig index 657b05638e03147e5d54d51b3768b97004333276..c875663d67e028ecccfc6e5cac6a9647fc4d7d26 100644 --- a/lib/std/zig.zig +++ b/lib/std/zig.zig @@ -1644,10 +1644,20 @@ pub const BuildExeSubprocessError = error{ FailedButCacheIntact, } || Io.Cancelable || Allocator.Error; +pub const BuildExeSubprocessResult = struct { + received_fs_inputs: bool, + cache_hit: bool, + path: Cache.Path, +}; + /// Assumes `argv` has `--listen=-` in it and the child process is `zig build-exe`. /// /// Result path is allocated via gpa. -pub fn buildExeSubprocess(gpa: Allocator, io: Io, options: BuildExeSubprocessOptions) BuildExeSubprocessError!Cache.Path { +pub fn buildExeSubprocess( + gpa: Allocator, + io: Io, + options: BuildExeSubprocessOptions, +) BuildExeSubprocessError!BuildExeSubprocessResult { const cmd: SubprocessCommand = .{ .argv = options.argv }; var child = std.process.spawn(io, .{ @@ -1699,6 +1709,7 @@ pub fn buildExeSubprocess(gpa: Allocator, io: Io, options: BuildExeSubprocessOpt defer body_buffer.deinit(gpa); var received_fs_inputs = false; + var cache_hit = false; while (true) { const header = stdout.takeStruct(Header, .little) catch |err| switch (err) { @@ -1739,9 +1750,7 @@ pub fn buildExeSubprocess(gpa: Allocator, io: Io, options: BuildExeSubprocessOpt .emit_digest => { const EmitDigest = Server.Message.EmitDigest; const ebp_hdr: *align(1) const EmitDigest = @ptrCast(body); - if (!ebp_hdr.flags.cache_hit) { - log.info("source changes detected; rebuilt {s}", .{options.root_name}); - } + cache_hit = ebp_hdr.flags.cache_hit; const digest = body[@sizeOf(EmitDigest)..][0..Cache.bin_digest_len]; if (result) |r| gpa.free(r.sub_path); result = .{ @@ -1831,7 +1840,11 @@ pub fn buildExeSubprocess(gpa: Allocator, io: Io, options: BuildExeSubprocessOpt .output_mode = .Exe, }); defer gpa.free(bin_name); - return base_path.join(gpa, bin_name); + return .{ + .received_fs_inputs = received_fs_inputs, + .cache_hit = cache_hit, + .path = try base_path.join(gpa, bin_name), + }; } fn readStreamAlloc(gpa: Allocator, io: Io, file: Io.File, limit: Io.Limit) ![]u8 {