From 127e2d8088a37b439ce087f2d58f544b9248dc02 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Wed, 5 Aug 2026 17:52:47 -0700 Subject: [PATCH] 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. --- lib/compiler/Maker/Step/Run.zig | 33 ++++++++++++ lib/std/Build/Configuration.zig | 7 +++ lib/std/Build/Serialize.zig | 95 +++++++++++++++++++++++++++++++++ lib/std/Build/Step/Run.zig | 53 ++++++++++++++++++ test/tests.zig | 9 ++-- 5 files changed, 193 insertions(+), 4 deletions(-) diff --git a/lib/compiler/Maker/Step/Run.zig b/lib/compiler/Maker/Step/Run.zig index 7f74e76954f44e5b965955d5ff5113d07428b6a7..85087be4d06ff29c71eabebd303e9ba6077dd1f9 100644 --- a/lib/compiler/Maker/Step/Run.zig +++ b/lib/compiler/Maker/Step/Run.zig @@ -187,6 +187,11 @@ pub fn make( man.hash.addListOfBytes(run_args); } }, + .enable_darling => thirdPartyToggle(&man.hash, &argv_list, conf, graph.enable_darling, arg.prefix.value, arg.suffix.value), + .enable_qemu => thirdPartyToggle(&man.hash, &argv_list, conf, graph.enable_qemu, arg.prefix.value, arg.suffix.value), + .enable_rosetta => thirdPartyToggle(&man.hash, &argv_list, conf, graph.enable_rosetta, arg.prefix.value, arg.suffix.value), + .enable_wasmtime => thirdPartyToggle(&man.hash, &argv_list, conf, graph.enable_wasmtime, arg.prefix.value, arg.suffix.value), + .enable_wine => thirdPartyToggle(&man.hash, &argv_list, conf, graph.enable_wine, arg.prefix.value, arg.suffix.value), } } @@ -351,6 +356,29 @@ pub fn make( step.clearFailedCommand(gpa); } +fn thirdPartyToggle( + man_hash: ?*Cache.HashHelper, + argv_list: *std.ArrayList([]const u8), + conf: *const Configuration, + setting: bool, + enable: ?Configuration.String, + disable: ?Configuration.String, +) void { + if (setting) { + if (enable) |string| { + const slice = string.slice(conf); + if (man_hash) |h| h.addBytesZ(slice); + argv_list.appendAssumeCapacity(slice); + } + } else { + if (disable) |string| { + const slice = string.slice(conf); + if (man_hash) |h| h.addBytesZ(slice); + argv_list.appendAssumeCapacity(slice); + } + } +} + /// Reads stdout of a Zig test process until a termination condition is reached: /// * A write fails, indicating the child unexpectedly closed stdin /// * A test (or a response from the test runner) times out @@ -1535,6 +1563,11 @@ pub fn rerunInFuzzMode( .output_file => unreachable, .output_directory => unreachable, .passthru => unreachable, + .enable_darling => thirdPartyToggle(null, &argv_list, conf, graph.enable_darling, arg.prefix.value, arg.suffix.value), + .enable_qemu => thirdPartyToggle(null, &argv_list, conf, graph.enable_qemu, arg.prefix.value, arg.suffix.value), + .enable_rosetta => thirdPartyToggle(null, &argv_list, conf, graph.enable_rosetta, arg.prefix.value, arg.suffix.value), + .enable_wasmtime => thirdPartyToggle(null, &argv_list, conf, graph.enable_wasmtime, arg.prefix.value, arg.suffix.value), + .enable_wine => thirdPartyToggle(null, &argv_list, conf, graph.enable_wine, arg.prefix.value, arg.suffix.value), } } diff --git a/lib/std/Build/Configuration.zig b/lib/std/Build/Configuration.zig index 8337da6d2f9d44f6f3b0a96241b4478f55afe3b0..fb5b04dc0039b28850dd11817b73c2f2b597da3d 100644 --- a/lib/std/Build/Configuration.zig +++ b/lib/std/Build/Configuration.zig @@ -626,6 +626,13 @@ pub const Step = extern struct { output_file, output_directory, passthru, + /// `prefix` contains the enabled string. + /// `suffix` contains the disabled string. + enable_darling, + enable_qemu, + enable_rosetta, + enable_wasmtime, + enable_wine, }; pub const Index = IndexType(@This()); diff --git a/lib/std/Build/Serialize.zig b/lib/std/Build/Serialize.zig index c3e9443181565196d6d922ea97f6e94f386b0f8a..995a69da87f9a6becfdb35f61683178b5e046c8b 100644 --- a/lib/std/Build/Serialize.zig +++ b/lib/std/Build/Serialize.zig @@ -1017,6 +1017,101 @@ fn initArgsList(s: *Serialize, args: []const Step.Run.Arg) ![]const Configuratio .producer = .{ .value = null }, .generated = .{ .value = null }, }, + .enable_darling => |a| .{ + .flags = .{ + .tag = .enable_darling, + .prefix = a.enabled != null, + .suffix = a.disabled != null, + .basename = false, + .path = false, + .producer = false, + .generated = false, + .dep_file = false, + .make_absolute = false, + }, + .prefix = .{ .value = try s.addOptionalString(a.enabled) }, + .suffix = .{ .value = try s.addOptionalString(a.disabled) }, + .basename = .{ .value = null }, + .path = .{ .value = null }, + .producer = .{ .value = null }, + .generated = .{ .value = null }, + }, + .enable_qemu => |a| .{ + .flags = .{ + .tag = .enable_qemu, + .prefix = a.enabled != null, + .suffix = a.disabled != null, + .basename = false, + .path = false, + .producer = false, + .generated = false, + .dep_file = false, + .make_absolute = false, + }, + .prefix = .{ .value = try s.addOptionalString(a.enabled) }, + .suffix = .{ .value = try s.addOptionalString(a.disabled) }, + .basename = .{ .value = null }, + .path = .{ .value = null }, + .producer = .{ .value = null }, + .generated = .{ .value = null }, + }, + .enable_rosetta => |a| .{ + .flags = .{ + .tag = .enable_rosetta, + .prefix = a.enabled != null, + .suffix = a.disabled != null, + .basename = false, + .path = false, + .producer = false, + .generated = false, + .dep_file = false, + .make_absolute = false, + }, + .prefix = .{ .value = try s.addOptionalString(a.enabled) }, + .suffix = .{ .value = try s.addOptionalString(a.disabled) }, + .basename = .{ .value = null }, + .path = .{ .value = null }, + .producer = .{ .value = null }, + .generated = .{ .value = null }, + }, + .enable_wasmtime => |a| .{ + .flags = .{ + .tag = .enable_wasmtime, + .prefix = a.enabled != null, + .suffix = a.disabled != null, + .basename = false, + .path = false, + .producer = false, + .generated = false, + .dep_file = false, + .make_absolute = false, + }, + .prefix = .{ .value = try s.addOptionalString(a.enabled) }, + .suffix = .{ .value = try s.addOptionalString(a.disabled) }, + .basename = .{ .value = null }, + .path = .{ .value = null }, + .producer = .{ .value = null }, + .generated = .{ .value = null }, + }, + .enable_wine => |a| .{ + .flags = .{ + .tag = .enable_wine, + .prefix = a.enabled != null, + .suffix = a.disabled != null, + .basename = false, + .path = false, + .producer = false, + .generated = false, + .dep_file = false, + .make_absolute = false, + }, + .prefix = .{ .value = try s.addOptionalString(a.enabled) }, + .suffix = .{ .value = try s.addOptionalString(a.disabled) }, + .basename = .{ .value = null }, + .path = .{ .value = null }, + .producer = .{ .value = null }, + .generated = .{ .value = null }, + }, }); } return result; diff --git a/lib/std/Build/Step/Run.zig b/lib/std/Build/Step/Run.zig index 564dd2507dca28de63f943054b787c8602cc4f86..7d271e10e1461606574b96a6966332975b39b706 100644 --- a/lib/std/Build/Step/Run.zig +++ b/lib/std/Build/Step/Run.zig @@ -151,6 +151,19 @@ pub const Arg = union(enum) { output_directory: *Output, /// The arguments passed after "--" on the "zig build" CLI. passthru, + + enable_darling: ToggleFlags, + enable_qemu: ToggleFlags, + enable_rosetta: ToggleFlags, + enable_wasmtime: ToggleFlags, + enable_wine: ToggleFlags, +}; + +pub const ToggleFlags = struct { + /// The string to pass when enabled, or null to omit the arg. + enabled: ?[]const u8 = null, + /// The string to pass when disabled, or null to omit the arg. + disabled: ?[]const u8 = null, }; pub const DecoratedArtifact = struct { @@ -578,6 +591,46 @@ pub fn addPassthruArgs(run: *Run) void { run.argv.append(arena, .passthru) catch @panic("OOM"); } +/// Appends a custom string to the command line depending on the `-fdarling` +/// value passed to `zig build`. +pub fn addThirdPartyEnabledArgDarling(run: *Run, toggle_flags: ToggleFlags) void { + const graph = run.step.owner.graph; + const arena = graph.arena; + run.argv.append(arena, .{ .enable_darling = toggle_flags }) catch @panic("OOM"); +} + +/// Appends a custom string to the command line depending on the `-fqemu` +/// value passed to `zig build`. +pub fn addThirdPartyEnabledArgQemu(run: *Run, toggle_flags: ToggleFlags) void { + const graph = run.step.owner.graph; + const arena = graph.arena; + run.argv.append(arena, .{ .enable_qemu = toggle_flags }) catch @panic("OOM"); +} + +/// Appends a custom string to the command line depending on the `-frosetta` +/// value passed to `zig build`. +pub fn addThirdPartyEnabledArgRosetta(run: *Run, toggle_flags: ToggleFlags) void { + const graph = run.step.owner.graph; + const arena = graph.arena; + run.argv.append(arena, .{ .enable_rosetta = toggle_flags }) catch @panic("OOM"); +} + +/// Appends a custom string to the command line depending on the `-fwasmtime` +/// value passed to `zig build`. +pub fn addThirdPartyEnabledArgWasmtime(run: *Run, toggle_flags: ToggleFlags) void { + const graph = run.step.owner.graph; + const arena = graph.arena; + run.argv.append(arena, .{ .enable_wasmtime = toggle_flags }) catch @panic("OOM"); +} + +/// Appends a custom string to the command line depending on the `-fwine` +/// value passed to `zig build`. +pub fn addThirdPartyEnabledArgWine(run: *Run, toggle_flags: ToggleFlags) void { + const graph = run.step.owner.graph; + const arena = graph.arena; + run.argv.append(arena, .{ .enable_wine = toggle_flags }) catch @panic("OOM"); +} + pub fn setStdIn(run: *Run, stdin: StdIn) void { switch (stdin) { .lazy_path => |lazy_path| lazy_path.addStepDependencies(&run.step), diff --git a/test/tests.zig b/test/tests.zig index bf72b15cf3eb42ab4de671277aeb6555bd5a5867..44fefc69357840c351979e7cd6551e43342f0298 100644 --- a/test/tests.zig +++ b/test/tests.zig @@ -3409,10 +3409,11 @@ pub fn addIncrementalTests(b: *std.Build, test_step: *Step, test_filters: []cons run.addArg("--quiet"); // don't fill stderr telling us about skipped tests etc - if (b.enable_qemu) run.addArg("-fqemu"); - if (b.enable_wine) run.addArg("-fwine"); - if (b.enable_wasmtime) run.addArg("-fwasmtime"); - if (b.enable_darling) run.addArg("-fdarling"); + run.addThirdPartyEnabledArgDarling(.{ .enabled = "-fdarling" }); + run.addThirdPartyEnabledArgQemu(.{ .enabled = "-fqemu" }); + run.addThirdPartyEnabledArgRosetta(.{ .enabled = "-frosetta" }); + run.addThirdPartyEnabledArgWasmtime(.{ .enabled = "-fwasmtime" }); + run.addThirdPartyEnabledArgWine(.{ .enabled = "-fwine" }); run.addCheck(.{ .expect_term = .{ .exited = 0 } }); test_step.dependOn(&run.step); -- 2.54.0