authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-07-01 14:19:42-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-07-01 14:19:42-07:00
logdc5feb49ebfee6e2af6f76dd45466760aac9f795
treee72bce90dc2bcedb6d4d136124c02ec6bb32de4e
parent8923dd4ca257436f04408a2a9ad9a429275a98dc

std.Build.serializeConfigurationExiting: extract from configurer


2 files changed, 26 insertions(+), 17 deletions(-)

lib/compiler/configurer.zig+1-13
......@@ -140,19 +140,7 @@ pub fn main(init: process.Init.Minimal) !void {
140140 try Serialize.packageOptions(builder, &graph.wip_configuration);
141141 try Serialize.systemIntegrationOptions(&graph, &graph.wip_configuration);
142142
143 var stdout_buffer: [1024]u8 = undefined;
144 var file_writer = Io.File.stdout().writerStreaming(io, &stdout_buffer);
145 Serialize.write(builder, &graph.wip_configuration, &file_writer.interface) catch |err| switch (err) {
146 error.WriteFailed => fatal("failed to write configuration output: {t}", .{file_writer.err.?}),
147 error.OutOfMemory => |e| return e,
148 };
149 file_writer.flush() catch |err| fatal("failed to write configuration output: {t}", .{err});
150
151 // This executable is short-lived and run in Debug mode, so we'd rather
152 // have `zig build` run faster than catch resource leaks in the user's
153 // build.zig script (or, frankly, this configure runner), therefore we call
154 // exit directly here rather than cleanExit.
155 process.exit(0);
143 builder.serializeConfigurationExiting();
156144}
157145
158146fn nextArg(args: []const [:0]const u8, idx: *usize) ?[:0]const u8 {
lib/std/Build.zig+25-4
......@@ -16,6 +16,7 @@ const process = std.process;
1616const File = std.Io.File;
1717const Sha256 = std.crypto.hash.sha2.Sha256;
1818const ArrayList = std.ArrayList;
19const fatal = std.process.fatal;
1920
2021pub const Cache = @import("Build/Cache.zig");
2122pub const Step = @import("Build/Step.zig");
......@@ -1989,13 +1990,13 @@ pub fn run(b: *Build, argv: []const []const u8) []u8 {
19891990 .stderr_behavior = .inherit,
19901991 })) {
19911992 .success => |stdout| return stdout,
1992 .spawn_failed => |err| process.fatal("the following command failed with {t}:\n{s}", .{
1993 .spawn_failed => |err| fatal("the following command failed with {t}:\n{s}", .{
19931994 err, std.zig.allocPrintCmd(arena, argv, .{}) catch @panic("OOM"),
19941995 }),
1995 .bad_exit_code => |code| process.fatal("the following command exited with code {d}:\n{s}", .{
1996 .bad_exit_code => |code| fatal("the following command exited with code {d}:\n{s}", .{
19961997 code, std.zig.allocPrintCmd(arena, argv, .{}) catch @panic("OOM"),
19971998 }),
1998 .crashed => process.fatal("the following command crashed:\n{s}", .{
1999 .crashed => fatal("the following command crashed:\n{s}", .{
19992000 std.zig.allocPrintCmd(arena, argv, .{}) catch @panic("OOM"),
20002001 }),
20012002 }
......@@ -2341,7 +2342,7 @@ fn dependencyInner(
23412342 .root_dir = .{
23422343 .path = build_root_string,
23432344 .handle = Io.Dir.cwd().openDir(io, build_root_string, .{}) catch |err|
2344 process.fatal("failed to open {q}: {t}", .{ build_root_string, err }),
2345 fatal("failed to open {q}: {t}", .{ build_root_string, err }),
23452346 },
23462347 };
23472348
......@@ -2838,6 +2839,26 @@ fn validateConfigureDependency(lazy_path: LazyPath) void {
28382839 }
28392840}
28402841
2842/// Build system implementation detail.
2843pub fn serializeConfigurationExiting(b: *Build) void {
2844 const graph = b.graph;
2845 const io = graph.io;
2846
2847 var stdout_buffer: [1024]u8 = undefined;
2848 var file_writer = Io.File.stdout().writerStreaming(io, &stdout_buffer);
2849 Serialize.write(b, &graph.wip_configuration, &file_writer.interface) catch |err| switch (err) {
2850 error.WriteFailed => fatal("failed to write configuration output: {t}", .{file_writer.err.?}),
2851 error.OutOfMemory => @panic("OOM"),
2852 };
2853 file_writer.flush() catch |err| fatal("failed to write configuration output: {t}", .{err});
2854
2855 // This executable is short-lived and run in Debug mode, so we'd rather
2856 // have `zig build` run faster than catch resource leaks in the user's
2857 // build.zig script (or, frankly, this configure runner), therefore we call
2858 // exit directly here rather than cleanExit.
2859 process.exit(0);
2860}
2861
28412862test {
28422863 _ = Cache;
28432864 _ = Configuration;