| author | |
| committer | |
| log | 852841fd1f82bb5ba5ecdf9a85a1f15ef70e6dd0 |
| tree | 68268845bdc0cf075b0755e4213697e6309a9a25 |
| parent | 3e2f8233a86bf4a2787eb6d37a54b9c8eae8a985 |
Like QEMU or Wine, you need to declare you want Rosetta
enabled for running tests/build artifacts via `-Denable-rosetta`
flag.4 files changed, 17 insertions(+), 19 deletions(-)
build.zig+6| ... | @@ -300,6 +300,7 @@ pub fn build(b: *Builder) !void { | ... | @@ -300,6 +300,7 @@ pub fn build(b: *Builder) !void { |
| 300 | const is_qemu_enabled = b.option(bool, "enable-qemu", "Use QEMU to run cross compiled foreign architecture tests") orelse false; | 300 | const is_qemu_enabled = b.option(bool, "enable-qemu", "Use QEMU to run cross compiled foreign architecture tests") orelse false; |
| 301 | const is_wasmtime_enabled = b.option(bool, "enable-wasmtime", "Use Wasmtime to enable and run WASI libstd tests") orelse false; | 301 | const is_wasmtime_enabled = b.option(bool, "enable-wasmtime", "Use Wasmtime to enable and run WASI libstd tests") orelse false; |
| 302 | const is_darling_enabled = b.option(bool, "enable-darling", "[Experimental] Use Darling to run cross compiled macOS tests") orelse false; | 302 | const is_darling_enabled = b.option(bool, "enable-darling", "[Experimental] Use Darling to run cross compiled macOS tests") orelse false; |
| 303 | const is_rosetta_enabled = b.option(bool, "enable-rosetta", "(Darwin) Use Rosetta to run x86_64 macOS tests on arm64 macOS") orelse false; | ||
| 303 | const glibc_multi_dir = b.option([]const u8, "enable-foreign-glibc", "Provide directory with glibc installations to run cross compiled tests that link glibc"); | 304 | const glibc_multi_dir = b.option([]const u8, "enable-foreign-glibc", "Provide directory with glibc installations to run cross compiled tests that link glibc"); |
| 304 | 305 | ||
| 305 | const test_stage2_options = b.addOptions(); | 306 | const test_stage2_options = b.addOptions(); |
| ... | @@ -319,6 +320,7 @@ pub fn build(b: *Builder) !void { | ... | @@ -319,6 +320,7 @@ pub fn build(b: *Builder) !void { |
| 319 | test_stage2_options.addOption(bool, "enable_qemu", is_qemu_enabled); | 320 | test_stage2_options.addOption(bool, "enable_qemu", is_qemu_enabled); |
| 320 | test_stage2_options.addOption(bool, "enable_wine", is_wine_enabled); | 321 | test_stage2_options.addOption(bool, "enable_wine", is_wine_enabled); |
| 321 | test_stage2_options.addOption(bool, "enable_wasmtime", is_wasmtime_enabled); | 322 | test_stage2_options.addOption(bool, "enable_wasmtime", is_wasmtime_enabled); |
| 323 | test_stage2_options.addOption(bool, "enable_rosetta", is_rosetta_enabled); | ||
| 322 | test_stage2_options.addOption(u32, "mem_leak_frames", mem_leak_frames * 2); | 324 | test_stage2_options.addOption(u32, "mem_leak_frames", mem_leak_frames * 2); |
| 323 | test_stage2_options.addOption(bool, "enable_darling", is_darling_enabled); | 325 | test_stage2_options.addOption(bool, "enable_darling", is_darling_enabled); |
| 324 | test_stage2_options.addOption(?[]const u8, "glibc_multi_install_dir", glibc_multi_dir); | 326 | test_stage2_options.addOption(?[]const u8, "glibc_multi_install_dir", glibc_multi_dir); |
| ... | @@ -370,6 +372,7 @@ pub fn build(b: *Builder) !void { | ... | @@ -370,6 +372,7 @@ pub fn build(b: *Builder) !void { |
| 370 | is_qemu_enabled, | 372 | is_qemu_enabled, |
| 371 | is_wasmtime_enabled, | 373 | is_wasmtime_enabled, |
| 372 | is_darling_enabled, | 374 | is_darling_enabled, |
| 375 | is_rosetta_enabled, | ||
| 373 | glibc_multi_dir, | 376 | glibc_multi_dir, |
| 374 | )); | 377 | )); |
| 375 | 378 | ||
| ... | @@ -387,6 +390,7 @@ pub fn build(b: *Builder) !void { | ... | @@ -387,6 +390,7 @@ pub fn build(b: *Builder) !void { |
| 387 | is_qemu_enabled, | 390 | is_qemu_enabled, |
| 388 | is_wasmtime_enabled, | 391 | is_wasmtime_enabled, |
| 389 | is_darling_enabled, | 392 | is_darling_enabled, |
| 393 | is_rosetta_enabled, | ||
| 390 | glibc_multi_dir, | 394 | glibc_multi_dir, |
| 391 | )); | 395 | )); |
| 392 | 396 | ||
| ... | @@ -404,6 +408,7 @@ pub fn build(b: *Builder) !void { | ... | @@ -404,6 +408,7 @@ pub fn build(b: *Builder) !void { |
| 404 | is_qemu_enabled, | 408 | is_qemu_enabled, |
| 405 | is_wasmtime_enabled, | 409 | is_wasmtime_enabled, |
| 406 | is_darling_enabled, | 410 | is_darling_enabled, |
| 411 | is_rosetta_enabled, | ||
| 407 | glibc_multi_dir, | 412 | glibc_multi_dir, |
| 408 | )); | 413 | )); |
| 409 | 414 | ||
| ... | @@ -434,6 +439,7 @@ pub fn build(b: *Builder) !void { | ... | @@ -434,6 +439,7 @@ pub fn build(b: *Builder) !void { |
| 434 | is_qemu_enabled, | 439 | is_qemu_enabled, |
| 435 | is_wasmtime_enabled, | 440 | is_wasmtime_enabled, |
| 436 | is_darling_enabled, | 441 | is_darling_enabled, |
| 442 | is_rosetta_enabled, | ||
| 437 | glibc_multi_dir, | 443 | glibc_multi_dir, |
| 438 | ); | 444 | ); |
| 439 | 445 |
lib/std/build.zig+7-1| ... | @@ -1516,6 +1516,9 @@ pub const LibExeObjStep = struct { | ... | @@ -1516,6 +1516,9 @@ pub const LibExeObjStep = struct { |
| 1516 | /// Experimental. Uses system Darling installation to run cross compiled macOS build artifacts. | 1516 | /// Experimental. Uses system Darling installation to run cross compiled macOS build artifacts. |
| 1517 | enable_darling: bool = false, | 1517 | enable_darling: bool = false, |
| 1518 | 1518 | ||
| 1519 | /// Darwin. Uses Rosetta to run x86_64 macOS build artifacts on arm64 macOS. | ||
| 1520 | enable_rosetta: bool = false, | ||
| 1521 | |||
| 1519 | /// After following the steps in https://github.com/ziglang/zig/wiki/Updating-libc#glibc, | 1522 | /// After following the steps in https://github.com/ziglang/zig/wiki/Updating-libc#glibc, |
| 1520 | /// this will be the directory $glibc-build-dir/install/glibcs | 1523 | /// this will be the directory $glibc-build-dir/install/glibcs |
| 1521 | /// Given the example of the aarch64 target, this is the directory | 1524 | /// Given the example of the aarch64 target, this is the directory |
| ... | @@ -2529,7 +2532,10 @@ pub const LibExeObjStep = struct { | ... | @@ -2529,7 +2532,10 @@ pub const LibExeObjStep = struct { |
| 2529 | } | 2532 | } |
| 2530 | } | 2533 | } |
| 2531 | } else switch (self.target.getExternalExecutor()) { | 2534 | } else switch (self.target.getExternalExecutor()) { |
| 2532 | .native, .rosetta, .unavailable => {}, | 2535 | .native, .unavailable => {}, |
| 2536 | .rosetta => if (self.enable_rosetta) { | ||
| 2537 | try zig_args.append("--test-cmd-bin"); | ||
| 2538 | }, | ||
| 2533 | .qemu => |bin_name| if (self.enable_qemu) qemu: { | 2539 | .qemu => |bin_name| if (self.enable_qemu) qemu: { |
| 2534 | const need_cross_glibc = self.target.isGnuLibC() and self.is_linking_libc; | 2540 | const need_cross_glibc = self.target.isGnuLibC() and self.is_linking_libc; |
| 2535 | const glibc_dir_arg = if (need_cross_glibc) | 2541 | const glibc_dir_arg = if (need_cross_glibc) |
src/test.zig+2-18| ... | @@ -10,6 +10,7 @@ const enable_qemu: bool = build_options.enable_qemu; | ... | @@ -10,6 +10,7 @@ const enable_qemu: bool = build_options.enable_qemu; |
| 10 | const enable_wine: bool = build_options.enable_wine; | 10 | const enable_wine: bool = build_options.enable_wine; |
| 11 | const enable_wasmtime: bool = build_options.enable_wasmtime; | 11 | const enable_wasmtime: bool = build_options.enable_wasmtime; |
| 12 | const enable_darling: bool = build_options.enable_darling; | 12 | const enable_darling: bool = build_options.enable_darling; |
| 13 | const enable_rosetta: bool = build_options.enable_rosetta; | ||
| 13 | const glibc_multi_install_dir: ?[]const u8 = build_options.glibc_multi_install_dir; | 14 | const glibc_multi_install_dir: ?[]const u8 = build_options.glibc_multi_install_dir; |
| 14 | const skip_compile_errors = build_options.skip_compile_errors; | 15 | const skip_compile_errors = build_options.skip_compile_errors; |
| 15 | const ThreadPool = @import("ThreadPool.zig"); | 16 | const ThreadPool = @import("ThreadPool.zig"); |
| ... | @@ -1132,24 +1133,7 @@ pub const TestContext = struct { | ... | @@ -1132,24 +1133,7 @@ pub const TestContext = struct { |
| 1132 | .native => try argv.append(exe_path), | 1133 | .native => try argv.append(exe_path), |
| 1133 | .unavailable => return, // Pass test. | 1134 | .unavailable => return, // Pass test. |
| 1134 | 1135 | ||
| 1135 | .rosetta => if (builtin.os.tag == .macos) { | 1136 | .rosetta => if (enable_rosetta) { |
| 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); | 1137 | try argv.append(exe_path); |
| 1154 | } else { | 1138 | } else { |
| 1155 | return; // Rosetta not available, pass test. | 1139 | return; // Rosetta not available, pass test. |
test/tests.zig+2| ... | @@ -511,6 +511,7 @@ pub fn addPkgTests( | ... | @@ -511,6 +511,7 @@ pub fn addPkgTests( |
| 511 | is_qemu_enabled: bool, | 511 | is_qemu_enabled: bool, |
| 512 | is_wasmtime_enabled: bool, | 512 | is_wasmtime_enabled: bool, |
| 513 | is_darling_enabled: bool, | 513 | is_darling_enabled: bool, |
| 514 | is_rosetta_enabled: bool, | ||
| 514 | glibc_dir: ?[]const u8, | 515 | glibc_dir: ?[]const u8, |
| 515 | ) *build.Step { | 516 | ) *build.Step { |
| 516 | const step = b.step(b.fmt("test-{s}", .{name}), desc); | 517 | const step = b.step(b.fmt("test-{s}", .{name}), desc); |
| ... | @@ -572,6 +573,7 @@ pub fn addPkgTests( | ... | @@ -572,6 +573,7 @@ pub fn addPkgTests( |
| 572 | these_tests.enable_qemu = is_qemu_enabled; | 573 | these_tests.enable_qemu = is_qemu_enabled; |
| 573 | these_tests.enable_wasmtime = is_wasmtime_enabled; | 574 | these_tests.enable_wasmtime = is_wasmtime_enabled; |
| 574 | these_tests.enable_darling = is_darling_enabled; | 575 | these_tests.enable_darling = is_darling_enabled; |
| 576 | these_tests.enable_rosetta = is_rosetta_enabled; | ||
| 575 | these_tests.glibc_multi_install_dir = glibc_dir; | 577 | these_tests.glibc_multi_install_dir = glibc_dir; |
| 576 | these_tests.addIncludeDir("test"); | 578 | these_tests.addIncludeDir("test"); |
| 577 | 579 |