master
 1const std = @import("std");
 2const builtin = @import("builtin");
 3
 4pub fn build(b: *std.Build) !void {
 5    const test_step = b.step("test", "Test it");
 6    b.default_step = test_step;
 7
 8    const optimize: std.builtin.OptimizeMode = .Debug;
 9    const target = b.graph.host;
10
11    if (builtin.os.tag != .windows) return;
12
13    const echo_args = b.addExecutable(.{
14        .name = "echo-args",
15        .root_module = b.createModule(.{
16            .root_source_file = b.path("echo-args.zig"),
17            .optimize = optimize,
18            .target = target,
19        }),
20    });
21
22    const test_exe = b.addExecutable(.{
23        .name = "test",
24        .root_module = b.createModule(.{
25            .root_source_file = b.path("test.zig"),
26            .optimize = optimize,
27            .target = target,
28        }),
29    });
30
31    const run = b.addRunArtifact(test_exe);
32    run.addArtifactArg(echo_args);
33    run.expectExitCode(0);
34    run.skip_foreign_checks = true;
35
36    test_step.dependOn(&run.step);
37
38    const fuzz = b.addExecutable(.{
39        .name = "fuzz",
40        .root_module = b.createModule(.{
41            .root_source_file = b.path("fuzz.zig"),
42            .optimize = optimize,
43            .target = target,
44        }),
45    });
46
47    const fuzz_max_iterations = b.option(u64, "iterations", "The max fuzz iterations (default: 100)") orelse 100;
48    const fuzz_iterations_arg = std.fmt.allocPrint(b.allocator, "{}", .{fuzz_max_iterations}) catch @panic("oom");
49
50    const fuzz_seed = b.option(u64, "seed", "Seed to use for the PRNG (default: random)") orelse seed: {
51        var buf: [8]u8 = undefined;
52        try std.posix.getrandom(&buf);
53        break :seed std.mem.readInt(u64, &buf, builtin.cpu.arch.endian());
54    };
55    const fuzz_seed_arg = std.fmt.allocPrint(b.allocator, "{}", .{fuzz_seed}) catch @panic("oom");
56
57    const fuzz_run = b.addRunArtifact(fuzz);
58    fuzz_run.addArtifactArg(echo_args);
59    fuzz_run.addArgs(&.{ fuzz_iterations_arg, fuzz_seed_arg });
60    fuzz_run.expectExitCode(0);
61    fuzz_run.skip_foreign_checks = true;
62
63    test_step.dependOn(&fuzz_run.step);
64}