1const std = @import("std");
 2
 3pub fn build(b: *std.Build) void {
 4    const test_step = b.step("test", "Test it");
 5    b.default_step = test_step;
 6
 7    add(b, test_step, .Debug);
 8    add(b, test_step, .ReleaseFast);
 9    add(b, test_step, .ReleaseSmall);
10    add(b, test_step, .ReleaseSafe);
11}
12
13fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {
14    const lib_a = b.addLibrary(.{
15        .linkage = .static,
16        .name = "a",
17        .root_module = b.createModule(.{
18            .root_source_file = null,
19            .optimize = optimize,
20            .target = b.graph.host,
21        }),
22    });
23    lib_a.root_module.addCSourceFiles(.{
24        .files = &.{"a.c"},
25        .flags = &.{"-fcommon"},
26    });
27
28    const test_exe = b.addTest(.{
29        .root_module = b.createModule(.{
30            .root_source_file = b.path("main.zig"),
31            .target = b.graph.host,
32            .optimize = optimize,
33        }),
34    });
35    test_exe.root_module.linkLibrary(lib_a);
36
37    test_step.dependOn(&b.addRunArtifact(test_exe).step);
38}