diff --git a/build.zig b/build.zig index 085201e954..5cce32b0b5 100644 --- a/build.zig +++ b/build.zig @@ -379,6 +379,8 @@ pub fn build(b: *std.Build) !void { } const test_filters = b.option([]const []const u8, "test-filter", "Skip tests that do not match any filter") orelse &[0][]const u8{}; + const test_target_filters = b.option([]const []const u8, "test-target-filter", "Skip tests whose target triple do not match any filter") orelse &[0][]const u8{}; + const test_slow_targets = b.option(bool, "test-slow-targets", "Enable running module tests for targets that have a slow compiler backend") orelse false; const test_cases_options = b.addOptions(); @@ -455,8 +457,12 @@ pub fn build(b: *std.Build) !void { }); test_step.dependOn(test_cases_step); - test_step.dependOn(tests.addModuleTests(b, .{ + const test_modules_step = b.step("test-modules", "Run the per-target module tests"); + + test_modules_step.dependOn(tests.addModuleTests(b, .{ .test_filters = test_filters, + .test_target_filters = test_target_filters, + .test_slow_targets = test_slow_targets, .root_src = "test/behavior.zig", .name = "behavior", .desc = "Run the behavior tests", @@ -468,8 +474,10 @@ pub fn build(b: *std.Build) !void { .max_rss = 1 * 1024 * 1024 * 1024, })); - test_step.dependOn(tests.addModuleTests(b, .{ + test_modules_step.dependOn(tests.addModuleTests(b, .{ .test_filters = test_filters, + .test_target_filters = test_target_filters, + .test_slow_targets = test_slow_targets, .root_src = "test/c_import.zig", .name = "c-import", .desc = "Run the @cImport tests", @@ -480,8 +488,10 @@ pub fn build(b: *std.Build) !void { .skip_libc = skip_libc, })); - test_step.dependOn(tests.addModuleTests(b, .{ + test_modules_step.dependOn(tests.addModuleTests(b, .{ .test_filters = test_filters, + .test_target_filters = test_target_filters, + .test_slow_targets = test_slow_targets, .root_src = "lib/compiler_rt.zig", .name = "compiler-rt", .desc = "Run the compiler_rt tests", @@ -493,8 +503,10 @@ pub fn build(b: *std.Build) !void { .no_builtin = true, })); - test_step.dependOn(tests.addModuleTests(b, .{ + test_modules_step.dependOn(tests.addModuleTests(b, .{ .test_filters = test_filters, + .test_target_filters = test_target_filters, + .test_slow_targets = test_slow_targets, .root_src = "lib/c.zig", .name = "universal-libc", .desc = "Run the universal libc tests", @@ -506,6 +518,24 @@ pub fn build(b: *std.Build) !void { .no_builtin = true, })); + test_modules_step.dependOn(tests.addModuleTests(b, .{ + .test_filters = test_filters, + .test_target_filters = test_target_filters, + .test_slow_targets = test_slow_targets, + .root_src = "lib/std/std.zig", + .name = "std", + .desc = "Run the standard library tests", + .optimize_modes = optimization_modes, + .include_paths = &.{}, + .skip_single_threaded = skip_single_threaded, + .skip_non_native = skip_non_native, + .skip_libc = skip_libc, + // I observed a value of 4572626944 on the M2 CI. + .max_rss = 5029889638, + })); + + test_step.dependOn(test_modules_step); + test_step.dependOn(tests.addCompareOutputTests(b, test_filters, optimization_modes)); test_step.dependOn(tests.addStandaloneTests( b, @@ -519,39 +549,25 @@ pub fn build(b: *std.Build) !void { test_step.dependOn(tests.addStackTraceTests(b, test_filters, optimization_modes)); test_step.dependOn(tests.addCliTests(b)); test_step.dependOn(tests.addAssembleAndLinkTests(b, test_filters, optimization_modes)); - test_step.dependOn(tests.addModuleTests(b, .{ - .test_filters = test_filters, - .root_src = "lib/std/std.zig", - .name = "std", - .desc = "Run the standard library tests", - .optimize_modes = optimization_modes, - .include_paths = &.{}, - .skip_single_threaded = skip_single_threaded, - .skip_non_native = skip_non_native, - .skip_libc = skip_libc, - // I observed a value of 4572626944 on the M2 CI. - .max_rss = 5029889638, - })); try addWasiUpdateStep(b, version); const update_mingw_step = b.step("update-mingw", "Update zig's bundled mingw"); const opt_mingw_src_path = b.option([]const u8, "mingw-src", "path to mingw-w64 source directory"); - const update_mingw_exe = b.addExecutable(.{ - .name = "update_mingw", - .target = b.graph.host, - .root_source_file = b.path("tools/update_mingw.zig"), - }); - const update_mingw_run = b.addRunArtifact(update_mingw_exe); - update_mingw_run.addDirectoryArg(b.path("lib")); if (opt_mingw_src_path) |mingw_src_path| { + const update_mingw_exe = b.addExecutable(.{ + .name = "update_mingw", + .target = b.graph.host, + .root_source_file = b.path("tools/update_mingw.zig"), + }); + const update_mingw_run = b.addRunArtifact(update_mingw_exe); + update_mingw_run.addDirectoryArg(b.path("lib")); update_mingw_run.addDirectoryArg(.{ .cwd_relative = mingw_src_path }); - } else { - // Intentionally cause an error if this build step is requested. - update_mingw_run.addArg("--missing-mingw-source-directory"); - } - update_mingw_step.dependOn(&update_mingw_run.step); + update_mingw_step.dependOn(&update_mingw_run.step); + } else { + update_mingw_step.dependOn(&b.addFail("The -Dmingw-src=... option is required for this step").step); + } } fn addWasiUpdateStep(b: *std.Build, version: [:0]const u8) !void { diff --git a/ci/aarch64-linux-debug.sh b/ci/aarch64-linux-debug.sh index 27effea36a..5fc0a1b6a1 100644 --- a/ci/aarch64-linux-debug.sh +++ b/ci/aarch64-linux-debug.sh @@ -62,7 +62,8 @@ stage3-debug/bin/zig build test docs \ -Dtarget=native-native-musl \ --search-prefix "$PREFIX" \ --zig-lib-dir "$PWD/../lib" \ - -Denable-tidy + -Denable-tidy \ + -Dtest-slow-targets # Ensure that updating the wasm binary from this commit will result in a viable build. stage3-debug/bin/zig build update-zig1 diff --git a/ci/aarch64-linux-release.sh b/ci/aarch64-linux-release.sh index 947694ce39..3c307a11c7 100644 --- a/ci/aarch64-linux-release.sh +++ b/ci/aarch64-linux-release.sh @@ -62,7 +62,8 @@ stage3-release/bin/zig build test docs \ -Dtarget=native-native-musl \ --search-prefix "$PREFIX" \ --zig-lib-dir "$PWD/../lib" \ - -Denable-tidy + -Denable-tidy \ + -Dtest-slow-targets # Ensure that stage3 and stage4 are byte-for-byte identical. stage3-release/bin/zig build \ diff --git a/ci/aarch64-macos-debug.sh b/ci/aarch64-macos-debug.sh index 9283321c1f..e233b00d6d 100755 --- a/ci/aarch64-macos-debug.sh +++ b/ci/aarch64-macos-debug.sh @@ -55,4 +55,5 @@ stage3-debug/bin/zig build test docs \ -Denable-macos-sdk \ -Dstatic-llvm \ -Dskip-non-native \ - --search-prefix "$PREFIX" + --search-prefix "$PREFIX" \ + -Dtest-slow-targets diff --git a/ci/aarch64-macos-release.sh b/ci/aarch64-macos-release.sh index 396aa1d464..ec3a23db18 100755 --- a/ci/aarch64-macos-release.sh +++ b/ci/aarch64-macos-release.sh @@ -55,7 +55,8 @@ stage3-release/bin/zig build test docs \ -Denable-macos-sdk \ -Dstatic-llvm \ -Dskip-non-native \ - --search-prefix "$PREFIX" + --search-prefix "$PREFIX" \ + -Dtest-slow-targets # Ensure that stage3 and stage4 are byte-for-byte identical. stage3-release/bin/zig build \ diff --git a/ci/aarch64-windows.ps1 b/ci/aarch64-windows.ps1 index bf68a6443c..a761b33604 100644 --- a/ci/aarch64-windows.ps1 +++ b/ci/aarch64-windows.ps1 @@ -67,7 +67,8 @@ Write-Output "Main test suite..." --search-prefix "$PREFIX_PATH" ` -Dstatic-llvm ` -Dskip-non-native ` - -Denable-symlinks-windows + -Denable-symlinks-windows ` + -Dtest-slow-targets CheckLastExitCode # Ensure that stage3 and stage4 are byte-for-byte identical. diff --git a/ci/x86_64-linux-debug.sh b/ci/x86_64-linux-debug.sh index 7d4a0119af..7bff35782f 100755 --- a/ci/x86_64-linux-debug.sh +++ b/ci/x86_64-linux-debug.sh @@ -70,7 +70,8 @@ stage3-debug/bin/zig build test docs \ -Dtarget=native-native-musl \ --search-prefix "$PREFIX" \ --zig-lib-dir "$PWD/../lib" \ - -Denable-tidy + -Denable-tidy \ + -Dtest-slow-targets # Ensure that updating the wasm binary from this commit will result in a viable build. stage3-debug/bin/zig build update-zig1 diff --git a/ci/x86_64-linux-release.sh b/ci/x86_64-linux-release.sh index 1ed5bca99c..85697422e5 100755 --- a/ci/x86_64-linux-release.sh +++ b/ci/x86_64-linux-release.sh @@ -70,7 +70,8 @@ stage3-release/bin/zig build test docs \ -Dtarget=native-native-musl \ --search-prefix "$PREFIX" \ --zig-lib-dir "$PWD/../lib" \ - -Denable-tidy + -Denable-tidy \ + -Dtest-slow-targets # Ensure that stage3 and stage4 are byte-for-byte identical. stage3-release/bin/zig build \ diff --git a/ci/x86_64-macos-release.sh b/ci/x86_64-macos-release.sh index acf2b91d9a..b6a0c00b22 100755 --- a/ci/x86_64-macos-release.sh +++ b/ci/x86_64-macos-release.sh @@ -59,7 +59,8 @@ stage3/bin/zig build test docs \ -Denable-macos-sdk \ -Dstatic-llvm \ -Dskip-non-native \ - --search-prefix "$PREFIX" + --search-prefix "$PREFIX" \ + -Dtest-slow-targets # Ensure that stage3 and stage4 are byte-for-byte identical. stage3/bin/zig build \ diff --git a/ci/x86_64-windows-debug.ps1 b/ci/x86_64-windows-debug.ps1 index db8be82d89..1d9c5b709b 100644 --- a/ci/x86_64-windows-debug.ps1 +++ b/ci/x86_64-windows-debug.ps1 @@ -68,7 +68,8 @@ Write-Output "Main test suite..." -Dstatic-llvm ` -Dskip-non-native ` -Dskip-release ` - -Denable-symlinks-windows + -Denable-symlinks-windows ` + -Dtest-slow-targets CheckLastExitCode Write-Output "Build x86_64-windows-msvc behavior tests using the C backend..." diff --git a/ci/x86_64-windows-release.ps1 b/ci/x86_64-windows-release.ps1 index 3d8938ce19..a2dcd06d73 100644 --- a/ci/x86_64-windows-release.ps1 +++ b/ci/x86_64-windows-release.ps1 @@ -67,7 +67,8 @@ Write-Output "Main test suite..." --search-prefix "$PREFIX_PATH" ` -Dstatic-llvm ` -Dskip-non-native ` - -Denable-symlinks-windows + -Denable-symlinks-windows ` + -Dtest-slow-targets CheckLastExitCode # Ensure that stage3 and stage4 are byte-for-byte identical. diff --git a/lib/std/zig/system.zig b/lib/std/zig/system.zig index fe3394b615..92058fbf3b 100644 --- a/lib/std/zig/system.zig +++ b/lib/std/zig/system.zig @@ -86,21 +86,37 @@ pub fn getExternalExecutor( .arm => Executor{ .qemu = "qemu-arm" }, .armeb => Executor{ .qemu = "qemu-armeb" }, .hexagon => Executor{ .qemu = "qemu-hexagon" }, - .x86 => Executor{ .qemu = "qemu-i386" }, .m68k => Executor{ .qemu = "qemu-m68k" }, .mips => Executor{ .qemu = "qemu-mips" }, .mipsel => Executor{ .qemu = "qemu-mipsel" }, - .mips64 => Executor{ .qemu = "qemu-mips64" }, - .mips64el => Executor{ .qemu = "qemu-mips64el" }, + .mips64 => Executor{ + .qemu = if (candidate.abi == .gnuabin32) + "qemu-mipsn32" + else + "qemu-mips64", + }, + .mips64el => Executor{ + .qemu = if (candidate.abi == .gnuabin32) + "qemu-mipsn32el" + else + "qemu-mips64el", + }, .powerpc => Executor{ .qemu = "qemu-ppc" }, .powerpc64 => Executor{ .qemu = "qemu-ppc64" }, .powerpc64le => Executor{ .qemu = "qemu-ppc64le" }, .riscv32 => Executor{ .qemu = "qemu-riscv32" }, .riscv64 => Executor{ .qemu = "qemu-riscv64" }, .s390x => Executor{ .qemu = "qemu-s390x" }, - .sparc => Executor{ .qemu = "qemu-sparc" }, + .sparc => Executor{ + .qemu = if (std.Target.sparc.featureSetHas(candidate.cpu.features, .v9)) + "qemu-sparc32plus" + else + "qemu-sparc", + }, .sparc64 => Executor{ .qemu = "qemu-sparc64" }, + .x86 => Executor{ .qemu = "qemu-i386" }, .x86_64 => Executor{ .qemu = "qemu-x86_64" }, + .xtensa => Executor{ .qemu = "qemu-xtensa" }, else => return bad_result, }; } diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig index 1a62e89517..fd95082428 100644 --- a/src/codegen/llvm.zig +++ b/src/codegen/llvm.zig @@ -11787,7 +11787,9 @@ fn backendSupportsF16(target: std.Target) bool { .mips64el, .s390x, => false, - .aarch64 => std.Target.aarch64.featureSetHas(target.cpu.features, .fp_armv8), + .aarch64, + .aarch64_be, + => std.Target.aarch64.featureSetHas(target.cpu.features, .fp_armv8), else => true, }; } @@ -11798,9 +11800,18 @@ fn backendSupportsF16(target: std.Target) bool { fn backendSupportsF128(target: std.Target) bool { return switch (target.cpu.arch) { .amdgcn, + .mips64, + .mips64el, .sparc, => false, - .aarch64 => std.Target.aarch64.featureSetHas(target.cpu.features, .fp_armv8), + .powerpc, + .powerpcle, + .powerpc64, + .powerpc64le, + => target.os.tag != .aix, + .aarch64, + .aarch64_be, + => std.Target.aarch64.featureSetHas(target.cpu.features, .fp_armv8), else => true, }; } diff --git a/test/tests.zig b/test/tests.zig index 1b3ef6ad74..e472fd4524 100644 --- a/test/tests.zig +++ b/test/tests.zig @@ -27,6 +27,12 @@ const TestTarget = struct { use_lld: ?bool = null, pic: ?bool = null, strip: ?bool = null, + + // This is intended for targets that are known to be slow to compile. These are acceptable to + // run in CI, but should not be run on developer machines by default. As an example, at the time + // of writing, this includes LLVM's MIPS backend which takes upwards of 20 minutes longer to + // compile tests than other backends. + slow_backend: bool = false, }; const test_targets = blk: { @@ -310,8 +316,8 @@ const test_targets = blk: { .os_tag = .linux, .abi = .none, }, + .slow_backend = true, }, - .{ .target = .{ .cpu_arch = .mips, @@ -319,17 +325,17 @@ const test_targets = blk: { .abi = .musl, }, .link_libc = true, + .slow_backend = true, + }, + .{ + .target = .{ + .cpu_arch = .mips, + .os_tag = .linux, + .abi = .gnueabihf, + }, + .link_libc = true, + .slow_backend = true, }, - - // https://github.com/ziglang/zig/issues/4927 - //.{ - // .target = .{ - // .cpu_arch = .mips, - // .os_tag = .linux, - // .abi = .gnueabihf, - // }, - // .link_libc = true, - //}, .{ .target = .{ @@ -337,8 +343,8 @@ const test_targets = blk: { .os_tag = .linux, .abi = .none, }, + .slow_backend = true, }, - .{ .target = .{ .cpu_arch = .mipsel, @@ -346,17 +352,17 @@ const test_targets = blk: { .abi = .musl, }, .link_libc = true, + .slow_backend = true, + }, + .{ + .target = .{ + .cpu_arch = .mipsel, + .os_tag = .linux, + .abi = .gnueabihf, + }, + .link_libc = true, + .slow_backend = true, }, - - // https://github.com/ziglang/zig/issues/4927 - //.{ - // .target = .{ - // .cpu_arch = .mipsel, - // .os_tag = .linux, - // .abi = .gnueabihf, - // }, - // .link_libc = true, - //}, .{ .target = .{ @@ -407,7 +413,8 @@ const test_targets = blk: { .link_libc = true, }, - // Disabled until LLVM fixes their O(N^2) codegen. + // Disabled until LLVM fixes their O(N^2) codegen. Note that this is so bad that we don't + // even want to include this in CI with `slow_backend`. // https://github.com/ziglang/zig/issues/18872 //.{ // .target = .{ @@ -418,7 +425,8 @@ const test_targets = blk: { // .use_llvm = true, //}, - // Disabled until LLVM fixes their O(N^2) codegen. + // Disabled until LLVM fixes their O(N^2) codegen. Note that this is so bad that we don't + // even want to include this in CI with `slow_backend`. // https://github.com/ziglang/zig/issues/18872 //.{ // .target = .{ @@ -971,6 +979,8 @@ pub fn addRunTranslatedCTests( const ModuleTestOptions = struct { test_filters: []const []const u8, + test_target_filters: []const []const u8, + test_slow_targets: bool, root_src: []const u8, name: []const u8, desc: []const u8, @@ -987,11 +997,20 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step { const step = b.step(b.fmt("test-{s}", .{options.name}), options.desc); for (test_targets) |test_target| { + if (!options.test_slow_targets and test_target.slow_backend) continue; + if (options.skip_non_native and !test_target.target.isNative()) continue; const resolved_target = b.resolveTargetQuery(test_target.target); const target = resolved_target.result; + const triple_txt = target.zigTriple(b.allocator) catch @panic("OOM"); + + if (options.test_target_filters.len > 0) { + for (options.test_target_filters) |filter| { + if (std.mem.indexOf(u8, triple_txt, filter) != null) break; + } else continue; + } if (options.skip_libc and test_target.link_libc == true) continue; @@ -1040,7 +1059,6 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step { if (!want_this_mode) continue; const libc_suffix = if (test_target.link_libc == true) "-libc" else ""; - const triple_txt = target.zigTriple(b.allocator) catch @panic("OOM"); const model_txt = target.cpu.model.name; // wasm32-wasi builds need more RAM, idk why