test: skip non-libc module tests for targets that require or default to libc

We were just creating duplicate work and breaking -Dskip-libc.
This commit is contained in:
Alex Rønne Petersen 2026-01-15 07:55:47 +01:00
parent b1b234daa0
commit ac793232ee
No known key found for this signature in database

View file

@ -2345,27 +2345,39 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step {
}
}
const resolved_target = b.resolveTargetQuery(test_target.target);
const target = &resolved_target.result;
if (test_target.link_libc == false and target.requiresLibC()) continue;
// If the target requires libc, there's no point building the cases that
// don't explicitly link libc as they'll just end up actually linking
// libc anyway, thus creating duplicate work and making -Dskip-libc not
// work as expected.
if (test_target.link_libc == null and target.requiresLibC()) continue;
// These targets don't strictly require libc, but we don't yet have a
// syscall layer for them, so the compiler links libc by default. They
// therefore get the same treatment here.
if (test_target.link_libc == null and (target.os.tag == .freebsd or target.os.tag == .netbsd)) continue;
if (!options.test_extra_targets and test_target.extra_target) continue;
if (options.skip_non_native and !test_target.target.isNative())
continue;
if (options.skip_spirv and test_target.target.cpu_arch != null and test_target.target.cpu_arch.?.isSpirV()) continue;
if (options.skip_wasm and test_target.target.cpu_arch != null and test_target.target.cpu_arch.?.isWasm()) continue;
if (options.skip_spirv and target.cpu.arch.isSpirV()) continue;
if (options.skip_wasm and target.cpu.arch.isWasm()) continue;
if (options.skip_freebsd and test_target.target.os_tag == .freebsd) continue;
if (options.skip_netbsd and test_target.target.os_tag == .netbsd) continue;
if (options.skip_openbsd and test_target.target.os_tag == .openbsd) continue;
if (options.skip_windows and test_target.target.os_tag == .windows) continue;
if (options.skip_darwin and test_target.target.os_tag != null and test_target.target.os_tag.?.isDarwin()) continue;
if (options.skip_linux and test_target.target.os_tag == .linux) 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;
const would_use_llvm = wouldUseLlvm(test_target.use_llvm, test_target.target, test_target.optimize_mode);
if (options.skip_llvm and would_use_llvm) continue;
const resolved_target = b.resolveTargetQuery(test_target.target);
const triple_txt = resolved_target.query.zigTriple(b.allocator) catch @panic("OOM");
const target = &resolved_target.result;
if (options.test_target_filters.len > 0) {
for (options.test_target_filters) |filter| {