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 {...@@ -140,19 +140,7 @@ pub fn main(init: process.Init.Minimal) !void {
140 try Serialize.packageOptions(builder, &graph.wip_configuration);140 try Serialize.packageOptions(builder, &graph.wip_configuration);
141 try Serialize.systemIntegrationOptions(&graph, &graph.wip_configuration);141 try Serialize.systemIntegrationOptions(&graph, &graph.wip_configuration);
142142
143 var stdout_buffer: [1024]u8 = undefined;143 builder.serializeConfigurationExiting();
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);
156}144}
157145
158fn nextArg(args: []const [:0]const u8, idx: *usize) ?[:0]const u8 {146fn 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;...@@ -16,6 +16,7 @@ const process = std.process;
16const File = std.Io.File;16const File = std.Io.File;
17const Sha256 = std.crypto.hash.sha2.Sha256;17const Sha256 = std.crypto.hash.sha2.Sha256;
18const ArrayList = std.ArrayList;18const ArrayList = std.ArrayList;
19const fatal = std.process.fatal;
1920
20pub const Cache = @import("Build/Cache.zig");21pub const Cache = @import("Build/Cache.zig");
21pub const Step = @import("Build/Step.zig");22pub const Step = @import("Build/Step.zig");
...@@ -1989,13 +1990,13 @@ pub fn run(b: *Build, argv: []const []const u8) []u8 {...@@ -1989,13 +1990,13 @@ pub fn run(b: *Build, argv: []const []const u8) []u8 {
1989 .stderr_behavior = .inherit,1990 .stderr_behavior = .inherit,
1990 })) {1991 })) {
1991 .success => |stdout| return stdout,1992 .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}", .{
1993 err, std.zig.allocPrintCmd(arena, argv, .{}) catch @panic("OOM"),1994 err, std.zig.allocPrintCmd(arena, argv, .{}) catch @panic("OOM"),
1994 }),1995 }),
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}", .{
1996 code, std.zig.allocPrintCmd(arena, argv, .{}) catch @panic("OOM"),1997 code, std.zig.allocPrintCmd(arena, argv, .{}) catch @panic("OOM"),
1997 }),1998 }),
1998 .crashed => process.fatal("the following command crashed:\n{s}", .{1999 .crashed => fatal("the following command crashed:\n{s}", .{
1999 std.zig.allocPrintCmd(arena, argv, .{}) catch @panic("OOM"),2000 std.zig.allocPrintCmd(arena, argv, .{}) catch @panic("OOM"),
2000 }),2001 }),
2001 }2002 }
...@@ -2341,7 +2342,7 @@ fn dependencyInner(...@@ -2341,7 +2342,7 @@ fn dependencyInner(
2341 .root_dir = .{2342 .root_dir = .{
2342 .path = build_root_string,2343 .path = build_root_string,
2343 .handle = Io.Dir.cwd().openDir(io, build_root_string, .{}) catch |err|2344 .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 }),
2345 },2346 },
2346 };2347 };
23472348
...@@ -2838,6 +2839,26 @@ fn validateConfigureDependency(lazy_path: LazyPath) void {...@@ -2838,6 +2839,26 @@ fn validateConfigureDependency(lazy_path: LazyPath) void {
2838 }2839 }
2839}2840}
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
2841test {2862test {
2842 _ = Cache;2863 _ = Cache;
2843 _ = Configuration;2864 _ = Configuration;