authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-07-02 11:18:12-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-07-02 11:18:12-07:00
log1323ad58f0a5ebe24e5dd25c47c7cec4093e3ab6
tree0d2891f80ea873381be3bd28e686a69eac0928a6
parent14678451848a6683904c24f75333699b4d166a46

sync


2 files changed, 52 insertions(+), 41 deletions(-)

lib/compiler/build_runner.zig+50-38
......@@ -379,12 +379,18 @@ pub fn main() !void {
379379
380380 validateSystemLibraryOptions(builder);
381381
382 {
383 var fw = std.fs.File.stdout().writer();
384 var bw = fw.interface().buffered(&stdio_buffer);
385 defer bw.flush() catch {};
386 if (help_menu) return usage(builder, &bw);
387 if (steps_menu) return steps(builder, &bw);
382 if (help_menu) {
383 var w = initStdoutWriter();
384 printUsage(builder, w) catch return stdout_writer_allocation.err.?;
385 w.flush() catch return stdout_writer_allocation.err.?;
386 return;
387 }
388
389 if (steps_menu) {
390 var w = initStdoutWriter();
391 printSteps(builder, w) catch return stdout_writer_allocation.err.?;
392 w.flush() catch return stdout_writer_allocation.err.?;
393 return;
388394 }
389395
390396 var run: Run = .{
......@@ -697,21 +703,21 @@ fn runStepNames(
697703 const ttyconf = run.ttyconf;
698704
699705 if (run.summary != .none) {
700 const bw = std.debug.lockStderrWriter(&stdio_buffer);
706 const w = std.debug.lockStderrWriter(&stdio_buffer_allocation);
701707 defer std.debug.unlockStderrWriter();
702708
703709 const total_count = success_count + failure_count + pending_count + skipped_count;
704 ttyconf.setColor(bw, .cyan) catch {};
705 bw.writeAll("Build Summary:") catch {};
706 ttyconf.setColor(bw, .reset) catch {};
707 bw.print(" {d}/{d} steps succeeded", .{ success_count, total_count }) catch {};
708 if (skipped_count > 0) bw.print("; {d} skipped", .{skipped_count}) catch {};
709 if (failure_count > 0) bw.print("; {d} failed", .{failure_count}) catch {};
710
711 if (test_count > 0) bw.print("; {d}/{d} tests passed", .{ test_pass_count, test_count }) catch {};
712 if (test_skip_count > 0) bw.print("; {d} skipped", .{test_skip_count}) catch {};
713 if (test_fail_count > 0) bw.print("; {d} failed", .{test_fail_count}) catch {};
714 if (test_leak_count > 0) bw.print("; {d} leaked", .{test_leak_count}) catch {};
710 ttyconf.setColor(w, .cyan) catch {};
711 w.writeAll("Build Summary:") catch {};
712 ttyconf.setColor(w, .reset) catch {};
713 w.print(" {d}/{d} steps succeeded", .{ success_count, total_count }) catch {};
714 if (skipped_count > 0) w.print("; {d} skipped", .{skipped_count}) catch {};
715 if (failure_count > 0) w.print("; {d} failed", .{failure_count}) catch {};
716
717 if (test_count > 0) w.print("; {d}/{d} tests passed", .{ test_pass_count, test_count }) catch {};
718 if (test_skip_count > 0) w.print("; {d} skipped", .{test_skip_count}) catch {};
719 if (test_fail_count > 0) w.print("; {d} failed", .{test_fail_count}) catch {};
720 if (test_leak_count > 0) w.print("; {d} leaked", .{test_leak_count}) catch {};
715721
716722 // Print a fancy tree with build results.
717723 var step_stack_copy = try step_stack.clone(gpa);
......@@ -720,7 +726,7 @@ fn runStepNames(
720726 var print_node: PrintNode = .{ .parent = null };
721727 if (step_names.len == 0) {
722728 print_node.last = true;
723 printTreeStep(b, b.default_step, run, bw, ttyconf, &print_node, &step_stack_copy) catch {};
729 printTreeStep(b, b.default_step, run, w, ttyconf, &print_node, &step_stack_copy) catch {};
724730 } else {
725731 const last_index = if (run.summary == .all) b.top_level_steps.count() else blk: {
726732 var i: usize = step_names.len;
......@@ -739,10 +745,10 @@ fn runStepNames(
739745 for (step_names, 0..) |step_name, i| {
740746 const tls = b.top_level_steps.get(step_name).?;
741747 print_node.last = i + 1 == last_index;
742 printTreeStep(b, &tls.step, run, bw, ttyconf, &print_node, &step_stack_copy) catch {};
748 printTreeStep(b, &tls.step, run, w, ttyconf, &print_node, &step_stack_copy) catch {};
743749 }
744750 }
745 bw.writeByte('\n') catch {};
751 w.writeByte('\n') catch {};
746752 }
747753
748754 if (failure_count == 0) {
......@@ -1128,7 +1134,7 @@ fn workerMakeOneStep(
11281134 const show_stderr = s.result_stderr.len > 0;
11291135
11301136 if (show_error_msgs or show_compile_errors or show_stderr) {
1131 const bw = std.debug.lockStderrWriter(&stdio_buffer);
1137 const bw = std.debug.lockStderrWriter(&stdio_buffer_allocation);
11321138 defer std.debug.unlockStderrWriter();
11331139
11341140 const gpa = b.allocator;
......@@ -1242,29 +1248,27 @@ pub fn printErrorMessages(
12421248 }
12431249}
12441250
1245fn steps(builder: *std.Build, bw: *Writer) !void {
1251fn printSteps(builder: *std.Build, w: *Writer) !void {
12461252 const allocator = builder.allocator;
12471253 for (builder.top_level_steps.values()) |top_level_step| {
12481254 const name = if (&top_level_step.step == builder.default_step)
12491255 try fmt.allocPrint(allocator, "{s} (default)", .{top_level_step.step.name})
12501256 else
12511257 top_level_step.step.name;
1252 try bw.print(" {s:<28} {s}\n", .{ name, top_level_step.description });
1258 try w.print(" {s:<28} {s}\n", .{ name, top_level_step.description });
12531259 }
12541260}
12551261
1256var stdio_buffer: [256]u8 = undefined;
1257
1258fn usage(b: *std.Build, bw: *Writer) !void {
1259 try bw.print(
1262fn printUsage(b: *std.Build, w: *Writer) !void {
1263 try w.print(
12601264 \\Usage: {s} build [steps] [options]
12611265 \\
12621266 \\Steps:
12631267 \\
12641268 , .{b.graph.zig_exe});
1265 try steps(b, bw);
1269 try printSteps(b, w);
12661270
1267 try bw.writeAll(
1271 try w.writeAll(
12681272 \\
12691273 \\General Options:
12701274 \\ -p, --prefix [path] Where to install files (default: zig-out)
......@@ -1320,25 +1324,25 @@ fn usage(b: *std.Build, bw: *Writer) !void {
13201324
13211325 const arena = b.allocator;
13221326 if (b.available_options_list.items.len == 0) {
1323 try bw.print(" (none)\n", .{});
1327 try w.print(" (none)\n", .{});
13241328 } else {
13251329 for (b.available_options_list.items) |option| {
13261330 const name = try fmt.allocPrint(arena, " -D{s}=[{s}]", .{
13271331 option.name,
13281332 @tagName(option.type_id),
13291333 });
1330 try bw.print("{s:<30} {s}\n", .{ name, option.description });
1334 try w.print("{s:<30} {s}\n", .{ name, option.description });
13311335 if (option.enum_options) |enum_options| {
13321336 const padding = " " ** 33;
1333 try bw.writeAll(padding ++ "Supported Values:\n");
1337 try w.writeAll(padding ++ "Supported Values:\n");
13341338 for (enum_options) |enum_option| {
1335 try bw.print(padding ++ " {s}\n", .{enum_option});
1339 try w.print(padding ++ " {s}\n", .{enum_option});
13361340 }
13371341 }
13381342 }
13391343 }
13401344
1341 try bw.writeAll(
1345 try w.writeAll(
13421346 \\
13431347 \\System Integration Options:
13441348 \\ --search-prefix [path] Add a path to look for binaries, libraries, headers
......@@ -1353,7 +1357,7 @@ fn usage(b: *std.Build, bw: *Writer) !void {
13531357 \\
13541358 );
13551359 if (b.graph.system_library_options.entries.len == 0) {
1356 try bw.writeAll(" (none) -\n");
1360 try w.writeAll(" (none) -\n");
13571361 } else {
13581362 for (b.graph.system_library_options.keys(), b.graph.system_library_options.values()) |k, v| {
13591363 const status = switch (v) {
......@@ -1361,11 +1365,11 @@ fn usage(b: *std.Build, bw: *Writer) !void {
13611365 .declared_disabled => "no",
13621366 .user_enabled, .user_disabled => unreachable, // already emitted error
13631367 };
1364 try bw.print(" {s:<43} {s}\n", .{ k, status });
1368 try w.print(" {s:<43} {s}\n", .{ k, status });
13651369 }
13661370 }
13671371
1368 try bw.writeAll(
1372 try w.writeAll(
13691373 \\
13701374 \\Advanced Options:
13711375 \\ -freference-trace[=num] How many lines of reference trace should be shown per compile error
......@@ -1545,3 +1549,11 @@ fn createModuleDependenciesForStep(step: *Step) Allocator.Error!void {
15451549 };
15461550 }
15471551}
1552
1553var stdio_buffer_allocation: [256]u8 = undefined;
1554var stdout_writer_allocation: std.fs.File.Writer = undefined;
1555
1556fn initStdoutWriter() *Writer {
1557 stdout_writer_allocation = std.fs.File.stdout().writerStreaming(&stdio_buffer_allocation);
1558 return &stdout_writer_allocation.interface;
1559}
lib/std/Build/Step/Compile.zig+2-3
......@@ -1744,8 +1744,7 @@ fn getZigArgs(compile: *Compile, fuzz: bool) ![][]const u8 {
17441744 }
17451745
17461746 if (compile.error_limit) |err_limit| try zig_args.appendSlice(&.{
1747 "--error-limit",
1748 b.fmt("{}", .{err_limit}),
1747 "--error-limit", b.fmt("{d}", .{err_limit}),
17491748 });
17501749
17511750 try addFlag(&zig_args, "incremental", b.graph.incremental);
......@@ -1975,7 +1974,7 @@ fn checkCompileErrors(compile: *Compile) !void {
19751974 .ttyconf = .no_color,
19761975 .include_reference_trace = false,
19771976 .include_source_line = false,
1978 }, &aw.interface);
1977 }, &aw.writer);
19791978 break :ae try aw.toOwnedSlice();
19801979 };
19811980