| author | |
| committer | |
| log | 0e078790feaf49964d7a0da3042117ebd10de13b |
| tree | dba66f98f82654a645a1540aea8df7d4f1ed4ca2 |
| parent | 81376e72057026464e1c17330666d4fb3c5a7ce0 |
21 files changed, 131 insertions(+), 31 deletions(-)
lib/build_runner.zig+1-1| ... | ... | @@ -571,7 +571,7 @@ fn workerMakeOneStep( |
| 571 | 571 | // For example, CompileStep does some sus things with modifying the saved |
| 572 | 572 | // *Build object in install header steps that might be able to be removed |
| 573 | 573 | // by passing the *Build object through the make() functions. |
| 574 | const make_result = s.make(); | |
| 574 | const make_result = s.make(&sub_prog_node); | |
| 575 | 575 | |
| 576 | 576 | // No matter the result, we want to display error/warning messages. |
| 577 | 577 | if (s.result_error_msgs.items.len > 0) { |
lib/std/Build.zig+13-3| ... | ... | @@ -718,7 +718,8 @@ pub fn getUninstallStep(self: *Build) *Step { |
| 718 | 718 | return &self.uninstall_tls.step; |
| 719 | 719 | } |
| 720 | 720 | |
| 721 | fn makeUninstall(uninstall_step: *Step) anyerror!void { | |
| 721 | fn makeUninstall(uninstall_step: *Step, prog_node: *std.Progress.Node) anyerror!void { | |
| 722 | _ = prog_node; | |
| 722 | 723 | const uninstall_tls = @fieldParentPtr(TopLevelStep, "step", uninstall_step); |
| 723 | 724 | const self = @fieldParentPtr(Build, "uninstall_tls", uninstall_tls); |
| 724 | 725 | |
| ... | ... | @@ -1404,7 +1405,7 @@ pub fn execAllowFail( |
| 1404 | 1405 | |
| 1405 | 1406 | /// This function is used exclusively for spawning and communicating with the zig compiler. |
| 1406 | 1407 | /// TODO: move to build_runner.zig |
| 1407 | pub fn execFromStep(b: *Build, argv: []const []const u8, s: *Step) ![]const u8 { | |
| 1408 | pub fn execFromStep(b: *Build, argv: []const []const u8, s: *Step, prog_node: *std.Progress.Node) ![]const u8 { | |
| 1408 | 1409 | assert(argv.len != 0); |
| 1409 | 1410 | |
| 1410 | 1411 | if (b.verbose) { |
| ... | ... | @@ -1439,6 +1440,11 @@ pub fn execFromStep(b: *Build, argv: []const []const u8, s: *Step) ![]const u8 { |
| 1439 | 1440 | const Header = std.zig.Server.Message.Header; |
| 1440 | 1441 | var result: ?[]const u8 = null; |
| 1441 | 1442 | |
| 1443 | var node_name: std.ArrayListUnmanaged(u8) = .{}; | |
| 1444 | defer node_name.deinit(b.allocator); | |
| 1445 | var sub_prog_node: ?std.Progress.Node = null; | |
| 1446 | defer if (sub_prog_node) |*n| n.end(); | |
| 1447 | ||
| 1442 | 1448 | while (try poller.poll()) { |
| 1443 | 1449 | const stdout = poller.fifo(.stdout); |
| 1444 | 1450 | const buf = stdout.readableSlice(0); |
| ... | ... | @@ -1478,7 +1484,11 @@ pub fn execFromStep(b: *Build, argv: []const []const u8, s: *Step) ![]const u8 { |
| 1478 | 1484 | }; |
| 1479 | 1485 | }, |
| 1480 | 1486 | .progress => { |
| 1481 | @panic("TODO handle progress message"); | |
| 1487 | if (sub_prog_node) |*n| n.end(); | |
| 1488 | node_name.clearRetainingCapacity(); | |
| 1489 | try node_name.appendSlice(b.allocator, body); | |
| 1490 | sub_prog_node = prog_node.start(node_name.items, 0); | |
| 1491 | sub_prog_node.?.activate(); | |
| 1482 | 1492 | }, |
| 1483 | 1493 | .emit_bin_path => { |
| 1484 | 1494 | result = try b.allocator.dupe(u8, body); |
lib/std/Build/CheckFileStep.zig+2-1| ... | ... | @@ -33,7 +33,8 @@ pub fn create( |
| 33 | 33 | return self; |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | fn make(step: *Step) !void { | |
| 36 | fn make(step: *Step, prog_node: *std.Progress.Node) !void { | |
| 37 | _ = prog_node; | |
| 37 | 38 | const self = @fieldParentPtr(CheckFileStep, "step", step); |
| 38 | 39 | |
| 39 | 40 | const src_path = self.source.getPath(self.builder); |
lib/std/Build/CheckObjectStep.zig+2-1| ... | ... | @@ -300,7 +300,8 @@ pub fn checkComputeCompare( |
| 300 | 300 | self.checks.append(new_check) catch @panic("OOM"); |
| 301 | 301 | } |
| 302 | 302 | |
| 303 | fn make(step: *Step) !void { | |
| 303 | fn make(step: *Step, prog_node: *std.Progress.Node) !void { | |
| 304 | _ = prog_node; | |
| 304 | 305 | const self = @fieldParentPtr(CheckObjectStep, "step", step); |
| 305 | 306 | |
| 306 | 307 | const gpa = self.builder.allocator; |
lib/std/Build/CompileStep.zig+3-3| ... | ... | @@ -1160,7 +1160,7 @@ fn constructDepString( |
| 1160 | 1160 | } |
| 1161 | 1161 | } |
| 1162 | 1162 | |
| 1163 | fn make(step: *Step) !void { | |
| 1163 | fn make(step: *Step, prog_node: *std.Progress.Node) !void { | |
| 1164 | 1164 | const self = @fieldParentPtr(CompileStep, "step", step); |
| 1165 | 1165 | const builder = self.builder; |
| 1166 | 1166 | |
| ... | ... | @@ -1718,7 +1718,7 @@ fn make(step: *Step) !void { |
| 1718 | 1718 | } |
| 1719 | 1719 | if (other.installed_headers.items.len > 0) { |
| 1720 | 1720 | for (other.installed_headers.items) |install_step| { |
| 1721 | try install_step.make(); | |
| 1721 | try install_step.make(prog_node); | |
| 1722 | 1722 | } |
| 1723 | 1723 | try zig_args.append("-I"); |
| 1724 | 1724 | try zig_args.append(builder.pathJoin(&.{ |
| ... | ... | @@ -1894,7 +1894,7 @@ fn make(step: *Step) !void { |
| 1894 | 1894 | try zig_args.append(resolved_args_file); |
| 1895 | 1895 | } |
| 1896 | 1896 | |
| 1897 | const output_bin_path = try builder.execFromStep(zig_args.items, &self.step); | |
| 1897 | const output_bin_path = try builder.execFromStep(zig_args.items, &self.step, prog_node); | |
| 1898 | 1898 | const build_output_dir = fs.path.dirname(output_bin_path).?; |
| 1899 | 1899 | |
| 1900 | 1900 | if (self.output_dir) |output_dir| { |
lib/std/Build/ConfigHeaderStep.zig+2-1| ... | ... | @@ -152,7 +152,8 @@ fn putValue(self: *ConfigHeaderStep, field_name: []const u8, comptime T: type, v |
| 152 | 152 | } |
| 153 | 153 | } |
| 154 | 154 | |
| 155 | fn make(step: *Step) !void { | |
| 155 | fn make(step: *Step, prog_node: *std.Progress.Node) !void { | |
| 156 | _ = prog_node; | |
| 156 | 157 | const self = @fieldParentPtr(ConfigHeaderStep, "step", step); |
| 157 | 158 | const gpa = self.builder.allocator; |
| 158 | 159 |
lib/std/Build/EmulatableRunStep.zig+2-1| ... | ... | @@ -71,7 +71,8 @@ pub fn create(builder: *std.Build, name: []const u8, artifact: *CompileStep) *Em |
| 71 | 71 | return self; |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | fn make(step: *Step) !void { | |
| 74 | fn make(step: *Step, prog_node: *std.Progress.Node) !void { | |
| 75 | _ = prog_node; | |
| 75 | 76 | const self = @fieldParentPtr(EmulatableRunStep, "step", step); |
| 76 | 77 | const host_info = self.builder.host; |
| 77 | 78 |
lib/std/Build/FmtStep.zig+2-1| ... | ... | @@ -29,7 +29,8 @@ pub fn create(builder: *std.Build, paths: []const []const u8) *FmtStep { |
| 29 | 29 | return self; |
| 30 | 30 | } |
| 31 | 31 | |
| 32 | fn make(step: *Step) !void { | |
| 32 | fn make(step: *Step, prog_node: *std.Progress.Node) !void { | |
| 33 | _ = prog_node; | |
| 33 | 34 | const self = @fieldParentPtr(FmtStep, "step", step); |
| 34 | 35 | |
| 35 | 36 | return self.builder.spawnChild(self.argv); |
lib/std/Build/InstallArtifactStep.zig+2-1| ... | ... | @@ -64,7 +64,8 @@ pub fn create(builder: *std.Build, artifact: *CompileStep) *InstallArtifactStep |
| 64 | 64 | return self; |
| 65 | 65 | } |
| 66 | 66 | |
| 67 | fn make(step: *Step) !void { | |
| 67 | fn make(step: *Step, prog_node: *std.Progress.Node) !void { | |
| 68 | _ = prog_node; | |
| 68 | 69 | const self = @fieldParentPtr(InstallArtifactStep, "step", step); |
| 69 | 70 | const builder = self.builder; |
| 70 | 71 |
lib/std/Build/InstallDirStep.zig+2-1| ... | ... | @@ -56,7 +56,8 @@ pub fn init( |
| 56 | 56 | }; |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | fn make(step: *Step) !void { | |
| 59 | fn make(step: *Step, prog_node: *std.Progress.Node) !void { | |
| 60 | _ = prog_node; | |
| 60 | 61 | const self = @fieldParentPtr(InstallDirStep, "step", step); |
| 61 | 62 | const dest_prefix = self.builder.getInstallPath(self.options.install_dir, self.options.install_subdir); |
| 62 | 63 | const src_builder = self.override_source_builder orelse self.builder; |
lib/std/Build/InstallFileStep.zig+2-1| ... | ... | @@ -35,7 +35,8 @@ pub fn init( |
| 35 | 35 | }; |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | fn make(step: *Step) !void { | |
| 38 | fn make(step: *Step, prog_node: *std.Progress.Node) !void { | |
| 39 | _ = prog_node; | |
| 39 | 40 | const self = @fieldParentPtr(InstallFileStep, "step", step); |
| 40 | 41 | const src_builder = self.override_source_builder orelse self.builder; |
| 41 | 42 | const full_src_path = self.source.getPath2(src_builder, step); |
lib/std/Build/LogStep.zig+2-1| ... | ... | @@ -21,7 +21,8 @@ pub fn init(builder: *std.Build, data: []const u8) LogStep { |
| 21 | 21 | }; |
| 22 | 22 | } |
| 23 | 23 | |
| 24 | fn make(step: *Step) anyerror!void { | |
| 24 | fn make(step: *Step, prog_node: *std.Progress.Node) anyerror!void { | |
| 25 | _ = prog_node; | |
| 25 | 26 | const self = @fieldParentPtr(LogStep, "step", step); |
| 26 | 27 | log.info("{s}", .{self.data}); |
| 27 | 28 | } |
lib/std/Build/ObjCopyStep.zig+2-1| ... | ... | @@ -66,7 +66,8 @@ pub fn getOutputSource(self: *const ObjCopyStep) std.Build.FileSource { |
| 66 | 66 | return .{ .generated = &self.output_file }; |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | fn make(step: *Step) !void { | |
| 69 | fn make(step: *Step, prog_node: *std.Progress.Node) !void { | |
| 70 | _ = prog_node; | |
| 70 | 71 | const self = @fieldParentPtr(ObjCopyStep, "step", step); |
| 71 | 72 | const b = self.builder; |
| 72 | 73 |
lib/std/Build/OptionsStep.zig+2-1| ... | ... | @@ -219,7 +219,8 @@ pub fn getSource(self: *OptionsStep) FileSource { |
| 219 | 219 | return .{ .generated = &self.generated_file }; |
| 220 | 220 | } |
| 221 | 221 | |
| 222 | fn make(step: *Step) !void { | |
| 222 | fn make(step: *Step, prog_node: *std.Progress.Node) !void { | |
| 223 | _ = prog_node; | |
| 223 | 224 | const self = @fieldParentPtr(OptionsStep, "step", step); |
| 224 | 225 | |
| 225 | 226 | for (self.artifact_args.items) |item| { |
lib/std/Build/RemoveDirStep.zig+2-1| ... | ... | @@ -22,7 +22,8 @@ pub fn init(builder: *std.Build, dir_path: []const u8) RemoveDirStep { |
| 22 | 22 | }; |
| 23 | 23 | } |
| 24 | 24 | |
| 25 | fn make(step: *Step) !void { | |
| 25 | fn make(step: *Step, prog_node: *std.Progress.Node) !void { | |
| 26 | _ = prog_node; | |
| 26 | 27 | const self = @fieldParentPtr(RemoveDirStep, "step", step); |
| 27 | 28 | |
| 28 | 29 | const full_path = self.builder.pathFromRoot(self.dir_path); |
lib/std/Build/RunStep.zig+2-1| ... | ... | @@ -206,7 +206,8 @@ fn needOutputCheck(self: RunStep) bool { |
| 206 | 206 | return false; |
| 207 | 207 | } |
| 208 | 208 | |
| 209 | fn make(step: *Step) !void { | |
| 209 | fn make(step: *Step, prog_node: *std.Progress.Node) !void { | |
| 210 | _ = prog_node; | |
| 210 | 211 | const self = @fieldParentPtr(RunStep, "step", step); |
| 211 | 212 | const need_output_check = self.needOutputCheck(); |
| 212 | 213 |
lib/std/Build/Step.zig+8-5| ... | ... | @@ -1,6 +1,6 @@ |
| 1 | 1 | id: Id, |
| 2 | 2 | name: []const u8, |
| 3 | makeFn: *const fn (self: *Step) anyerror!void, | |
| 3 | makeFn: MakeFn, | |
| 4 | 4 | dependencies: std.ArrayList(*Step), |
| 5 | 5 | /// This field is empty during execution of the user's build script, and |
| 6 | 6 | /// then populated during dependency loop checking in the build runner. |
| ... | ... | @@ -13,6 +13,8 @@ debug_stack_trace: [n_debug_stack_frames]usize, |
| 13 | 13 | result_error_msgs: std.ArrayListUnmanaged([]const u8), |
| 14 | 14 | result_error_bundle: std.zig.ErrorBundle, |
| 15 | 15 | |
| 16 | pub const MakeFn = *const fn (self: *Step, prog_node: *std.Progress.Node) anyerror!void; | |
| 17 | ||
| 16 | 18 | const n_debug_stack_frames = 4; |
| 17 | 19 | |
| 18 | 20 | pub const State = enum { |
| ... | ... | @@ -72,7 +74,7 @@ pub const Id = enum { |
| 72 | 74 | pub const Options = struct { |
| 73 | 75 | id: Id, |
| 74 | 76 | name: []const u8, |
| 75 | makeFn: *const fn (self: *Step) anyerror!void = makeNoOp, | |
| 77 | makeFn: MakeFn = makeNoOp, | |
| 76 | 78 | first_ret_addr: ?usize = null, |
| 77 | 79 | }; |
| 78 | 80 | |
| ... | ... | @@ -101,8 +103,8 @@ pub fn init(allocator: Allocator, options: Options) Step { |
| 101 | 103 | /// If the Step's `make` function reports `error.MakeFailed`, it indicates they |
| 102 | 104 | /// have already reported the error. Otherwise, we add a simple error report |
| 103 | 105 | /// here. |
| 104 | pub fn make(s: *Step) error{MakeFailed}!void { | |
| 105 | return s.makeFn(s) catch |err| { | |
| 106 | pub fn make(s: *Step, prog_node: *std.Progress.Node) error{MakeFailed}!void { | |
| 107 | return s.makeFn(s, prog_node) catch |err| { | |
| 106 | 108 | if (err != error.MakeFailed) { |
| 107 | 109 | const gpa = s.dependencies.allocator; |
| 108 | 110 | s.result_error_msgs.append(gpa, std.fmt.allocPrint(gpa, "{s} failed: {s}", .{ |
| ... | ... | @@ -129,8 +131,9 @@ pub fn getStackTrace(s: *Step) std.builtin.StackTrace { |
| 129 | 131 | }; |
| 130 | 132 | } |
| 131 | 133 | |
| 132 | fn makeNoOp(self: *Step) anyerror!void { | |
| 134 | fn makeNoOp(self: *Step, prog_node: *std.Progress.Node) anyerror!void { | |
| 133 | 135 | _ = self; |
| 136 | _ = prog_node; | |
| 134 | 137 | } |
| 135 | 138 | |
| 136 | 139 | pub fn cast(step: *Step, comptime T: type) ?*T { |
lib/std/Build/TranslateCStep.zig+2-2| ... | ... | @@ -88,7 +88,7 @@ pub fn defineCMacroRaw(self: *TranslateCStep, name_and_value: []const u8) void { |
| 88 | 88 | self.c_macros.append(self.builder.dupe(name_and_value)) catch @panic("OOM"); |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | fn make(step: *Step) !void { | |
| 91 | fn make(step: *Step, prog_node: *std.Progress.Node) !void { | |
| 92 | 92 | const self = @fieldParentPtr(TranslateCStep, "step", step); |
| 93 | 93 | |
| 94 | 94 | var argv_list = std.ArrayList([]const u8).init(self.builder.allocator); |
| ... | ... | @@ -120,7 +120,7 @@ fn make(step: *Step) !void { |
| 120 | 120 | |
| 121 | 121 | try argv_list.append(self.source.getPath(self.builder)); |
| 122 | 122 | |
| 123 | const output_path_nl = try self.builder.execFromStep(argv_list.items, &self.step); | |
| 123 | const output_path_nl = try self.builder.execFromStep(argv_list.items, &self.step, prog_node); | |
| 124 | 124 | const output_path = mem.trimRight(u8, output_path_nl, "\r\n"); |
| 125 | 125 | |
| 126 | 126 | self.out_basename = fs.path.basename(output_path); |
lib/std/Build/WriteFileStep.zig+2-1| ... | ... | @@ -99,7 +99,8 @@ pub fn getFileSource(wf: *WriteFileStep, sub_path: []const u8) ?std.Build.FileSo |
| 99 | 99 | return null; |
| 100 | 100 | } |
| 101 | 101 | |
| 102 | fn make(step: *Step) !void { | |
| 102 | fn make(step: *Step, prog_node: *std.Progress.Node) !void { | |
| 103 | _ = prog_node; | |
| 103 | 104 | const wf = @fieldParentPtr(WriteFileStep, "step", step); |
| 104 | 105 | |
| 105 | 106 | // Writing to source files is kind of an extra capability of this |
src/main.zig+72-1| ... | ... | @@ -3573,7 +3573,21 @@ fn serve( |
| 3573 | 3573 | if (comp.bin_file.options.output_mode == .Exe) { |
| 3574 | 3574 | try comp.makeBinFileWritable(); |
| 3575 | 3575 | } |
| 3576 | try comp.update(main_progress_node); | |
| 3576 | ||
| 3577 | { | |
| 3578 | var reset: std.Thread.ResetEvent = .{}; | |
| 3579 | ||
| 3580 | var progress_thread = try std.Thread.spawn(.{}, progressThread, .{ | |
| 3581 | &progress, out, &reset, | |
| 3582 | }); | |
| 3583 | defer { | |
| 3584 | reset.set(); | |
| 3585 | progress_thread.join(); | |
| 3586 | } | |
| 3587 | ||
| 3588 | try comp.update(main_progress_node); | |
| 3589 | } | |
| 3590 | ||
| 3577 | 3591 | try comp.makeBinFileExecutable(); |
| 3578 | 3592 | try serveUpdateResults(out, comp); |
| 3579 | 3593 | }, |
| ... | ... | @@ -3629,6 +3643,63 @@ fn serve( |
| 3629 | 3643 | } |
| 3630 | 3644 | } |
| 3631 | 3645 | |
| 3646 | fn progressThread(progress: *std.Progress, out: fs.File, reset: *std.Thread.ResetEvent) void { | |
| 3647 | while (true) { | |
| 3648 | if (reset.timedWait(500 * std.time.ns_per_ms)) |_| { | |
| 3649 | // The Compilation update has completed. | |
| 3650 | return; | |
| 3651 | } else |err| switch (err) { | |
| 3652 | error.Timeout => {}, | |
| 3653 | } | |
| 3654 | ||
| 3655 | var buf: std.BoundedArray(u8, 160) = .{}; | |
| 3656 | ||
| 3657 | { | |
| 3658 | progress.update_mutex.lock(); | |
| 3659 | defer progress.update_mutex.unlock(); | |
| 3660 | ||
| 3661 | var need_ellipse = false; | |
| 3662 | var maybe_node: ?*std.Progress.Node = &progress.root; | |
| 3663 | while (maybe_node) |node| { | |
| 3664 | if (need_ellipse) { | |
| 3665 | buf.appendSlice("... ") catch {}; | |
| 3666 | } | |
| 3667 | need_ellipse = false; | |
| 3668 | const eti = @atomicLoad(usize, &node.unprotected_estimated_total_items, .Monotonic); | |
| 3669 | const completed_items = @atomicLoad(usize, &node.unprotected_completed_items, .Monotonic); | |
| 3670 | const current_item = completed_items + 1; | |
| 3671 | if (node.name.len != 0 or eti > 0) { | |
| 3672 | if (node.name.len != 0) { | |
| 3673 | buf.appendSlice(node.name) catch {}; | |
| 3674 | need_ellipse = true; | |
| 3675 | } | |
| 3676 | if (eti > 0) { | |
| 3677 | if (need_ellipse) buf.appendSlice(" ") catch {}; | |
| 3678 | buf.writer().print("[{d}/{d}] ", .{ current_item, eti }) catch {}; | |
| 3679 | need_ellipse = false; | |
| 3680 | } else if (completed_items != 0) { | |
| 3681 | if (need_ellipse) buf.appendSlice(" ") catch {}; | |
| 3682 | buf.writer().print("[{d}] ", .{current_item}) catch {}; | |
| 3683 | need_ellipse = false; | |
| 3684 | } | |
| 3685 | } | |
| 3686 | maybe_node = @atomicLoad(?*std.Progress.Node, &node.recently_updated_child, .Acquire); | |
| 3687 | } | |
| 3688 | } | |
| 3689 | ||
| 3690 | const progress_string = buf.slice(); | |
| 3691 | ||
| 3692 | serveMessage(out, .{ | |
| 3693 | .tag = .progress, | |
| 3694 | .bytes_len = @intCast(u32, progress_string.len), | |
| 3695 | }, &.{ | |
| 3696 | progress_string, | |
| 3697 | }) catch |err| { | |
| 3698 | fatal("unable to write to client: {s}", .{@errorName(err)}); | |
| 3699 | }; | |
| 3700 | } | |
| 3701 | } | |
| 3702 | ||
| 3632 | 3703 | fn serveMessage( |
| 3633 | 3704 | out: fs.File, |
| 3634 | 3705 | header: std.zig.Server.Message.Header, |
test/tests.zig+4-2| ... | ... | @@ -875,7 +875,8 @@ pub const StackTracesContext = struct { |
| 875 | 875 | return ptr; |
| 876 | 876 | } |
| 877 | 877 | |
| 878 | fn make(step: *Step) !void { | |
| 878 | fn make(step: *Step, prog_node: *std.Progress.Node) !void { | |
| 879 | _ = prog_node; | |
| 879 | 880 | const self = @fieldParentPtr(RunAndCompareStep, "step", step); |
| 880 | 881 | const b = self.context.b; |
| 881 | 882 | |
| ... | ... | @@ -1218,7 +1219,8 @@ pub const GenHContext = struct { |
| 1218 | 1219 | return ptr; |
| 1219 | 1220 | } |
| 1220 | 1221 | |
| 1221 | fn make(step: *Step) !void { | |
| 1222 | fn make(step: *Step, prog_node: *std.Progress.Node) !void { | |
| 1223 | _ = prog_node; | |
| 1222 | 1224 | const self = @fieldParentPtr(GenHCmpOutputStep, "step", step); |
| 1223 | 1225 | const b = self.context.b; |
| 1224 | 1226 |