| author | |
| committer | |
| log | 3e2f8233a86bf4a2787eb6d37a54b9c8eae8a985 |
| tree | c937506b8b1ada5367bb2856674ac3728af7178e |
| parent | 77c5208c77f8e91786192dfc4e5945d40d67312a |
When running, check if Rosetta is available, otherwise, pass the
tests.4 files changed, 37 insertions(+), 7 deletions(-)
lib/std/build.zig+1-1| ... | @@ -2529,7 +2529,7 @@ pub const LibExeObjStep = struct { | ... | @@ -2529,7 +2529,7 @@ pub const LibExeObjStep = struct { |
| 2529 | } | 2529 | } |
| 2530 | } | 2530 | } |
| 2531 | } else switch (self.target.getExternalExecutor()) { | 2531 | } else switch (self.target.getExternalExecutor()) { |
| 2532 | .native, .unavailable => {}, | 2532 | .native, .rosetta, .unavailable => {}, |
| 2533 | .qemu => |bin_name| if (self.enable_qemu) qemu: { | 2533 | .qemu => |bin_name| if (self.enable_qemu) qemu: { |
| 2534 | const need_cross_glibc = self.target.isGnuLibC() and self.is_linking_libc; | 2534 | const need_cross_glibc = self.target.isGnuLibC() and self.is_linking_libc; |
| 2535 | const glibc_dir_arg = if (need_cross_glibc) | 2535 | const glibc_dir_arg = if (need_cross_glibc) |
lib/std/zig/CrossTarget.zig+6-3| ... | @@ -643,10 +643,13 @@ pub fn getExternalExecutor(self: CrossTarget) Executor { | ... | @@ -643,10 +643,13 @@ pub fn getExternalExecutor(self: CrossTarget) Executor { |
| 643 | return .native; | 643 | return .native; |
| 644 | } | 644 | } |
| 645 | } | 645 | } |
| 646 | // If the OS match and OS is macOS and CPU is arm64, treat always as native | 646 | // If the OS match and OS is macOS and CPU is arm64, we can use Rosetta 2 |
| 647 | // since we'll be running the foreign architecture tests using Rosetta2. | 647 | // to emulate the foreign architecture. |
| 648 | if (os_match and os_tag == .macos and builtin.cpu.arch == .aarch64) { | 648 | if (os_match and os_tag == .macos and builtin.cpu.arch == .aarch64) { |
| 649 | return .native; | 649 | return switch (cpu_arch) { |
| 650 | .x86_64 => .rosetta, | ||
| 651 | else => .unavailable, | ||
| 652 | }; | ||
| 650 | } | 653 | } |
| 651 | 654 | ||
| 652 | // If the OS matches, we can use QEMU to emulate a foreign architecture. | 655 | // If the OS matches, we can use QEMU to emulate a foreign architecture. |
lib/std/zig/cross_target.zig+7-3| ... | @@ -596,6 +596,7 @@ pub const CrossTarget = struct { | ... | @@ -596,6 +596,7 @@ pub const CrossTarget = struct { |
| 596 | 596 | ||
| 597 | pub const Executor = union(enum) { | 597 | pub const Executor = union(enum) { |
| 598 | native, | 598 | native, |
| 599 | rosetta, | ||
| 599 | qemu: []const u8, | 600 | qemu: []const u8, |
| 600 | wine: []const u8, | 601 | wine: []const u8, |
| 601 | wasmtime: []const u8, | 602 | wasmtime: []const u8, |
| ... | @@ -626,10 +627,13 @@ pub const CrossTarget = struct { | ... | @@ -626,10 +627,13 @@ pub const CrossTarget = struct { |
| 626 | return .native; | 627 | return .native; |
| 627 | } | 628 | } |
| 628 | } | 629 | } |
| 629 | // If the OS match and OS is macOS and CPU is arm64, treat always as native | 630 | // If the OS match and OS is macOS and CPU is arm64, we can use Rosetta 2 |
| 630 | // since we'll be running the foreign architecture tests using Rosetta2. | 631 | // to emulate the foreign architecture. |
| 631 | if (os_match and os_tag == .macos and builtin.cpu.arch == .aarch64) { | 632 | if (os_match and os_tag == .macos and builtin.cpu.arch == .aarch64) { |
| 632 | return .native; | 633 | return switch (cpu_arch) { |
| 634 | .x86_64 => .rosetta, | ||
| 635 | else => .unavailable, | ||
| 636 | }; | ||
| 633 | } | 637 | } |
| 634 | 638 | ||
| 635 | // If the OS matches, we can use QEMU to emulate a foreign architecture. | 639 | // If the OS matches, we can use QEMU to emulate a foreign architecture. |
src/test.zig+23| ... | @@ -1132,6 +1132,29 @@ pub const TestContext = struct { | ... | @@ -1132,6 +1132,29 @@ pub const TestContext = struct { |
| 1132 | .native => try argv.append(exe_path), | 1132 | .native => try argv.append(exe_path), |
| 1133 | .unavailable => return, // Pass test. | 1133 | .unavailable => return, // Pass test. |
| 1134 | 1134 | ||
| 1135 | .rosetta => if (builtin.os.tag == .macos) { | ||
| 1136 | // Check based on official Apple docs. | ||
| 1137 | // If sysctlbyname returns errno.ENOENT, then we are running a native process. | ||
| 1138 | // Otherwise, if an error occurs then we are not native and there is no Rosetta available. | ||
| 1139 | // Finally if OK, we are running a translated process via Rosetta. | ||
| 1140 | // https://developer.apple.com/documentation/apple-silicon/about-the-rosetta-translation-environment | ||
| 1141 | var ret: c_int = 0; | ||
| 1142 | var size: usize = @sizeOf(c_int); | ||
| 1143 | std.os.sysctlbynameZ( | ||
| 1144 | "sysctl.proc_translated", | ||
| 1145 | &ret, | ||
| 1146 | &size, | ||
| 1147 | null, | ||
| 1148 | 0, | ||
| 1149 | ) catch |err| switch (err) { | ||
| 1150 | error.UnknownName => unreachable, // Native process, we should never trigger it as .rosetta. | ||
| 1151 | else => return, // No Rosetta available, pass test. | ||
| 1152 | }; | ||
| 1153 | try argv.append(exe_path); | ||
| 1154 | } else { | ||
| 1155 | return; // Rosetta not available, pass test. | ||
| 1156 | }, | ||
| 1157 | |||
| 1135 | .qemu => |qemu_bin_name| if (enable_qemu) { | 1158 | .qemu => |qemu_bin_name| if (enable_qemu) { |
| 1136 | // TODO Ability for test cases to specify whether to link libc. | 1159 | // TODO Ability for test cases to specify whether to link libc. |
| 1137 | const need_cross_glibc = false; // target.isGnuLibC() and self.is_linking_libc; | 1160 | const need_cross_glibc = false; // target.isGnuLibC() and self.is_linking_libc; |