-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.zig
More file actions
133 lines (117 loc) · 4.31 KB
/
build.zig
File metadata and controls
133 lines (117 loc) · 4.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const ocispec_dep = b.dependency("ocispec", .{});
const ocispec_module = ocispec_dep.module("ocispec");
const runz_module = b.addModule("runz", .{
.root_source_file = b.path("src/lib.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "ocispec", .module = ocispec_module },
},
});
// CLI binary
const exe = b.addExecutable(.{
.name = "runz",
.root_module = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
.link_libc = true,
.imports = &.{
.{ .name = "runz", .module = runz_module },
},
}),
});
b.installArtifact(exe);
// Tests
const test_module = b.createModule(.{
.root_source_file = b.path("src/lib.zig"),
.target = target,
.optimize = optimize,
.link_libc = true,
});
test_module.addImport("ocispec", ocispec_module);
const tests = b.addTest(.{
.root_module = test_module,
});
const test_step = b.step("test", "Run unit tests");
test_step.dependOn(&b.addRunArtifact(tests).step);
// Layer 1: Library integration tests
const integration_module = b.createModule(.{
.root_source_file = b.path("tests/integration.zig"),
.target = target,
.optimize = optimize,
.link_libc = true,
});
integration_module.addImport("runz", runz_module);
const integration_tests = b.addTest(.{
.root_module = integration_module,
});
const integration_step = b.step("test-integration", "Run library integration tests");
integration_step.dependOn(&b.addRunArtifact(integration_tests).step);
// Layer 2: CLI end-to-end tests (requires built binary)
const cli_module = b.createModule(.{
.root_source_file = b.path("tests/cli.zig"),
.target = target,
.optimize = optimize,
.link_libc = true,
});
const cli_tests = b.addTest(.{
.root_module = cli_module,
});
const cli_step = b.step("test-cli", "Run CLI end-to-end tests (requires built binary)");
cli_step.dependOn(b.getInstallStep()); // ensure binary is built first
cli_step.dependOn(&b.addRunArtifact(cli_tests).step);
// Layer 3: OCI compliance tests (requires root + built binary)
const compliance_module = b.createModule(.{
.root_source_file = b.path("tests/compliance.zig"),
.target = target,
.optimize = optimize,
.link_libc = true,
});
const compliance_tests = b.addTest(.{
.root_module = compliance_module,
});
const compliance_step = b.step("test-compliance", "Run OCI compliance tests (requires root + built binary)");
compliance_step.dependOn(b.getInstallStep());
compliance_step.dependOn(&b.addRunArtifact(compliance_tests).step);
// Fuzz targets
const fuzz_module = b.createModule(.{
.root_source_file = b.path("src/fuzz.zig"),
.target = target,
.optimize = optimize,
.link_libc = true,
});
fuzz_module.addImport("ocispec", ocispec_module);
const fuzz_tests = b.addTest(.{
.root_module = fuzz_module,
});
const fuzz_step = b.step("fuzz", "Run fuzz tests (use -ffuzz to enable fuzzing mode)");
fuzz_step.dependOn(&b.addRunArtifact(fuzz_tests).step);
// Valgrind step: run tests under valgrind
const valgrind_step = b.step("valgrind", "Run tests under valgrind");
const valgrind_run = b.addSystemCommand(&.{
"valgrind",
"--leak-check=full",
"--error-exitcode=1",
"--track-origins=yes",
"--suppressions=/dev/null",
});
valgrind_run.addArtifactArg(tests);
valgrind_step.dependOn(&valgrind_run.step);
// Docs step
const docs_step = b.step("docs", "Generate API documentation");
const docs_lib = b.addLibrary(.{
.name = "runz",
.root_module = runz_module,
});
const docs_install = b.addInstallDirectory(.{
.source_dir = docs_lib.getEmittedDocs(),
.install_dir = .prefix,
.install_subdir = "docs",
});
docs_step.dependOn(&docs_install.step);
}