From ceca6cca1624dbe64aef63bf9c29efa91ec93feb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Sun, 30 Aug 2026 08:43:56 +0200 Subject: [PATCH 1/2] test-incremental: respect -Dskip-non-native and other similar options --- build.zig | 14 ++++++- test/tests.zig | 101 +++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 98 insertions(+), 17 deletions(-) diff --git a/build.zig b/build.zig index 2e6439b66003c8c575c34365aeb69e1e1e0c04a7..f159572db55f699336919125c99678db47389fe4 100644 --- a/build.zig +++ b/build.zig @@ -772,7 +772,19 @@ pub fn build(b: *std.Build) !void { } const test_incremental_step = b.step("test-incremental", "Run the incremental compilation test cases"); - try tests.addIncrementalTests(b, test_incremental_step, test_filters, test_target_filters); + try tests.addIncrementalTests(b, test_incremental_step, .{ + .test_filters = test_filters, + .test_target_filters = test_target_filters, + .skip_non_native = skip_non_native, + .skip_wasm = skip_wasm, + .skip_freebsd = skip_freebsd, + .skip_netbsd = skip_netbsd, + .skip_openbsd = skip_openbsd, + .skip_windows = skip_windows, + .skip_darwin = skip_darwin, + .skip_linux = skip_linux, + .skip_llvm = skip_llvm, + }); if (!skip_test_incremental) test_step.dependOn(test_incremental_step); if (tests.addLibcTestNszTests(b, .{ diff --git a/test/tests.zig b/test/tests.zig index 2ebb7447a4a184fef81b3ec1e9931a9f8adbb74b..d9ddb99d3826a43a591740fd3a3355d2e369f3af 100644 --- a/test/tests.zig +++ b/test/tests.zig @@ -2250,23 +2250,57 @@ const link_targets = blk: { }; }; -/// Unlike `test_targets` and `c_abi_targets`, these targets are just simple strings which we pass -/// directly to `incr-check`. They include the target triple and the compiler backend. +const IncrementalTarget = struct { + target: std.Target.Query, + backend: enum { selfhosted, llvm, cbe }, +}; + +/// These are passed to `incr-check` as `-` strings. /// /// If only one specific test is failing on a target, instead of entirely disabling the target here, /// you can skip the target for that specific test only by adding a line like this to the manifest: /// #skip_target=x86_64-linux-selfhosted -const incremental_targets: []const []const u8 = &.{ +const incremental_targets = &[_]IncrementalTarget{ // Avoid adding more CBE or LLVM targets without good reason: they're a lot slower than others // to run due to the output (C source code or LLVM IR) being built non-incrementally (by Clang // or LLVM). We just have a couple here to make sure that it works. - "x86_64-linux-cbe", - "x86_64-linux-llvm", + .{ + .target = .{ + .cpu_arch = .x86_64, + .os_tag = .linux, + }, + .backend = .cbe, + }, + .{ + .target = .{ + .cpu_arch = .x86_64, + .os_tag = .linux, + }, + .backend = .llvm, + }, - "x86_64-linux-selfhosted", + .{ + .target = .{ + .cpu_arch = .x86_64, + .os_tag = .linux, + }, + .backend = .selfhosted, + }, // https://codeberg.org/ziglang/zig/issues/31773 - //"x86_64-windows-selfhosted", - "wasm32-wasi-selfhosted", + // .{ + // .target = .{ + // .cpu_arch = .x86_64, + // .os_tag = .windows, + // }, + // .backend = .selfhosted, + // }, + .{ + .target = .{ + .cpu_arch = .wasm32, + .os_tag = .wasi, + }, + .backend = .selfhosted, + }, }; fn compatible32bitArch(host: *const std.Target) ?std.Target.Cpu.Arch { @@ -3290,11 +3324,24 @@ pub fn addDebuggerTests(b: *std.Build, options: DebuggerContext.Options) ?*Step return step; } +const IncrementalTestOptions = struct { + test_filters: []const []const u8, + test_target_filters: []const []const u8, + skip_non_native: bool, + skip_wasm: bool, + skip_freebsd: bool, + skip_netbsd: bool, + skip_openbsd: bool, + skip_windows: bool, + skip_darwin: bool, + skip_linux: bool, + skip_llvm: bool, +}; + pub fn addIncrementalTests( b: *std.Build, test_step: *Step, - test_filters: []const []const u8, - test_target_filters: []const []const u8, + options: IncrementalTestOptions, ) !void { const io = b.graph.io; @@ -3316,9 +3363,9 @@ pub fn addIncrementalTests( while (try it.next(io)) |entry| { if (std.mem.endsWith(u8, entry.basename, ".swp")) continue; - for (test_filters) |test_filter| { + for (options.test_filters) |test_filter| { if (std.mem.find(u8, entry.path, test_filter)) |_| break; - } else if (test_filters.len > 0) continue; + } else if (options.test_filters.len > 0) continue; switch (entry.kind) { .file => {}, @@ -3329,13 +3376,35 @@ pub fn addIncrementalTests( } b.dependOnFileContents(b.path(b.pathJoin(&.{ "test", "incremental", entry.path }))); - for (incremental_targets) |target_str| { - if (test_target_filters.len > 0) { - for (test_target_filters) |filter| { - if (std.mem.find(u8, target_str, filter) != null) break; + for (incremental_targets) |test_target| { + const resolved_target = b.resolveTargetQuery(test_target.target); + + if (options.skip_non_native and !isNative(&resolved_target, &b.graph.host.result)) + continue; + + const target = &resolved_target.result; + + if (options.skip_wasm and target.cpu.arch.isWasm()) continue; + + if (options.skip_freebsd and target.os.tag == .freebsd) continue; + if (options.skip_netbsd and target.os.tag == .netbsd) continue; + if (options.skip_openbsd and target.os.tag == .openbsd) continue; + if (options.skip_windows and target.os.tag == .windows) continue; + if (options.skip_darwin and target.os.tag.isDarwin()) continue; + if (options.skip_linux and target.os.tag == .linux) continue; + + if (options.skip_llvm and test_target.backend == .llvm) continue; + + const triple_txt = resolved_target.query.zigTriple(b.allocator) catch @panic("OOM"); + + if (options.test_target_filters.len > 0) { + for (options.test_target_filters) |filter| { + if (std.mem.find(u8, triple_txt, filter) != null) break; } else continue; } + const target_str = b.fmt("{s}-{t}", .{ triple_txt, test_target.backend }); + const run = b.addRunArtifact(incr_check); run.setName(b.fmt("incr-check {s} '{s}'", .{ target_str, entry.basename })); -- 2.54.0 From 6534993573f184c78733ab5a05c61b4860c71d87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Sun, 30 Aug 2026 09:00:59 +0200 Subject: [PATCH 2/2] test-link: respect various skip options properly Also use the smarter isNative() function. --- build.zig | 6 ++++++ test/tests.zig | 31 ++++++++++++++++++++++++++----- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/build.zig b/build.zig index f159572db55f699336919125c99678db47389fe4..cc95846296692b8115195ac9f599ab93e4961263 100644 --- a/build.zig +++ b/build.zig @@ -656,8 +656,14 @@ pub fn build(b: *std.Build) !void { .test_filters = test_filters, .optimize_modes = optimize_modes, .skip_non_native = skip_non_native, + .skip_freebsd = skip_freebsd, + .skip_netbsd = skip_netbsd, + .skip_openbsd = skip_openbsd, .skip_windows = skip_windows, + .skip_darwin = skip_darwin, + .skip_linux = skip_linux, .skip_llvm = skip_llvm, + .skip_libc = skip_libc, .max_rss = 100_000_000, })); test_step.dependOn(tests.addStackTraceTests(b, .{ diff --git a/test/tests.zig b/test/tests.zig index d9ddb99d3826a43a591740fd3a3355d2e369f3af..41e54a82fc7020b6b728f1a6ade49592c1332d9a 100644 --- a/test/tests.zig +++ b/test/tests.zig @@ -3198,8 +3198,14 @@ const LinkTestOptions = struct { test_filters: []const []const u8, optimize_modes: []const OptimizeMode, skip_non_native: bool, + skip_freebsd: bool, + skip_netbsd: bool, + skip_openbsd: bool, skip_windows: bool, + skip_darwin: bool, + skip_linux: bool, skip_llvm: bool, + skip_libc: bool, max_rss: usize, }; @@ -3212,22 +3218,37 @@ pub fn addLinkTests(b: *std.Build, options: LinkTestOptions) *Step { ) orelse false; for (link_targets) |link_target| { - if (options.skip_non_native and !link_target.target.isNative()) continue; - if (options.skip_windows and link_target.target.os_tag == .windows) continue; - const resolved_target = b.resolveTargetQuery(link_target.target); - const triple_txt = resolved_target.query.zigTriple(b.allocator) catch @panic("OOM"); + + if (options.skip_non_native and !isNative(&resolved_target, &b.graph.host.result)) + continue; + const target = &resolved_target.result; + if (options.skip_freebsd and target.os.tag == .freebsd) continue; + if (options.skip_netbsd and target.os.tag == .netbsd) continue; + if (options.skip_openbsd and target.os.tag == .openbsd) continue; + if (options.skip_windows and target.os.tag == .windows) continue; + if (options.skip_darwin and target.os.tag.isDarwin()) continue; + if (options.skip_linux and target.os.tag == .linux) continue; + + const triple_txt = resolved_target.query.zigTriple(b.allocator) catch @panic("OOM"); + if (options.test_target_filters.len > 0) { for (options.test_target_filters) |filter| { if (std.mem.find(u8, triple_txt, filter) != null) break; } else continue; } + if (options.skip_libc and (link_target.link_libc == true or std.os.targetRequiresLibC(target))) + continue; + + // We can't provide MSVC libc when cross-compiling. + if (target.abi == .msvc and link_target.link_libc == true and builtin.os.tag != .windows) + continue; + for (options.optimize_modes) |optimize_mode| { if (link_target.optimize_mode != optimize_mode) continue; - if (link_target.link_libc and target.abi == .msvc and b.graph.host.result.os.tag != .windows) continue; const would_use_llvm = wouldUseLlvm(link_target.use_llvm, link_target.target, optimize_mode); if (options.skip_llvm and would_use_llvm) continue; -- 2.54.0