From dc5feb49ebfee6e2af6f76dd45466760aac9f795 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Wed, 1 Jul 2026 14:19:42 -0700 Subject: [PATCH] std.Build.serializeConfigurationExiting: extract from configurer --- lib/compiler/configurer.zig | 14 +------------- lib/std/Build.zig | 29 +++++++++++++++++++++++++---- 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/lib/compiler/configurer.zig b/lib/compiler/configurer.zig index cdc25780979568e8c2ad0962cec606429a44bf3d..9151d0d06bab9540bb2382693553ac06ad8d964e 100644 --- a/lib/compiler/configurer.zig +++ b/lib/compiler/configurer.zig @@ -140,19 +140,7 @@ pub fn main(init: process.Init.Minimal) !void { try Serialize.packageOptions(builder, &graph.wip_configuration); try Serialize.systemIntegrationOptions(&graph, &graph.wip_configuration); - var stdout_buffer: [1024]u8 = undefined; - var file_writer = Io.File.stdout().writerStreaming(io, &stdout_buffer); - Serialize.write(builder, &graph.wip_configuration, &file_writer.interface) catch |err| switch (err) { - error.WriteFailed => fatal("failed to write configuration output: {t}", .{file_writer.err.?}), - error.OutOfMemory => |e| return e, - }; - file_writer.flush() catch |err| fatal("failed to write configuration output: {t}", .{err}); - - // This executable is short-lived and run in Debug mode, so we'd rather - // have `zig build` run faster than catch resource leaks in the user's - // build.zig script (or, frankly, this configure runner), therefore we call - // exit directly here rather than cleanExit. - process.exit(0); + builder.serializeConfigurationExiting(); } fn nextArg(args: []const [:0]const u8, idx: *usize) ?[:0]const u8 { diff --git a/lib/std/Build.zig b/lib/std/Build.zig index adabef5f3c4f15c3ce1b6a334507bff6b43c37de..30b4c1bd9e3e2b94bd028659aff788caab8a4a08 100644 --- a/lib/std/Build.zig +++ b/lib/std/Build.zig @@ -16,6 +16,7 @@ const process = std.process; const File = std.Io.File; const Sha256 = std.crypto.hash.sha2.Sha256; const ArrayList = std.ArrayList; +const fatal = std.process.fatal; pub const Cache = @import("Build/Cache.zig"); pub const Step = @import("Build/Step.zig"); @@ -1989,13 +1990,13 @@ pub fn run(b: *Build, argv: []const []const u8) []u8 { .stderr_behavior = .inherit, })) { .success => |stdout| return stdout, - .spawn_failed => |err| process.fatal("the following command failed with {t}:\n{s}", .{ + .spawn_failed => |err| fatal("the following command failed with {t}:\n{s}", .{ err, std.zig.allocPrintCmd(arena, argv, .{}) catch @panic("OOM"), }), - .bad_exit_code => |code| process.fatal("the following command exited with code {d}:\n{s}", .{ + .bad_exit_code => |code| fatal("the following command exited with code {d}:\n{s}", .{ code, std.zig.allocPrintCmd(arena, argv, .{}) catch @panic("OOM"), }), - .crashed => process.fatal("the following command crashed:\n{s}", .{ + .crashed => fatal("the following command crashed:\n{s}", .{ std.zig.allocPrintCmd(arena, argv, .{}) catch @panic("OOM"), }), } @@ -2341,7 +2342,7 @@ fn dependencyInner( .root_dir = .{ .path = build_root_string, .handle = Io.Dir.cwd().openDir(io, build_root_string, .{}) catch |err| - process.fatal("failed to open {q}: {t}", .{ build_root_string, err }), + fatal("failed to open {q}: {t}", .{ build_root_string, err }), }, }; @@ -2838,6 +2839,26 @@ fn validateConfigureDependency(lazy_path: LazyPath) void { } } +/// Build system implementation detail. +pub fn serializeConfigurationExiting(b: *Build) void { + const graph = b.graph; + const io = graph.io; + + var stdout_buffer: [1024]u8 = undefined; + var file_writer = Io.File.stdout().writerStreaming(io, &stdout_buffer); + Serialize.write(b, &graph.wip_configuration, &file_writer.interface) catch |err| switch (err) { + error.WriteFailed => fatal("failed to write configuration output: {t}", .{file_writer.err.?}), + error.OutOfMemory => @panic("OOM"), + }; + file_writer.flush() catch |err| fatal("failed to write configuration output: {t}", .{err}); + + // This executable is short-lived and run in Debug mode, so we'd rather + // have `zig build` run faster than catch resource leaks in the user's + // build.zig script (or, frankly, this configure runner), therefore we call + // exit directly here rather than cleanExit. + process.exit(0); +} + test { _ = Cache; _ = Configuration; -- 2.54.0