| author | |
| committer | |
| log | 2996eb558756c697e2ccfe9691356e536c88916b |
| tree | 769ca1781323bcc5dcc612d6032934764958d786 |
| parent | 80d1976db9efd21920a45890cbf368d808b166e5 |
5 files changed, 58 insertions(+), 11 deletions(-)
lib/std/Build/ObjCopyStep.zig+1-1| ... | ... | @@ -113,7 +113,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 113 | 113 | }; |
| 114 | 114 | |
| 115 | 115 | try argv.appendSlice(&.{ full_src_path, full_dest_path }); |
| 116 | _ = try step.spawnZigProcess(argv.items, prog_node); | |
| 116 | _ = try step.evalZigProcess(argv.items, prog_node); | |
| 117 | 117 | |
| 118 | 118 | self.output_file.path = full_dest_path; |
| 119 | 119 | try man.writeManifest(); |
lib/std/Build/Step.zig+9-1| ... | ... | @@ -234,10 +234,12 @@ pub fn evalZigProcess( |
| 234 | 234 | child.stdin_behavior = .Pipe; |
| 235 | 235 | child.stdout_behavior = .Pipe; |
| 236 | 236 | child.stderr_behavior = .Pipe; |
| 237 | child.request_resource_usage_statistics = true; | |
| 237 | 238 | |
| 238 | 239 | child.spawn() catch |err| return s.fail("unable to spawn {s}: {s}", .{ |
| 239 | 240 | argv[0], @errorName(err), |
| 240 | 241 | }); |
| 242 | var timer = try std.time.Timer.start(); | |
| 241 | 243 | |
| 242 | 244 | var poller = std.io.poll(gpa, enum { stdout, stderr }, .{ |
| 243 | 245 | .stdout = child.stdout.?, |
| ... | ... | @@ -301,7 +303,10 @@ pub fn evalZigProcess( |
| 301 | 303 | sub_prog_node.?.activate(); |
| 302 | 304 | }, |
| 303 | 305 | .emit_bin_path => { |
| 304 | result = try arena.dupe(u8, body); | |
| 306 | const EbpHdr = std.zig.Server.Message.EmitBinPath; | |
| 307 | const ebp_hdr = @ptrCast(*align(1) const EbpHdr, body); | |
| 308 | s.result_cached = ebp_hdr.flags.cache_hit; | |
| 309 | result = try arena.dupe(u8, body[@sizeOf(EbpHdr)..]); | |
| 305 | 310 | }, |
| 306 | 311 | _ => { |
| 307 | 312 | // Unrecognized message. |
| ... | ... | @@ -323,6 +328,9 @@ pub fn evalZigProcess( |
| 323 | 328 | const term = child.wait() catch |err| { |
| 324 | 329 | return s.fail("unable to wait for {s}: {s}", .{ argv[0], @errorName(err) }); |
| 325 | 330 | }; |
| 331 | s.result_duration_ns = timer.read(); | |
| 332 | s.result_peak_rss = child.resource_usage_statistics.getMaxRss() orelse 0; | |
| 333 | ||
| 326 | 334 | try handleChildProcessTerm(s, term, null, argv); |
| 327 | 335 | |
| 328 | 336 | if (s.result_error_bundle.errorMessageCount() > 0) { |
lib/std/zig/Server.zig+12-1| ... | ... | @@ -12,7 +12,7 @@ pub const Message = struct { |
| 12 | 12 | error_bundle, |
| 13 | 13 | /// Body is a UTF-8 string. |
| 14 | 14 | progress, |
| 15 | /// Body is a UTF-8 string. | |
| 15 | /// Body is a EmitBinPath. | |
| 16 | 16 | emit_bin_path, |
| 17 | 17 | _, |
| 18 | 18 | }; |
| ... | ... | @@ -25,4 +25,15 @@ pub const Message = struct { |
| 25 | 25 | extra_len: u32, |
| 26 | 26 | string_bytes_len: u32, |
| 27 | 27 | }; |
| 28 | ||
| 29 | /// Trailing: | |
| 30 | /// * the file system path the emitted binary can be found | |
| 31 | pub const EmitBinPath = extern struct { | |
| 32 | flags: Flags, | |
| 33 | ||
| 34 | pub const Flags = packed struct(u8) { | |
| 35 | cache_hit: bool, | |
| 36 | reserved: u7 = 0, | |
| 37 | }; | |
| 38 | }; | |
| 28 | 39 | }; |
src/Compilation.zig+3| ... | ... | @@ -100,6 +100,7 @@ job_queued_compiler_rt_lib: bool = false, |
| 100 | 100 | job_queued_compiler_rt_obj: bool = false, |
| 101 | 101 | alloc_failure_occurred: bool = false, |
| 102 | 102 | formatted_panics: bool = false, |
| 103 | last_update_was_cache_hit: bool = false, | |
| 103 | 104 | |
| 104 | 105 | c_source_files: []const CSourceFile, |
| 105 | 106 | clang_argv: []const []const u8, |
| ... | ... | @@ -1860,6 +1861,7 @@ pub fn update(comp: *Compilation, main_progress_node: *std.Progress.Node) !void |
| 1860 | 1861 | defer tracy_trace.end(); |
| 1861 | 1862 | |
| 1862 | 1863 | comp.clearMiscFailures(); |
| 1864 | comp.last_update_was_cache_hit = false; | |
| 1863 | 1865 | |
| 1864 | 1866 | var man: Cache.Manifest = undefined; |
| 1865 | 1867 | defer if (comp.whole_cache_manifest != null) man.deinit(); |
| ... | ... | @@ -1887,6 +1889,7 @@ pub fn update(comp: *Compilation, main_progress_node: *std.Progress.Node) !void |
| 1887 | 1889 | return err; |
| 1888 | 1890 | }; |
| 1889 | 1891 | if (is_hit) { |
| 1892 | comp.last_update_was_cache_hit = true; | |
| 1890 | 1893 | log.debug("CacheMode.whole cache hit for {s}", .{comp.bin_file.options.root_name}); |
| 1891 | 1894 | const digest = man.final(); |
| 1892 | 1895 |
src/main.zig+33-8| ... | ... | @@ -3578,9 +3578,11 @@ fn serve( |
| 3578 | 3578 | var arena_instance = std.heap.ArenaAllocator.init(gpa); |
| 3579 | 3579 | defer arena_instance.deinit(); |
| 3580 | 3580 | const arena = arena_instance.allocator(); |
| 3581 | var output_path: []const u8 = undefined; | |
| 3582 | try cmdTranslateC(comp, arena, &output_path); | |
| 3583 | try serveStringMessage(out, .emit_bin_path, output_path); | |
| 3581 | var output: TranslateCOutput = undefined; | |
| 3582 | try cmdTranslateC(comp, arena, &output); | |
| 3583 | try serveEmitBinPath(out, output.path, .{ | |
| 3584 | .flags = .{ .cache_hit = output.cache_hit }, | |
| 3585 | }); | |
| 3584 | 3586 | continue; |
| 3585 | 3587 | } |
| 3586 | 3588 | |
| ... | ... | @@ -3760,10 +3762,26 @@ fn serveUpdateResults(out: fs.File, comp: *Compilation) !void { |
| 3760 | 3762 | } else if (comp.bin_file.options.emit) |emit| { |
| 3761 | 3763 | const full_path = try emit.directory.join(gpa, &.{emit.sub_path}); |
| 3762 | 3764 | defer gpa.free(full_path); |
| 3763 | try serveStringMessage(out, .emit_bin_path, full_path); | |
| 3765 | try serveEmitBinPath(out, full_path, .{ | |
| 3766 | .flags = .{ .cache_hit = comp.last_update_was_cache_hit }, | |
| 3767 | }); | |
| 3764 | 3768 | } |
| 3765 | 3769 | } |
| 3766 | 3770 | |
| 3771 | fn serveEmitBinPath( | |
| 3772 | out: fs.File, | |
| 3773 | fs_path: []const u8, | |
| 3774 | header: std.zig.Server.Message.EmitBinPath, | |
| 3775 | ) !void { | |
| 3776 | try serveMessage(out, .{ | |
| 3777 | .tag = .emit_bin_path, | |
| 3778 | .bytes_len = @intCast(u32, fs_path.len + @sizeOf(std.zig.Server.Message.EmitBinPath)), | |
| 3779 | }, &.{ | |
| 3780 | std.mem.asBytes(&header), | |
| 3781 | fs_path, | |
| 3782 | }); | |
| 3783 | } | |
| 3784 | ||
| 3767 | 3785 | fn serveStringMessage(out: fs.File, tag: std.zig.Server.Message.Tag, s: []const u8) !void { |
| 3768 | 3786 | try serveMessage(out, .{ |
| 3769 | 3787 | .tag = tag, |
| ... | ... | @@ -4115,7 +4133,12 @@ fn updateModule(gpa: Allocator, comp: *Compilation, hook: AfterUpdateHook) !void |
| 4115 | 4133 | } |
| 4116 | 4134 | } |
| 4117 | 4135 | |
| 4118 | fn cmdTranslateC(comp: *Compilation, arena: Allocator, output_path: ?*[]const u8) !void { | |
| 4136 | const TranslateCOutput = struct { | |
| 4137 | path: []const u8, | |
| 4138 | cache_hit: bool, | |
| 4139 | }; | |
| 4140 | ||
| 4141 | fn cmdTranslateC(comp: *Compilation, arena: Allocator, fancy_output: ?*TranslateCOutput) !void { | |
| 4119 | 4142 | if (!build_options.have_llvm) |
| 4120 | 4143 | fatal("cannot translate-c: compiler built without LLVM extensions", .{}); |
| 4121 | 4144 | |
| ... | ... | @@ -4126,14 +4149,16 @@ fn cmdTranslateC(comp: *Compilation, arena: Allocator, output_path: ?*[]const u8 |
| 4126 | 4149 | |
| 4127 | 4150 | var man: Cache.Manifest = comp.obtainCObjectCacheManifest(); |
| 4128 | 4151 | man.want_shared_lock = false; |
| 4129 | defer if (output_path != null) man.deinit(); | |
| 4152 | defer man.deinit(); | |
| 4130 | 4153 | |
| 4131 | 4154 | man.hash.add(@as(u16, 0xb945)); // Random number to distinguish translate-c from compiling C objects |
| 4132 | 4155 | Compilation.cache_helpers.hashCSource(&man, c_source_file) catch |err| { |
| 4133 | 4156 | fatal("unable to process '{s}': {s}", .{ c_source_file.src_path, @errorName(err) }); |
| 4134 | 4157 | }; |
| 4135 | 4158 | |
| 4159 | if (fancy_output) |p| p.cache_hit = true; | |
| 4136 | 4160 | const digest = if (try man.hit()) man.final() else digest: { |
| 4161 | if (fancy_output) |p| p.cache_hit = false; | |
| 4137 | 4162 | var argv = std.ArrayList([]const u8).init(arena); |
| 4138 | 4163 | try argv.append(""); // argv[0] is program name, actual args start at [1] |
| 4139 | 4164 | |
| ... | ... | @@ -4229,11 +4254,11 @@ fn cmdTranslateC(comp: *Compilation, arena: Allocator, output_path: ?*[]const u8 |
| 4229 | 4254 | break :digest digest; |
| 4230 | 4255 | }; |
| 4231 | 4256 | |
| 4232 | if (output_path) |out_path| { | |
| 4257 | if (fancy_output) |p| { | |
| 4233 | 4258 | const full_zig_path = try comp.local_cache_directory.join(arena, &[_][]const u8{ |
| 4234 | 4259 | "o", &digest, translated_zig_basename, |
| 4235 | 4260 | }); |
| 4236 | out_path.* = full_zig_path; | |
| 4261 | p.path = full_zig_path; | |
| 4237 | 4262 | } else { |
| 4238 | 4263 | const out_zig_path = try fs.path.join(arena, &[_][]const u8{ "o", &digest, translated_zig_basename }); |
| 4239 | 4264 | const zig_file = comp.local_cache_directory.handle.openFile(out_zig_path, .{}) catch |err| { |