master
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.addCSourceFile(.{ .file = b.path("a.c"), .flags = &[_][]const u8{} });
24 lib_a.root_module.addIncludePath(b.path("."));
25
26 const lib_b = b.addLibrary(.{
27 .linkage = .static,
28 .name = "b",
29 .root_module = b.createModule(.{
30 .root_source_file = null,
31 .optimize = optimize,
32 .target = b.graph.host,
33 }),
34 });
35 lib_b.root_module.addCSourceFile(.{ .file = b.path("b.c"), .flags = &[_][]const u8{} });
36 lib_b.root_module.addIncludePath(b.path("."));
37
38 const test_exe = b.addTest(.{
39 .root_module = b.createModule(.{
40 .root_source_file = b.path("main.zig"),
41 .target = b.graph.host,
42 .optimize = optimize,
43 }),
44 });
45 test_exe.root_module.linkLibrary(lib_a);
46 test_exe.root_module.linkLibrary(lib_b);
47 test_exe.root_module.addIncludePath(b.path("."));
48
49 test_step.dependOn(&b.addRunArtifact(test_exe).step);
50}