authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-01-12 20:52:35-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-01-13 20:45:46+01:00
log7ea38425498e6be084278dcfd327b705940f15ed
tree1710b2cb4e86c850fd3878b42cb1e4b482cf1f78
parent2301f2ecdf3a4f823c1a66482af2574738ffb554

cli: add --test-execve option


1 files changed, 7 insertions(+), 1 deletions(-)

src/main.zig+7-1
......@@ -672,6 +672,7 @@ const usage_build_generic =
672672 \\ --test-cmd-bin Appends test binary path to test cmd args
673673 \\ --test-no-exec Compiles test binary without running it
674674 \\ --test-runner [path] Specify a custom test runner
675 \\ --test-execve Runs the test binary with execve if available instead of as a child process
675676 \\
676677 \\Debug Options (Zig Compiler Development):
677678 \\ -fopt-bisect-limit=[limit] Only run [limit] first LLVM optimization passes
......@@ -888,6 +889,7 @@ fn buildOutputType(
888889 var linker_optimization: ?[]const u8 = null;
889890 var linker_module_definition_file: ?[]const u8 = null;
890891 var test_no_exec = false;
892 var test_execve = false;
891893 var entry: Compilation.CreateOptions.Entry = .default;
892894 var force_undefined_symbols: std.StringArrayHashMapUnmanaged(void) = .empty;
893895 var stack_size: ?u64 = null;
......@@ -1393,6 +1395,8 @@ fn buildOutputType(
13931395 test_no_exec = true;
13941396 } else if (mem.eql(u8, arg, "--time-report")) {
13951397 time_report = true;
1398 } else if (mem.eql(u8, arg, "--test-execve")) {
1399 test_execve = true;
13961400 } else if (mem.eql(u8, arg, "-fstack-report")) {
13971401 stack_report = true;
13981402 } else if (mem.eql(u8, arg, "-fPIC")) {
......@@ -3770,6 +3774,7 @@ fn buildOutputType(
37703774 all_args,
37713775 runtime_args_start,
37723776 create_module.resolved_options.link_libc,
3777 test_execve,
37733778 environ_map,
37743779 );
37753780 }
......@@ -4407,6 +4412,7 @@ fn runOrTest(
44074412 all_args: []const []const u8,
44084413 runtime_args_start: ?usize,
44094414 link_libc: bool,
4415 test_execve: bool,
44104416 environ_map: *process.Environ.Map,
44114417) !void {
44124418 const raw_emit_bin = comp.emit_bin orelse return;
......@@ -4448,7 +4454,7 @@ fn runOrTest(
44484454
44494455 // We do not execve for tests because if the test fails we want to print
44504456 // the error message and invocation below.
4451 if (process.can_replace and arg_mode == .run) {
4457 if (process.can_replace and (arg_mode == .run or (arg_mode == .zig_test and test_execve))) {
44524458 // process replacement releases the locks; no need to destroy the Compilation here.
44534459 _ = try io.lockStderr(&.{}, .no_color);
44544460 const err = process.replace(io, .{ .argv = argv.items, .environ_map = environ_map });