aboutsummaryrefslogtreecommitdiff
path: root/lib/std/Build
diff options
context:
space:
mode:
authorMatthew Lugg <mlugg@mlugg.co.uk>2025-10-30 15:24:47 +0000
committerGitHub <noreply@github.com>2025-10-30 15:24:47 +0000
commit4174ab9c2c98d798452dd745d5d5dc657d601591 (patch)
tree3c7b27d5e3ebc31e94c2865e017707717ed30c8b /lib/std/Build
parent74c23a237ef5245b63eb06b832a511aabeb715c0 (diff)
parent32779a7c7392d823c945ae0a13a65cf94a4044b8 (diff)
downloadzig-4174ab9c2c98d798452dd745d5d5dc657d601591.tar.gz
zig-4174ab9c2c98d798452dd745d5d5dc657d601591.zip
Merge pull request #25726 from mlugg/std-log-colors
Cache stderr ttyconf, colorize `std.log`, and fix `--webui`
Diffstat (limited to 'lib/std/Build')
-rw-r--r--lib/std/Build/Fuzz.zig18
-rw-r--r--lib/std/Build/Step/Compile.zig11
-rw-r--r--lib/std/Build/Step/Run.zig14
-rw-r--r--lib/std/Build/WebServer.zig9
4 files changed, 27 insertions, 25 deletions
diff --git a/lib/std/Build/Fuzz.zig b/lib/std/Build/Fuzz.zig
index d342628871..6dd4f70f9f 100644
--- a/lib/std/Build/Fuzz.zig
+++ b/lib/std/Build/Fuzz.zig
@@ -16,6 +16,7 @@ const build_runner = @import("root");
gpa: Allocator,
io: Io,
+ttyconf: tty.Config,
mode: Mode,
/// Allocated into `gpa`.
@@ -25,7 +26,6 @@ wait_group: std.Thread.WaitGroup,
root_prog_node: std.Progress.Node,
prog_node: std.Progress.Node,
thread_pool: *std.Thread.Pool,
-ttyconf: tty.Config,
/// Protects `coverage_files`.
coverage_mutex: std.Thread.Mutex,
@@ -79,9 +79,9 @@ pub fn init(
gpa: Allocator,
io: Io,
thread_pool: *std.Thread.Pool,
+ ttyconf: tty.Config,
all_steps: []const *Build.Step,
root_prog_node: std.Progress.Node,
- ttyconf: tty.Config,
mode: Mode,
) Allocator.Error!Fuzz {
const run_steps: []const *Step.Run = steps: {
@@ -115,11 +115,11 @@ pub fn init(
return .{
.gpa = gpa,
.io = io,
+ .ttyconf = ttyconf,
.mode = mode,
.run_steps = run_steps,
.wait_group = .{},
.thread_pool = thread_pool,
- .ttyconf = ttyconf,
.root_prog_node = root_prog_node,
.prog_node = .none,
.coverage_files = .empty,
@@ -158,7 +158,7 @@ pub fn deinit(fuzz: *Fuzz) void {
fuzz.gpa.free(fuzz.run_steps);
}
-fn rebuildTestsWorkerRun(run: *Step.Run, gpa: Allocator, ttyconf: std.Io.tty.Config, parent_prog_node: std.Progress.Node) void {
+fn rebuildTestsWorkerRun(run: *Step.Run, gpa: Allocator, ttyconf: tty.Config, parent_prog_node: std.Progress.Node) void {
rebuildTestsWorkerRunFallible(run, gpa, ttyconf, parent_prog_node) catch |err| {
const compile = run.producer.?;
log.err("step '{s}': failed to rebuild in fuzz mode: {s}", .{
@@ -167,7 +167,7 @@ fn rebuildTestsWorkerRun(run: *Step.Run, gpa: Allocator, ttyconf: std.Io.tty.Con
};
}
-fn rebuildTestsWorkerRunFallible(run: *Step.Run, gpa: Allocator, ttyconf: std.Io.tty.Config, parent_prog_node: std.Progress.Node) !void {
+fn rebuildTestsWorkerRunFallible(run: *Step.Run, gpa: Allocator, ttyconf: tty.Config, parent_prog_node: std.Progress.Node) !void {
const compile = run.producer.?;
const prog_node = parent_prog_node.start(compile.step.name, 0);
defer prog_node.end();
@@ -180,9 +180,9 @@ fn rebuildTestsWorkerRunFallible(run: *Step.Run, gpa: Allocator, ttyconf: std.Io
if (show_error_msgs or show_compile_errors or show_stderr) {
var buf: [256]u8 = undefined;
- const w = std.debug.lockStderrWriter(&buf);
+ const w, _ = std.debug.lockStderrWriter(&buf);
defer std.debug.unlockStderrWriter();
- build_runner.printErrorMessages(gpa, &compile.step, .{ .ttyconf = ttyconf }, w, .verbose, .indent) catch {};
+ build_runner.printErrorMessages(gpa, &compile.step, .{}, w, ttyconf, .verbose, .indent) catch {};
}
const rebuilt_bin_path = result catch |err| switch (err) {
@@ -206,9 +206,9 @@ fn fuzzWorkerRun(
run.rerunInFuzzMode(fuzz, unit_test_index, prog_node) catch |err| switch (err) {
error.MakeFailed => {
var buf: [256]u8 = undefined;
- const w = std.debug.lockStderrWriter(&buf);
+ const w, _ = std.debug.lockStderrWriter(&buf);
defer std.debug.unlockStderrWriter();
- build_runner.printErrorMessages(gpa, &run.step, .{ .ttyconf = fuzz.ttyconf }, w, .verbose, .indent) catch {};
+ build_runner.printErrorMessages(gpa, &run.step, .{}, w, fuzz.ttyconf, .verbose, .indent) catch {};
return;
},
else => {
diff --git a/lib/std/Build/Step/Compile.zig b/lib/std/Build/Step/Compile.zig
index 2188d8bfc7..a5f2d696be 100644
--- a/lib/std/Build/Step/Compile.zig
+++ b/lib/std/Build/Step/Compile.zig
@@ -1056,15 +1056,15 @@ fn getGeneratedFilePath(compile: *Compile, comptime tag_name: []const u8, asking
const maybe_path: ?*GeneratedFile = @field(compile, tag_name);
const generated_file = maybe_path orelse {
- const w = std.debug.lockStderrWriter(&.{});
- std.Build.dumpBadGetPathHelp(&compile.step, w, .detect(.stderr()), compile.step.owner, asking_step) catch {};
+ const w, const ttyconf = std.debug.lockStderrWriter(&.{});
+ std.Build.dumpBadGetPathHelp(&compile.step, w, ttyconf, compile.step.owner, asking_step) catch {};
std.debug.unlockStderrWriter();
@panic("missing emit option for " ++ tag_name);
};
const path = generated_file.path orelse {
- const w = std.debug.lockStderrWriter(&.{});
- std.Build.dumpBadGetPathHelp(&compile.step, w, .detect(.stderr()), compile.step.owner, asking_step) catch {};
+ const w, const ttyconf = std.debug.lockStderrWriter(&.{});
+ std.Build.dumpBadGetPathHelp(&compile.step, w, ttyconf, compile.step.owner, asking_step) catch {};
std.debug.unlockStderrWriter();
@panic(tag_name ++ " is null. Is there a missing step dependency?");
};
@@ -2027,10 +2027,9 @@ fn checkCompileErrors(compile: *Compile) !void {
var aw: std.Io.Writer.Allocating = .init(arena);
defer aw.deinit();
try actual_eb.renderToWriter(.{
- .ttyconf = .no_color,
.include_reference_trace = false,
.include_source_line = false,
- }, &aw.writer);
+ }, &aw.writer, .no_color);
break :ae try aw.toOwnedSlice();
};
diff --git a/lib/std/Build/Step/Run.zig b/lib/std/Build/Step/Run.zig
index 314862e201..eb1de3dd3b 100644
--- a/lib/std/Build/Step/Run.zig
+++ b/lib/std/Build/Step/Run.zig
@@ -1587,11 +1587,15 @@ fn spawnChildAndCollect(
run.step.test_results = res.test_results;
if (res.test_metadata) |tm| {
run.cached_test_metadata = tm.toCachedTestMetadata();
- if (options.web_server) |ws| ws.updateTimeReportRunTest(
- run,
- &run.cached_test_metadata.?,
- tm.ns_per_test,
- );
+ if (options.web_server) |ws| {
+ if (b.graph.time_report) {
+ ws.updateTimeReportRunTest(
+ run,
+ &run.cached_test_metadata.?,
+ tm.ns_per_test,
+ );
+ }
+ }
}
return null;
} else {
diff --git a/lib/std/Build/WebServer.zig b/lib/std/Build/WebServer.zig
index 50e304c950..4a136ccbf4 100644
--- a/lib/std/Build/WebServer.zig
+++ b/lib/std/Build/WebServer.zig
@@ -54,9 +54,9 @@ pub fn notifyUpdate(ws: *WebServer) void {
pub const Options = struct {
gpa: Allocator,
thread_pool: *std.Thread.Pool,
+ ttyconf: Io.tty.Config,
graph: *const std.Build.Graph,
all_steps: []const *Build.Step,
- ttyconf: Io.tty.Config,
root_prog_node: std.Progress.Node,
watch: bool,
listen_address: net.IpAddress,
@@ -101,10 +101,10 @@ pub fn init(opts: Options) WebServer {
return .{
.gpa = opts.gpa,
.thread_pool = opts.thread_pool,
+ .ttyconf = opts.ttyconf,
.graph = opts.graph,
.all_steps = all_steps,
.listen_address = opts.listen_address,
- .ttyconf = opts.ttyconf,
.root_prog_node = opts.root_prog_node,
.watch = opts.watch,
@@ -236,9 +236,9 @@ pub fn finishBuild(ws: *WebServer, opts: struct {
ws.gpa,
ws.graph.io,
ws.thread_pool,
+ ws.ttyconf,
ws.all_steps,
ws.root_prog_node,
- ws.ttyconf,
.{ .forever = .{ .ws = ws } },
) catch |err| std.process.fatal("failed to start fuzzer: {s}", .{@errorName(err)});
ws.fuzz.?.start();
@@ -655,8 +655,7 @@ fn buildClientWasm(ws: *WebServer, arena: Allocator, optimize: std.builtin.Optim
}
if (result_error_bundle.errorMessageCount() > 0) {
- const color = std.zig.Color.auto;
- result_error_bundle.renderToStdErr(color.renderOptions());
+ result_error_bundle.renderToStdErr(.{}, .auto);
log.err("the following command failed with {d} compilation errors:\n{s}", .{
result_error_bundle.errorMessageCount(),
try Build.Step.allocPrintCmd(arena, null, argv.items),