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 {...@@ -379,12 +379,18 @@ pub fn main() !void {
379379
380 validateSystemLibraryOptions(builder);380 validateSystemLibraryOptions(builder);
381381
382 {382 if (help_menu) {
383 var fw = std.fs.File.stdout().writer();383 var w = initStdoutWriter();
384 var bw = fw.interface().buffered(&stdio_buffer);384 printUsage(builder, w) catch return stdout_writer_allocation.err.?;
385 defer bw.flush() catch {};385 w.flush() catch return stdout_writer_allocation.err.?;
386 if (help_menu) return usage(builder, &bw);386 return;
387 if (steps_menu) return steps(builder, &bw);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;
388 }394 }
389395
390 var run: Run = .{396 var run: Run = .{
...@@ -697,21 +703,21 @@ fn runStepNames(...@@ -697,21 +703,21 @@ fn runStepNames(
697 const ttyconf = run.ttyconf;703 const ttyconf = run.ttyconf;
698704
699 if (run.summary != .none) {705 if (run.summary != .none) {
700 const bw = std.debug.lockStderrWriter(&stdio_buffer);706 const w = std.debug.lockStderrWriter(&stdio_buffer_allocation);
701 defer std.debug.unlockStderrWriter();707 defer std.debug.unlockStderrWriter();
702708
703 const total_count = success_count + failure_count + pending_count + skipped_count;709 const total_count = success_count + failure_count + pending_count + skipped_count;
704 ttyconf.setColor(bw, .cyan) catch {};710 ttyconf.setColor(w, .cyan) catch {};
705 bw.writeAll("Build Summary:") catch {};711 w.writeAll("Build Summary:") catch {};
706 ttyconf.setColor(bw, .reset) catch {};712 ttyconf.setColor(w, .reset) catch {};
707 bw.print(" {d}/{d} steps succeeded", .{ success_count, total_count }) catch {};713 w.print(" {d}/{d} steps succeeded", .{ success_count, total_count }) catch {};
708 if (skipped_count > 0) bw.print("; {d} skipped", .{skipped_count}) catch {};714 if (skipped_count > 0) w.print("; {d} skipped", .{skipped_count}) catch {};
709 if (failure_count > 0) bw.print("; {d} failed", .{failure_count}) catch {};715 if (failure_count > 0) w.print("; {d} failed", .{failure_count}) catch {};
710716
711 if (test_count > 0) bw.print("; {d}/{d} tests passed", .{ test_pass_count, test_count }) catch {};717 if (test_count > 0) w.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 {};718 if (test_skip_count > 0) w.print("; {d} skipped", .{test_skip_count}) catch {};
713 if (test_fail_count > 0) bw.print("; {d} failed", .{test_fail_count}) catch {};719 if (test_fail_count > 0) w.print("; {d} failed", .{test_fail_count}) catch {};
714 if (test_leak_count > 0) bw.print("; {d} leaked", .{test_leak_count}) catch {};720 if (test_leak_count > 0) w.print("; {d} leaked", .{test_leak_count}) catch {};
715721
716 // Print a fancy tree with build results.722 // Print a fancy tree with build results.
717 var step_stack_copy = try step_stack.clone(gpa);723 var step_stack_copy = try step_stack.clone(gpa);
...@@ -720,7 +726,7 @@ fn runStepNames(...@@ -720,7 +726,7 @@ fn runStepNames(
720 var print_node: PrintNode = .{ .parent = null };726 var print_node: PrintNode = .{ .parent = null };
721 if (step_names.len == 0) {727 if (step_names.len == 0) {
722 print_node.last = true;728 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 {};
724 } else {730 } else {
725 const last_index = if (run.summary == .all) b.top_level_steps.count() else blk: {731 const last_index = if (run.summary == .all) b.top_level_steps.count() else blk: {
726 var i: usize = step_names.len;732 var i: usize = step_names.len;
...@@ -739,10 +745,10 @@ fn runStepNames(...@@ -739,10 +745,10 @@ fn runStepNames(
739 for (step_names, 0..) |step_name, i| {745 for (step_names, 0..) |step_name, i| {
740 const tls = b.top_level_steps.get(step_name).?;746 const tls = b.top_level_steps.get(step_name).?;
741 print_node.last = i + 1 == last_index;747 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 {};
743 }749 }
744 }750 }
745 bw.writeByte('\n') catch {};751 w.writeByte('\n') catch {};
746 }752 }
747753
748 if (failure_count == 0) {754 if (failure_count == 0) {
...@@ -1128,7 +1134,7 @@ fn workerMakeOneStep(...@@ -1128,7 +1134,7 @@ fn workerMakeOneStep(
1128 const show_stderr = s.result_stderr.len > 0;1134 const show_stderr = s.result_stderr.len > 0;
11291135
1130 if (show_error_msgs or show_compile_errors or show_stderr) {1136 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);
1132 defer std.debug.unlockStderrWriter();1138 defer std.debug.unlockStderrWriter();
11331139
1134 const gpa = b.allocator;1140 const gpa = b.allocator;
...@@ -1242,29 +1248,27 @@ pub fn printErrorMessages(...@@ -1242,29 +1248,27 @@ pub fn printErrorMessages(
1242 }1248 }
1243}1249}
12441250
1245fn steps(builder: *std.Build, bw: *Writer) !void {1251fn printSteps(builder: *std.Build, w: *Writer) !void {
1246 const allocator = builder.allocator;1252 const allocator = builder.allocator;
1247 for (builder.top_level_steps.values()) |top_level_step| {1253 for (builder.top_level_steps.values()) |top_level_step| {
1248 const name = if (&top_level_step.step == builder.default_step)1254 const name = if (&top_level_step.step == builder.default_step)
1249 try fmt.allocPrint(allocator, "{s} (default)", .{top_level_step.step.name})1255 try fmt.allocPrint(allocator, "{s} (default)", .{top_level_step.step.name})
1250 else1256 else
1251 top_level_step.step.name;1257 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 });
1253 }1259 }
1254}1260}
12551261
1256var stdio_buffer: [256]u8 = undefined;1262fn printUsage(b: *std.Build, w: *Writer) !void {
12571263 try w.print(
1258fn usage(b: *std.Build, bw: *Writer) !void {
1259 try bw.print(
1260 \\Usage: {s} build [steps] [options]1264 \\Usage: {s} build [steps] [options]
1261 \\1265 \\
1262 \\Steps:1266 \\Steps:
1263 \\1267 \\
1264 , .{b.graph.zig_exe});1268 , .{b.graph.zig_exe});
1265 try steps(b, bw);1269 try printSteps(b, w);
12661270
1267 try bw.writeAll(1271 try w.writeAll(
1268 \\1272 \\
1269 \\General Options:1273 \\General Options:
1270 \\ -p, --prefix [path] Where to install files (default: zig-out)1274 \\ -p, --prefix [path] Where to install files (default: zig-out)
...@@ -1320,25 +1324,25 @@ fn usage(b: *std.Build, bw: *Writer) !void {...@@ -1320,25 +1324,25 @@ fn usage(b: *std.Build, bw: *Writer) !void {
13201324
1321 const arena = b.allocator;1325 const arena = b.allocator;
1322 if (b.available_options_list.items.len == 0) {1326 if (b.available_options_list.items.len == 0) {
1323 try bw.print(" (none)\n", .{});1327 try w.print(" (none)\n", .{});
1324 } else {1328 } else {
1325 for (b.available_options_list.items) |option| {1329 for (b.available_options_list.items) |option| {
1326 const name = try fmt.allocPrint(arena, " -D{s}=[{s}]", .{1330 const name = try fmt.allocPrint(arena, " -D{s}=[{s}]", .{
1327 option.name,1331 option.name,
1328 @tagName(option.type_id),1332 @tagName(option.type_id),
1329 });1333 });
1330 try bw.print("{s:<30} {s}\n", .{ name, option.description });1334 try w.print("{s:<30} {s}\n", .{ name, option.description });
1331 if (option.enum_options) |enum_options| {1335 if (option.enum_options) |enum_options| {
1332 const padding = " " ** 33;1336 const padding = " " ** 33;
1333 try bw.writeAll(padding ++ "Supported Values:\n");1337 try w.writeAll(padding ++ "Supported Values:\n");
1334 for (enum_options) |enum_option| {1338 for (enum_options) |enum_option| {
1335 try bw.print(padding ++ " {s}\n", .{enum_option});1339 try w.print(padding ++ " {s}\n", .{enum_option});
1336 }1340 }
1337 }1341 }
1338 }1342 }
1339 }1343 }
13401344
1341 try bw.writeAll(1345 try w.writeAll(
1342 \\1346 \\
1343 \\System Integration Options:1347 \\System Integration Options:
1344 \\ --search-prefix [path] Add a path to look for binaries, libraries, headers1348 \\ --search-prefix [path] Add a path to look for binaries, libraries, headers
...@@ -1353,7 +1357,7 @@ fn usage(b: *std.Build, bw: *Writer) !void {...@@ -1353,7 +1357,7 @@ fn usage(b: *std.Build, bw: *Writer) !void {
1353 \\1357 \\
1354 );1358 );
1355 if (b.graph.system_library_options.entries.len == 0) {1359 if (b.graph.system_library_options.entries.len == 0) {
1356 try bw.writeAll(" (none) -\n");1360 try w.writeAll(" (none) -\n");
1357 } else {1361 } else {
1358 for (b.graph.system_library_options.keys(), b.graph.system_library_options.values()) |k, v| {1362 for (b.graph.system_library_options.keys(), b.graph.system_library_options.values()) |k, v| {
1359 const status = switch (v) {1363 const status = switch (v) {
...@@ -1361,11 +1365,11 @@ fn usage(b: *std.Build, bw: *Writer) !void {...@@ -1361,11 +1365,11 @@ fn usage(b: *std.Build, bw: *Writer) !void {
1361 .declared_disabled => "no",1365 .declared_disabled => "no",
1362 .user_enabled, .user_disabled => unreachable, // already emitted error1366 .user_enabled, .user_disabled => unreachable, // already emitted error
1363 };1367 };
1364 try bw.print(" {s:<43} {s}\n", .{ k, status });1368 try w.print(" {s:<43} {s}\n", .{ k, status });
1365 }1369 }
1366 }1370 }
13671371
1368 try bw.writeAll(1372 try w.writeAll(
1369 \\1373 \\
1370 \\Advanced Options:1374 \\Advanced Options:
1371 \\ -freference-trace[=num] How many lines of reference trace should be shown per compile error1375 \\ -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 {...@@ -1545,3 +1549,11 @@ fn createModuleDependenciesForStep(step: *Step) Allocator.Error!void {
1545 };1549 };
1546 }1550 }
1547}1551}
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 {...@@ -1744,8 +1744,7 @@ fn getZigArgs(compile: *Compile, fuzz: bool) ![][]const u8 {
1744 }1744 }
17451745
1746 if (compile.error_limit) |err_limit| try zig_args.appendSlice(&.{1746 if (compile.error_limit) |err_limit| try zig_args.appendSlice(&.{
1747 "--error-limit",1747 "--error-limit", b.fmt("{d}", .{err_limit}),
1748 b.fmt("{}", .{err_limit}),
1749 });1748 });
17501749
1751 try addFlag(&zig_args, "incremental", b.graph.incremental);1750 try addFlag(&zig_args, "incremental", b.graph.incremental);
...@@ -1975,7 +1974,7 @@ fn checkCompileErrors(compile: *Compile) !void {...@@ -1975,7 +1974,7 @@ fn checkCompileErrors(compile: *Compile) !void {
1975 .ttyconf = .no_color,1974 .ttyconf = .no_color,
1976 .include_reference_trace = false,1975 .include_reference_trace = false,
1977 .include_source_line = false,1976 .include_source_line = false,
1978 }, &aw.interface);1977 }, &aw.writer);
1979 break :ae try aw.toOwnedSlice();1978 break :ae try aw.toOwnedSlice();
1980 };1979 };
19811980