authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-08-05 17:52:47-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-08-07 11:19:55-07:00
log127e2d8088a37b439ce087f2d58f544b9248dc02
treee97fe7d8c0f2233e5681ad0af352be523b839812
parent5228c8902fe178834f678cb5bec12a5a32d5df2f

ability to forward third party integration arguments to child processes

This provides a way to forward, e.g. the `-fqemu` argument from `zig build` to a child process during Maker execution without providing the information to the configuration logic.

5 files changed, 193 insertions(+), 4 deletions(-)

lib/compiler/Maker/Step/Run.zig+33
......@@ -187,6 +187,11 @@ pub fn make(
187187 man.hash.addListOfBytes(run_args);
188188 }
189189 },
190 .enable_darling => thirdPartyToggle(&man.hash, &argv_list, conf, graph.enable_darling, arg.prefix.value, arg.suffix.value),
191 .enable_qemu => thirdPartyToggle(&man.hash, &argv_list, conf, graph.enable_qemu, arg.prefix.value, arg.suffix.value),
192 .enable_rosetta => thirdPartyToggle(&man.hash, &argv_list, conf, graph.enable_rosetta, arg.prefix.value, arg.suffix.value),
193 .enable_wasmtime => thirdPartyToggle(&man.hash, &argv_list, conf, graph.enable_wasmtime, arg.prefix.value, arg.suffix.value),
194 .enable_wine => thirdPartyToggle(&man.hash, &argv_list, conf, graph.enable_wine, arg.prefix.value, arg.suffix.value),
190195 }
191196 }
192197
......@@ -351,6 +356,29 @@ pub fn make(
351356 step.clearFailedCommand(gpa);
352357}
353358
359fn thirdPartyToggle(
360 man_hash: ?*Cache.HashHelper,
361 argv_list: *std.ArrayList([]const u8),
362 conf: *const Configuration,
363 setting: bool,
364 enable: ?Configuration.String,
365 disable: ?Configuration.String,
366) void {
367 if (setting) {
368 if (enable) |string| {
369 const slice = string.slice(conf);
370 if (man_hash) |h| h.addBytesZ(slice);
371 argv_list.appendAssumeCapacity(slice);
372 }
373 } else {
374 if (disable) |string| {
375 const slice = string.slice(conf);
376 if (man_hash) |h| h.addBytesZ(slice);
377 argv_list.appendAssumeCapacity(slice);
378 }
379 }
380}
381
354382/// Reads stdout of a Zig test process until a termination condition is reached:
355383/// * A write fails, indicating the child unexpectedly closed stdin
356384/// * A test (or a response from the test runner) times out
......@@ -1535,6 +1563,11 @@ pub fn rerunInFuzzMode(
15351563 .output_file => unreachable,
15361564 .output_directory => unreachable,
15371565 .passthru => unreachable,
1566 .enable_darling => thirdPartyToggle(null, &argv_list, conf, graph.enable_darling, arg.prefix.value, arg.suffix.value),
1567 .enable_qemu => thirdPartyToggle(null, &argv_list, conf, graph.enable_qemu, arg.prefix.value, arg.suffix.value),
1568 .enable_rosetta => thirdPartyToggle(null, &argv_list, conf, graph.enable_rosetta, arg.prefix.value, arg.suffix.value),
1569 .enable_wasmtime => thirdPartyToggle(null, &argv_list, conf, graph.enable_wasmtime, arg.prefix.value, arg.suffix.value),
1570 .enable_wine => thirdPartyToggle(null, &argv_list, conf, graph.enable_wine, arg.prefix.value, arg.suffix.value),
15381571 }
15391572 }
15401573
lib/std/Build/Configuration.zig+7
......@@ -626,6 +626,13 @@ pub const Step = extern struct {
626626 output_file,
627627 output_directory,
628628 passthru,
629 /// `prefix` contains the enabled string.
630 /// `suffix` contains the disabled string.
631 enable_darling,
632 enable_qemu,
633 enable_rosetta,
634 enable_wasmtime,
635 enable_wine,
629636 };
630637
631638 pub const Index = IndexType(@This());
lib/std/Build/Serialize.zig+95
......@@ -1017,6 +1017,101 @@ fn initArgsList(s: *Serialize, args: []const Step.Run.Arg) ![]const Configuratio
10171017 .producer = .{ .value = null },
10181018 .generated = .{ .value = null },
10191019 },
1020 .enable_darling => |a| .{
1021 .flags = .{
1022 .tag = .enable_darling,
1023 .prefix = a.enabled != null,
1024 .suffix = a.disabled != null,
1025 .basename = false,
1026 .path = false,
1027 .producer = false,
1028 .generated = false,
1029 .dep_file = false,
1030 .make_absolute = false,
1031 },
1032 .prefix = .{ .value = try s.addOptionalString(a.enabled) },
1033 .suffix = .{ .value = try s.addOptionalString(a.disabled) },
1034 .basename = .{ .value = null },
1035 .path = .{ .value = null },
1036 .producer = .{ .value = null },
1037 .generated = .{ .value = null },
1038 },
1039 .enable_qemu => |a| .{
1040 .flags = .{
1041 .tag = .enable_qemu,
1042 .prefix = a.enabled != null,
1043 .suffix = a.disabled != null,
1044 .basename = false,
1045 .path = false,
1046 .producer = false,
1047 .generated = false,
1048 .dep_file = false,
1049 .make_absolute = false,
1050 },
1051 .prefix = .{ .value = try s.addOptionalString(a.enabled) },
1052 .suffix = .{ .value = try s.addOptionalString(a.disabled) },
1053 .basename = .{ .value = null },
1054 .path = .{ .value = null },
1055 .producer = .{ .value = null },
1056 .generated = .{ .value = null },
1057 },
1058 .enable_rosetta => |a| .{
1059 .flags = .{
1060 .tag = .enable_rosetta,
1061 .prefix = a.enabled != null,
1062 .suffix = a.disabled != null,
1063 .basename = false,
1064 .path = false,
1065 .producer = false,
1066 .generated = false,
1067 .dep_file = false,
1068 .make_absolute = false,
1069 },
1070 .prefix = .{ .value = try s.addOptionalString(a.enabled) },
1071 .suffix = .{ .value = try s.addOptionalString(a.disabled) },
1072 .basename = .{ .value = null },
1073 .path = .{ .value = null },
1074 .producer = .{ .value = null },
1075 .generated = .{ .value = null },
1076 },
1077 .enable_wasmtime => |a| .{
1078 .flags = .{
1079 .tag = .enable_wasmtime,
1080 .prefix = a.enabled != null,
1081 .suffix = a.disabled != null,
1082 .basename = false,
1083 .path = false,
1084 .producer = false,
1085 .generated = false,
1086 .dep_file = false,
1087 .make_absolute = false,
1088 },
1089 .prefix = .{ .value = try s.addOptionalString(a.enabled) },
1090 .suffix = .{ .value = try s.addOptionalString(a.disabled) },
1091 .basename = .{ .value = null },
1092 .path = .{ .value = null },
1093 .producer = .{ .value = null },
1094 .generated = .{ .value = null },
1095 },
1096 .enable_wine => |a| .{
1097 .flags = .{
1098 .tag = .enable_wine,
1099 .prefix = a.enabled != null,
1100 .suffix = a.disabled != null,
1101 .basename = false,
1102 .path = false,
1103 .producer = false,
1104 .generated = false,
1105 .dep_file = false,
1106 .make_absolute = false,
1107 },
1108 .prefix = .{ .value = try s.addOptionalString(a.enabled) },
1109 .suffix = .{ .value = try s.addOptionalString(a.disabled) },
1110 .basename = .{ .value = null },
1111 .path = .{ .value = null },
1112 .producer = .{ .value = null },
1113 .generated = .{ .value = null },
1114 },
10201115 });
10211116 }
10221117 return result;
lib/std/Build/Step/Run.zig+53
......@@ -151,6 +151,19 @@ pub const Arg = union(enum) {
151151 output_directory: *Output,
152152 /// The arguments passed after "--" on the "zig build" CLI.
153153 passthru,
154
155 enable_darling: ToggleFlags,
156 enable_qemu: ToggleFlags,
157 enable_rosetta: ToggleFlags,
158 enable_wasmtime: ToggleFlags,
159 enable_wine: ToggleFlags,
160};
161
162pub const ToggleFlags = struct {
163 /// The string to pass when enabled, or null to omit the arg.
164 enabled: ?[]const u8 = null,
165 /// The string to pass when disabled, or null to omit the arg.
166 disabled: ?[]const u8 = null,
154167};
155168
156169pub const DecoratedArtifact = struct {
......@@ -578,6 +591,46 @@ pub fn addPassthruArgs(run: *Run) void {
578591 run.argv.append(arena, .passthru) catch @panic("OOM");
579592}
580593
594/// Appends a custom string to the command line depending on the `-fdarling`
595/// value passed to `zig build`.
596pub fn addThirdPartyEnabledArgDarling(run: *Run, toggle_flags: ToggleFlags) void {
597 const graph = run.step.owner.graph;
598 const arena = graph.arena;
599 run.argv.append(arena, .{ .enable_darling = toggle_flags }) catch @panic("OOM");
600}
601
602/// Appends a custom string to the command line depending on the `-fqemu`
603/// value passed to `zig build`.
604pub fn addThirdPartyEnabledArgQemu(run: *Run, toggle_flags: ToggleFlags) void {
605 const graph = run.step.owner.graph;
606 const arena = graph.arena;
607 run.argv.append(arena, .{ .enable_qemu = toggle_flags }) catch @panic("OOM");
608}
609
610/// Appends a custom string to the command line depending on the `-frosetta`
611/// value passed to `zig build`.
612pub fn addThirdPartyEnabledArgRosetta(run: *Run, toggle_flags: ToggleFlags) void {
613 const graph = run.step.owner.graph;
614 const arena = graph.arena;
615 run.argv.append(arena, .{ .enable_rosetta = toggle_flags }) catch @panic("OOM");
616}
617
618/// Appends a custom string to the command line depending on the `-fwasmtime`
619/// value passed to `zig build`.
620pub fn addThirdPartyEnabledArgWasmtime(run: *Run, toggle_flags: ToggleFlags) void {
621 const graph = run.step.owner.graph;
622 const arena = graph.arena;
623 run.argv.append(arena, .{ .enable_wasmtime = toggle_flags }) catch @panic("OOM");
624}
625
626/// Appends a custom string to the command line depending on the `-fwine`
627/// value passed to `zig build`.
628pub fn addThirdPartyEnabledArgWine(run: *Run, toggle_flags: ToggleFlags) void {
629 const graph = run.step.owner.graph;
630 const arena = graph.arena;
631 run.argv.append(arena, .{ .enable_wine = toggle_flags }) catch @panic("OOM");
632}
633
581634pub fn setStdIn(run: *Run, stdin: StdIn) void {
582635 switch (stdin) {
583636 .lazy_path => |lazy_path| lazy_path.addStepDependencies(&run.step),
test/tests.zig+5-4
......@@ -3409,10 +3409,11 @@ pub fn addIncrementalTests(b: *std.Build, test_step: *Step, test_filters: []cons
34093409
34103410 run.addArg("--quiet"); // don't fill stderr telling us about skipped tests etc
34113411
3412 if (b.enable_qemu) run.addArg("-fqemu");
3413 if (b.enable_wine) run.addArg("-fwine");
3414 if (b.enable_wasmtime) run.addArg("-fwasmtime");
3415 if (b.enable_darling) run.addArg("-fdarling");
3412 run.addThirdPartyEnabledArgDarling(.{ .enabled = "-fdarling" });
3413 run.addThirdPartyEnabledArgQemu(.{ .enabled = "-fqemu" });
3414 run.addThirdPartyEnabledArgRosetta(.{ .enabled = "-frosetta" });
3415 run.addThirdPartyEnabledArgWasmtime(.{ .enabled = "-fwasmtime" });
3416 run.addThirdPartyEnabledArgWine(.{ .enabled = "-fwine" });
34163417
34173418 run.addCheck(.{ .expect_term = .{ .exited = 0 } });
34183419 test_step.dependOn(&run.step);