diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2021-12-02 16:28:10 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2021-12-02 17:40:51 -0700 |
| commit | 0cd87102221233c2885faccfcaaac297b8d3b656 (patch) | |
| tree | 398202b27b782976d0971b26e5627837d99788de /lib | |
| parent | b24cbecdb2abb4399d65553ebade318263cd57d3 (diff) | |
| download | zig-0cd87102221233c2885faccfcaaac297b8d3b656.tar.gz zig-0cd87102221233c2885faccfcaaac297b8d3b656.zip | |
CLI: always try to exec binaries
Previously when using `zig run` or `zig test`, zig would try to guess
whether the host system was capable of running the target binaries. Now,
it will always try. If it fails, then Zig emits a helpful warning to
explain the probable cause.
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/std/build.zig | 71 |
1 files changed, 43 insertions, 28 deletions
diff --git a/lib/std/build.zig b/lib/std/build.zig index 041510bb02..75e6db301e 100644 --- a/lib/std/build.zig +++ b/lib/std/build.zig @@ -2527,45 +2527,56 @@ pub const LibExeObjStep = struct { } } } else switch (self.target.getExternalExecutor()) { - .native, .unavailable => {}, + .native => {}, + .unavailable => { + try zig_args.append("--test-no-exec"); + }, .rosetta => if (builder.enable_rosetta) { try zig_args.append("--test-cmd-bin"); + } else { + try zig_args.append("--test-no-exec"); }, - .qemu => |bin_name| if (builder.enable_qemu) qemu: { - const need_cross_glibc = self.target.isGnuLibC() and self.is_linking_libc; - const glibc_dir_arg = if (need_cross_glibc) - builder.glibc_runtimes_dir orelse break :qemu - else - null; - try zig_args.append("--test-cmd"); - try zig_args.append(bin_name); - if (glibc_dir_arg) |dir| { - // TODO look into making this a call to `linuxTriple`. This - // needs the directory to be called "i686" rather than - // "i386" which is why we do it manually here. - const fmt_str = "{s}" ++ fs.path.sep_str ++ "{s}-{s}-{s}"; - const cpu_arch = self.target.getCpuArch(); - const os_tag = self.target.getOsTag(); - const abi = self.target.getAbi(); - const cpu_arch_name: []const u8 = if (cpu_arch == .i386) - "i686" + .qemu => |bin_name| ok: { + if (builder.enable_qemu) qemu: { + const need_cross_glibc = self.target.isGnuLibC() and self.is_linking_libc; + const glibc_dir_arg = if (need_cross_glibc) + builder.glibc_runtimes_dir orelse break :qemu else - @tagName(cpu_arch); - const full_dir = try std.fmt.allocPrint(builder.allocator, fmt_str, .{ - dir, cpu_arch_name, @tagName(os_tag), @tagName(abi), - }); - + null; try zig_args.append("--test-cmd"); - try zig_args.append("-L"); - try zig_args.append("--test-cmd"); - try zig_args.append(full_dir); + try zig_args.append(bin_name); + if (glibc_dir_arg) |dir| { + // TODO look into making this a call to `linuxTriple`. This + // needs the directory to be called "i686" rather than + // "i386" which is why we do it manually here. + const fmt_str = "{s}" ++ fs.path.sep_str ++ "{s}-{s}-{s}"; + const cpu_arch = self.target.getCpuArch(); + const os_tag = self.target.getOsTag(); + const abi = self.target.getAbi(); + const cpu_arch_name: []const u8 = if (cpu_arch == .i386) + "i686" + else + @tagName(cpu_arch); + const full_dir = try std.fmt.allocPrint(builder.allocator, fmt_str, .{ + dir, cpu_arch_name, @tagName(os_tag), @tagName(abi), + }); + + try zig_args.append("--test-cmd"); + try zig_args.append("-L"); + try zig_args.append("--test-cmd"); + try zig_args.append(full_dir); + } + try zig_args.append("--test-cmd-bin"); + break :ok; } - try zig_args.append("--test-cmd-bin"); + try zig_args.append("--test-no-exec"); }, .wine => |bin_name| if (builder.enable_wine) { try zig_args.append("--test-cmd"); try zig_args.append(bin_name); try zig_args.append("--test-cmd-bin"); + } else { + try zig_args.append("--test-no-exec"); }, .wasmtime => |bin_name| if (builder.enable_wasmtime) { try zig_args.append("--test-cmd"); @@ -2573,11 +2584,15 @@ pub const LibExeObjStep = struct { try zig_args.append("--test-cmd"); try zig_args.append("--dir=."); try zig_args.append("--test-cmd-bin"); + } else { + try zig_args.append("--test-no-exec"); }, .darling => |bin_name| if (builder.enable_darling) { try zig_args.append("--test-cmd"); try zig_args.append(bin_name); try zig_args.append("--test-cmd-bin"); + } else { + try zig_args.append("--test-no-exec"); }, } |
