diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2021-12-01 17:32:27 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-12-01 17:32:27 -0800 |
| commit | 14b532ec8596d7f84b76127f1b858271f010126f (patch) | |
| tree | 1e05b622760b5288bba853c575daa2d048a10403 /lib/std | |
| parent | 1912ec0323af9a9077a8706157beb8207f6e3eb9 (diff) | |
| parent | 42db5156656ebd1649f7ec3707697b08657b9cab (diff) | |
| download | zig-14b532ec8596d7f84b76127f1b858271f010126f.tar.gz zig-14b532ec8596d7f84b76127f1b858271f010126f.zip | |
Merge pull request #10122 from ziglang/x86_64-as-native-rosetta
Treat x86_64 tests as native under the Rosetta 2 on M1 Macs
Diffstat (limited to 'lib/std')
| -rw-r--r-- | lib/std/build.zig | 6 | ||||
| -rw-r--r-- | lib/std/zig/CrossTarget.zig | 9 |
2 files changed, 15 insertions, 0 deletions
diff --git a/lib/std/build.zig b/lib/std/build.zig index ea6a0e05f1..600fb691ae 100644 --- a/lib/std/build.zig +++ b/lib/std/build.zig @@ -1516,6 +1516,9 @@ pub const LibExeObjStep = struct { /// Experimental. Uses system Darling installation to run cross compiled macOS build artifacts. enable_darling: bool = false, + /// Darwin. Uses Rosetta to run x86_64 macOS build artifacts on arm64 macOS. + enable_rosetta: bool = false, + /// After following the steps in https://github.com/ziglang/zig/wiki/Updating-libc#glibc, /// this will be the directory $glibc-build-dir/install/glibcs /// Given the example of the aarch64 target, this is the directory @@ -2530,6 +2533,9 @@ pub const LibExeObjStep = struct { } } else switch (self.target.getExternalExecutor()) { .native, .unavailable => {}, + .rosetta => if (self.enable_rosetta) { + try zig_args.append("--test-cmd-bin"); + }, .qemu => |bin_name| if (self.enable_qemu) qemu: { const need_cross_glibc = self.target.isGnuLibC() and self.is_linking_libc; const glibc_dir_arg = if (need_cross_glibc) diff --git a/lib/std/zig/CrossTarget.zig b/lib/std/zig/CrossTarget.zig index 03bb6bc5ff..96213b1471 100644 --- a/lib/std/zig/CrossTarget.zig +++ b/lib/std/zig/CrossTarget.zig @@ -612,6 +612,7 @@ pub fn vcpkgTriplet(self: CrossTarget, allocator: mem.Allocator, linkage: VcpkgL pub const Executor = union(enum) { native, + rosetta, qemu: []const u8, wine: []const u8, wasmtime: []const u8, @@ -642,6 +643,14 @@ pub fn getExternalExecutor(self: CrossTarget) Executor { return .native; } } + // If the OS match and OS is macOS and CPU is arm64, we can use Rosetta 2 + // to emulate the foreign architecture. + if (os_match and os_tag == .macos and builtin.cpu.arch == .aarch64) { + return switch (cpu_arch) { + .x86_64 => .rosetta, + else => .unavailable, + }; + } // If the OS matches, we can use QEMU to emulate a foreign architecture. if (os_match) { |
