commit 5b9bb0a4045aaae387b049f4b28f350aef0dbed2 (tree)
parent e40557b1f75863d9a66af301e83c8c48f0df81d5
Author: Kendall Condon <goon.pri.low@gmail.com>
Date: Fri, 13 Feb 2026 17:50:30 -0500
add -Dfuzz-only
Runs only one configuration suitable for fuzzing.
Diffstat:
2 files changed, 29 insertions(+), 10 deletions(-)
diff --git a/build.zig b/build.zig
@@ -85,6 +85,7 @@ pub fn build(b: *std.Build) !void {
docs_step.dependOn(std_docs_step);
const no_matrix = b.option(bool, "no-matrix", "Limit test matrix to exactly one target configuration") orelse false;
+ const fuzz_only = b.option(bool, "fuzz-only", "Limit test matrix to one target suitable for fuzzing") orelse false;
const skip_debug = b.option(bool, "skip-debug", "Main test suite skips debug builds") orelse false;
const skip_release = b.option(bool, "skip-release", "Main test suite skips release builds") orelse no_matrix;
const skip_release_small = b.option(bool, "skip-release-small", "Main test suite skips release-small builds") orelse skip_release;
@@ -417,6 +418,13 @@ pub fn build(b: *std.Build) !void {
}
const optimization_modes = chosen_opt_modes_buf[0..chosen_mode_index];
+ const test_only: ?tests.ModuleTestOptions.TestOnly = if (no_matrix)
+ .default
+ else if (fuzz_only)
+ .{ .fuzz = optimize }
+ else
+ null;
+
const fmt_include_paths = &.{ "lib", "src", "test", "tools", "build.zig", "build.zig.zon" };
const fmt_exclude_paths = &.{ "test/cases", "test/behavior/zon" };
const do_fmt = b.addFmt(.{
@@ -472,7 +480,7 @@ pub fn build(b: *std.Build) !void {
.include_paths = &.{},
.skip_single_threaded = skip_single_threaded,
.skip_non_native = skip_non_native,
- .test_default_only = no_matrix,
+ .test_only = test_only,
.skip_spirv = skip_spirv,
.skip_wasm = skip_wasm,
.skip_freebsd = skip_freebsd,
@@ -497,7 +505,7 @@ pub fn build(b: *std.Build) !void {
.include_paths = &.{},
.skip_single_threaded = true,
.skip_non_native = skip_non_native,
- .test_default_only = no_matrix,
+ .test_only = test_only,
.skip_spirv = skip_spirv,
.skip_wasm = skip_wasm,
.skip_freebsd = skip_freebsd,
@@ -523,7 +531,7 @@ pub fn build(b: *std.Build) !void {
.include_paths = &.{},
.skip_single_threaded = true,
.skip_non_native = skip_non_native,
- .test_default_only = no_matrix,
+ .test_only = test_only,
.skip_spirv = skip_spirv,
.skip_wasm = skip_wasm,
.skip_freebsd = skip_freebsd,
@@ -549,7 +557,7 @@ pub fn build(b: *std.Build) !void {
.include_paths = &.{},
.skip_single_threaded = skip_single_threaded,
.skip_non_native = skip_non_native,
- .test_default_only = no_matrix,
+ .test_only = test_only,
.skip_spirv = skip_spirv,
.skip_wasm = skip_wasm,
.skip_freebsd = skip_freebsd,
diff --git a/test/tests.zig b/test/tests.zig
@@ -2310,7 +2310,7 @@ pub fn addCliTests(b: *std.Build) *Step {
return step;
}
-const ModuleTestOptions = struct {
+pub const ModuleTestOptions = struct {
test_filters: []const []const u8,
test_target_filters: []const []const u8,
test_extra_targets: bool,
@@ -2319,7 +2319,7 @@ const ModuleTestOptions = struct {
desc: []const u8,
optimize_modes: []const OptimizeMode,
include_paths: []const []const u8,
- test_default_only: bool,
+ test_only: ?TestOnly,
skip_single_threaded: bool,
skip_non_native: bool,
skip_spirv: bool,
@@ -2335,20 +2335,31 @@ const ModuleTestOptions = struct {
max_rss: usize = 0,
no_builtin: bool = false,
build_options: ?*Step.Options = null,
+
+ pub const TestOnly = union(enum) {
+ default: void,
+ fuzz: OptimizeMode,
+ };
};
pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step {
const step = b.step(b.fmt("test-{s}", .{options.name}), options.desc);
- if (options.test_default_only) {
- const test_target = &test_targets[0];
+ if (options.test_only) |test_only| {
+ const test_target: TestTarget = switch (test_only) {
+ .default => test_targets[0],
+ .fuzz => |optimize| .{
+ .optimize_mode = optimize,
+ .use_llvm = true,
+ },
+ };
const resolved_target = b.resolveTargetQuery(test_target.target);
const triple_txt = resolved_target.query.zigTriple(b.allocator) catch @panic("OOM");
addOneModuleTest(b, step, test_target, &resolved_target, triple_txt, options);
return step;
}
- for_targets: for (&test_targets) |*test_target| {
+ for_targets: for (test_targets) |test_target| {
if (test_target.skip_modules.len > 0) {
for (test_target.skip_modules) |skip_mod| {
if (std.mem.eql(u8, options.name, skip_mod)) continue :for_targets;
@@ -2425,7 +2436,7 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step {
fn addOneModuleTest(
b: *std.Build,
step: *Step,
- test_target: *const TestTarget,
+ test_target: TestTarget,
resolved_target: *const std.Build.ResolvedTarget,
triple_txt: []const u8,
options: ModuleTestOptions,