| author | |
| committer | |
| log | 14b532ec8596d7f84b76127f1b858271f010126f |
| tree | 1e05b622760b5288bba853c575daa2d048a10403 |
| parent | 1912ec0323af9a9077a8706157beb8207f6e3eb9 |
| parent | 42db5156656ebd1649f7ec3707697b08657b9cab |
| signature |
Treat x86_64 tests as native under the Rosetta 2 on M1 Macs6 files changed, 43 insertions(+), 2 deletions(-)
build.zig+6| ... | ... | @@ -300,6 +300,7 @@ pub fn build(b: *Builder) !void { |
| 300 | 300 | const is_qemu_enabled = b.option(bool, "enable-qemu", "Use QEMU to run cross compiled foreign architecture tests") orelse false; |
| 301 | 301 | const is_wasmtime_enabled = b.option(bool, "enable-wasmtime", "Use Wasmtime to enable and run WASI libstd tests") orelse false; |
| 302 | 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 | 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 | 306 | const test_stage2_options = b.addOptions(); |
| ... | ... | @@ -319,6 +320,7 @@ pub fn build(b: *Builder) !void { |
| 319 | 320 | test_stage2_options.addOption(bool, "enable_qemu", is_qemu_enabled); |
| 320 | 321 | test_stage2_options.addOption(bool, "enable_wine", is_wine_enabled); |
| 321 | 322 | test_stage2_options.addOption(bool, "enable_wasmtime", is_wasmtime_enabled); |
| 323 | test_stage2_options.addOption(bool, "enable_rosetta", is_rosetta_enabled); | |
| 322 | 324 | test_stage2_options.addOption(u32, "mem_leak_frames", mem_leak_frames * 2); |
| 323 | 325 | test_stage2_options.addOption(bool, "enable_darling", is_darling_enabled); |
| 324 | 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 | 372 | is_qemu_enabled, |
| 371 | 373 | is_wasmtime_enabled, |
| 372 | 374 | is_darling_enabled, |
| 375 | is_rosetta_enabled, | |
| 373 | 376 | glibc_multi_dir, |
| 374 | 377 | )); |
| 375 | 378 | |
| ... | ... | @@ -387,6 +390,7 @@ pub fn build(b: *Builder) !void { |
| 387 | 390 | is_qemu_enabled, |
| 388 | 391 | is_wasmtime_enabled, |
| 389 | 392 | is_darling_enabled, |
| 393 | is_rosetta_enabled, | |
| 390 | 394 | glibc_multi_dir, |
| 391 | 395 | )); |
| 392 | 396 | |
| ... | ... | @@ -404,6 +408,7 @@ pub fn build(b: *Builder) !void { |
| 404 | 408 | is_qemu_enabled, |
| 405 | 409 | is_wasmtime_enabled, |
| 406 | 410 | is_darling_enabled, |
| 411 | is_rosetta_enabled, | |
| 407 | 412 | glibc_multi_dir, |
| 408 | 413 | )); |
| 409 | 414 | |
| ... | ... | @@ -434,6 +439,7 @@ pub fn build(b: *Builder) !void { |
| 434 | 439 | is_qemu_enabled, |
| 435 | 440 | is_wasmtime_enabled, |
| 436 | 441 | is_darling_enabled, |
| 442 | is_rosetta_enabled, | |
| 437 | 443 | glibc_multi_dir, |
| 438 | 444 | ); |
| 439 | 445 |
lib/std/build.zig+6| ... | ... | @@ -1516,6 +1516,9 @@ pub const LibExeObjStep = struct { |
| 1516 | 1516 | /// Experimental. Uses system Darling installation to run cross compiled macOS build artifacts. |
| 1517 | 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 | 1522 | /// After following the steps in https://github.com/ziglang/zig/wiki/Updating-libc#glibc, |
| 1520 | 1523 | /// this will be the directory $glibc-build-dir/install/glibcs |
| 1521 | 1524 | /// Given the example of the aarch64 target, this is the directory |
| ... | ... | @@ -2530,6 +2533,9 @@ pub const LibExeObjStep = struct { |
| 2530 | 2533 | } |
| 2531 | 2534 | } else switch (self.target.getExternalExecutor()) { |
| 2532 | 2535 | .native, .unavailable => {}, |
| 2536 | .rosetta => if (self.enable_rosetta) { | |
| 2537 | try zig_args.append("--test-cmd-bin"); | |
| 2538 | }, | |
| 2533 | 2539 | .qemu => |bin_name| if (self.enable_qemu) qemu: { |
| 2534 | 2540 | const need_cross_glibc = self.target.isGnuLibC() and self.is_linking_libc; |
| 2535 | 2541 | const glibc_dir_arg = if (need_cross_glibc) |
lib/std/zig/CrossTarget.zig+9| ... | ... | @@ -612,6 +612,7 @@ pub fn vcpkgTriplet(self: CrossTarget, allocator: mem.Allocator, linkage: VcpkgL |
| 612 | 612 | |
| 613 | 613 | pub const Executor = union(enum) { |
| 614 | 614 | native, |
| 615 | rosetta, | |
| 615 | 616 | qemu: []const u8, |
| 616 | 617 | wine: []const u8, |
| 617 | 618 | wasmtime: []const u8, |
| ... | ... | @@ -642,6 +643,14 @@ pub fn getExternalExecutor(self: CrossTarget) Executor { |
| 642 | 643 | return .native; |
| 643 | 644 | } |
| 644 | 645 | } |
| 646 | // If the OS match and OS is macOS and CPU is arm64, we can use Rosetta 2 | |
| 647 | // to emulate the foreign architecture. | |
| 648 | if (os_match and os_tag == .macos and builtin.cpu.arch == .aarch64) { | |
| 649 | return switch (cpu_arch) { | |
| 650 | .x86_64 => .rosetta, | |
| 651 | else => .unavailable, | |
| 652 | }; | |
| 653 | } | |
| 645 | 654 | |
| 646 | 655 | // If the OS matches, we can use QEMU to emulate a foreign architecture. |
| 647 | 656 | if (os_match) { |
src/test.zig+7| ... | ... | @@ -10,6 +10,7 @@ const enable_qemu: bool = build_options.enable_qemu; |
| 10 | 10 | const enable_wine: bool = build_options.enable_wine; |
| 11 | 11 | const enable_wasmtime: bool = build_options.enable_wasmtime; |
| 12 | 12 | const enable_darling: bool = build_options.enable_darling; |
| 13 | const enable_rosetta: bool = build_options.enable_rosetta; | |
| 13 | 14 | const glibc_multi_install_dir: ?[]const u8 = build_options.glibc_multi_install_dir; |
| 14 | 15 | const skip_compile_errors = build_options.skip_compile_errors; |
| 15 | 16 | const ThreadPool = @import("ThreadPool.zig"); |
| ... | ... | @@ -1132,6 +1133,12 @@ pub const TestContext = struct { |
| 1132 | 1133 | .native => try argv.append(exe_path), |
| 1133 | 1134 | .unavailable => return, // Pass test. |
| 1134 | 1135 | |
| 1136 | .rosetta => if (enable_rosetta) { | |
| 1137 | try argv.append(exe_path); | |
| 1138 | } else { | |
| 1139 | return; // Rosetta not available, pass test. | |
| 1140 | }, | |
| 1141 | ||
| 1135 | 1142 | .qemu => |qemu_bin_name| if (enable_qemu) { |
| 1136 | 1143 | // TODO Ability for test cases to specify whether to link libc. |
| 1137 | 1144 | const need_cross_glibc = false; // target.isGnuLibC() and self.is_linking_libc; |
test/behavior/muladd.zig+5| ... | ... | @@ -1,3 +1,4 @@ |
| 1 | const builtin = @import("builtin"); | |
| 1 | 2 | const expect = @import("std").testing.expect; |
| 2 | 3 | |
| 3 | 4 | test "@mulAdd" { |
| ... | ... | @@ -24,6 +25,10 @@ fn testMulAdd() !void { |
| 24 | 25 | var c: f64 = 6.25; |
| 25 | 26 | try expect(@mulAdd(f64, a, b, c) == 20); |
| 26 | 27 | } |
| 28 | if (builtin.os.tag == .macos and builtin.cpu.arch == .aarch64) { | |
| 29 | // https://github.com/ziglang/zig/issues/9900 | |
| 30 | return error.SkipZigTest; | |
| 31 | } | |
| 27 | 32 | { |
| 28 | 33 | var a: f16 = 5.5; |
| 29 | 34 | var b: f128 = 2.5; |
test/tests.zig+10-2| ... | ... | @@ -270,8 +270,14 @@ const test_targets = blk: { |
| 270 | 270 | .os_tag = .macos, |
| 271 | 271 | .abi = .gnu, |
| 272 | 272 | }, |
| 273 | // https://github.com/ziglang/zig/issues/3295 | |
| 274 | .disable_native = true, | |
| 273 | }, | |
| 274 | ||
| 275 | TestTarget{ | |
| 276 | .target = .{ | |
| 277 | .cpu_arch = .aarch64, | |
| 278 | .os_tag = .macos, | |
| 279 | .abi = .gnu, | |
| 280 | }, | |
| 275 | 281 | }, |
| 276 | 282 | |
| 277 | 283 | TestTarget{ |
| ... | ... | @@ -511,6 +517,7 @@ pub fn addPkgTests( |
| 511 | 517 | is_qemu_enabled: bool, |
| 512 | 518 | is_wasmtime_enabled: bool, |
| 513 | 519 | is_darling_enabled: bool, |
| 520 | is_rosetta_enabled: bool, | |
| 514 | 521 | glibc_dir: ?[]const u8, |
| 515 | 522 | ) *build.Step { |
| 516 | 523 | const step = b.step(b.fmt("test-{s}", .{name}), desc); |
| ... | ... | @@ -572,6 +579,7 @@ pub fn addPkgTests( |
| 572 | 579 | these_tests.enable_qemu = is_qemu_enabled; |
| 573 | 580 | these_tests.enable_wasmtime = is_wasmtime_enabled; |
| 574 | 581 | these_tests.enable_darling = is_darling_enabled; |
| 582 | these_tests.enable_rosetta = is_rosetta_enabled; | |
| 575 | 583 | these_tests.glibc_multi_install_dir = glibc_dir; |
| 576 | 584 | these_tests.addIncludeDir("test"); |
| 577 | 585 |