authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-10-30 15:44:58-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-10-30 15:44:58-07:00
log9b54c9dee8a571f1c821b3eb4ee3d2c713cf63fa
treef24ec417b12c1a964eee9a15adbc5454adcd7332
parent8caed4846018cd185b632bc884c7df81b8dd39dc

zig test: forward target CLI args to zig run when using -ofmt=c

Previously, if you used `zig test -ofmt=c -target foobar` then Zig would try to compile the generated C code with the native target instead of "foobar". With this change, `--test-cmd` with e.g. QEMU still won't work, but at least the binary will get compiled for the correct target.

1 files changed, 11 insertions(+), 0 deletions(-)

src/main.zig+11
......@@ -3021,6 +3021,17 @@ fn buildOutputType(
30213021 try test_exec_args.append(self_exe_path);
30223022 try test_exec_args.append("run");
30233023 if (link_libc) try test_exec_args.append("-lc");
3024 if (!mem.eql(u8, target_arch_os_abi, "native")) {
3025 try test_exec_args.append("-target");
3026 try test_exec_args.append(target_arch_os_abi);
3027 }
3028 if (target_mcpu) |mcpu| {
3029 try test_exec_args.append(try std.fmt.allocPrint(arena, "-mcpu={s}", .{mcpu}));
3030 }
3031 if (target_dynamic_linker) |dl| {
3032 try test_exec_args.append("--dynamic-linker");
3033 try test_exec_args.append(dl);
3034 }
30243035 try test_exec_args.append(c_code_path);
30253036 }
30263037