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 =...@@ -672,6 +672,7 @@ const usage_build_generic =
672 \\ --test-cmd-bin Appends test binary path to test cmd args672 \\ --test-cmd-bin Appends test binary path to test cmd args
673 \\ --test-no-exec Compiles test binary without running it673 \\ --test-no-exec Compiles test binary without running it
674 \\ --test-runner [path] Specify a custom test runner674 \\ --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
675 \\676 \\
676 \\Debug Options (Zig Compiler Development):677 \\Debug Options (Zig Compiler Development):
677 \\ -fopt-bisect-limit=[limit] Only run [limit] first LLVM optimization passes678 \\ -fopt-bisect-limit=[limit] Only run [limit] first LLVM optimization passes
...@@ -888,6 +889,7 @@ fn buildOutputType(...@@ -888,6 +889,7 @@ fn buildOutputType(
888 var linker_optimization: ?[]const u8 = null;889 var linker_optimization: ?[]const u8 = null;
889 var linker_module_definition_file: ?[]const u8 = null;890 var linker_module_definition_file: ?[]const u8 = null;
890 var test_no_exec = false;891 var test_no_exec = false;
892 var test_execve = false;
891 var entry: Compilation.CreateOptions.Entry = .default;893 var entry: Compilation.CreateOptions.Entry = .default;
892 var force_undefined_symbols: std.StringArrayHashMapUnmanaged(void) = .empty;894 var force_undefined_symbols: std.StringArrayHashMapUnmanaged(void) = .empty;
893 var stack_size: ?u64 = null;895 var stack_size: ?u64 = null;
...@@ -1393,6 +1395,8 @@ fn buildOutputType(...@@ -1393,6 +1395,8 @@ fn buildOutputType(
1393 test_no_exec = true;1395 test_no_exec = true;
1394 } else if (mem.eql(u8, arg, "--time-report")) {1396 } else if (mem.eql(u8, arg, "--time-report")) {
1395 time_report = true;1397 time_report = true;
1398 } else if (mem.eql(u8, arg, "--test-execve")) {
1399 test_execve = true;
1396 } else if (mem.eql(u8, arg, "-fstack-report")) {1400 } else if (mem.eql(u8, arg, "-fstack-report")) {
1397 stack_report = true;1401 stack_report = true;
1398 } else if (mem.eql(u8, arg, "-fPIC")) {1402 } else if (mem.eql(u8, arg, "-fPIC")) {
...@@ -3770,6 +3774,7 @@ fn buildOutputType(...@@ -3770,6 +3774,7 @@ fn buildOutputType(
3770 all_args,3774 all_args,
3771 runtime_args_start,3775 runtime_args_start,
3772 create_module.resolved_options.link_libc,3776 create_module.resolved_options.link_libc,
3777 test_execve,
3773 environ_map,3778 environ_map,
3774 );3779 );
3775 }3780 }
...@@ -4407,6 +4412,7 @@ fn runOrTest(...@@ -4407,6 +4412,7 @@ fn runOrTest(
4407 all_args: []const []const u8,4412 all_args: []const []const u8,
4408 runtime_args_start: ?usize,4413 runtime_args_start: ?usize,
4409 link_libc: bool,4414 link_libc: bool,
4415 test_execve: bool,
4410 environ_map: *process.Environ.Map,4416 environ_map: *process.Environ.Map,
4411) !void {4417) !void {
4412 const raw_emit_bin = comp.emit_bin orelse return;4418 const raw_emit_bin = comp.emit_bin orelse return;
...@@ -4448,7 +4454,7 @@ fn runOrTest(...@@ -4448,7 +4454,7 @@ fn runOrTest(
44484454
4449 // We do not execve for tests because if the test fails we want to print4455 // We do not execve for tests because if the test fails we want to print
4450 // the error message and invocation below.4456 // 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))) {
4452 // process replacement releases the locks; no need to destroy the Compilation here.4458 // process replacement releases the locks; no need to destroy the Compilation here.
4453 _ = try io.lockStderr(&.{}, .no_color);4459 _ = try io.lockStderr(&.{}, .no_color);
4454 const err = process.replace(io, .{ .argv = argv.items, .environ_map = environ_map });4460 const err = process.replace(io, .{ .argv = argv.items, .environ_map = environ_map });