commit a3e81984779b9848c02b88d56ebd6d916fcfe8ce (tree)
parent d6e65fe565e475b1e8f5c9ecf0ada5ffa87ac9f6
Author: Motiejus Jakštys <motiejus@jakstys.lt>
Date: Wed, 11 Feb 2026 18:27:44 +0000
valgrind
Diffstat:
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/build.zig b/build.zig
@@ -44,9 +44,10 @@ pub fn build(b: *std.Build) !void {
const cc = b.option([]const u8, "cc", "C compiler") orelse "zig";
const no_exec = b.option(bool, "no-exec", "Compile test binary without running it") orelse false;
+ const valgrind = b.option(bool, "valgrind", "Run tests under valgrind") orelse false;
const test_step = b.step("test", "Run unit tests");
- addTestStep(b, test_step, target, optimize, cc, no_exec);
+ addTestStep(b, test_step, target, optimize, cc, no_exec, valgrind);
const fmt_step = b.step("fmt", "clang-format");
const clang_format = b.addSystemCommand(&.{ "clang-format", "-i" });
@@ -102,7 +103,7 @@ pub fn build(b: *std.Build) !void {
all_step.dependOn(&fmt_check.step);
for (compilers) |compiler| {
- addTestStep(b, all_step, target, optimize, compiler, false);
+ addTestStep(b, all_step, target, optimize, compiler, false, valgrind);
}
b.default_step = all_step;
@@ -115,6 +116,7 @@ fn addTestStep(
optimize: std.builtin.OptimizeMode,
cc: []const u8,
no_exec: bool,
+ valgrind: bool,
) void {
const test_mod = b.createModule(.{
.root_source_file = b.path("test_all.zig"),
@@ -144,6 +146,13 @@ fn addTestStep(
}
const test_exe = b.addTest(.{ .root_module = test_mod });
+ if (valgrind) {
+ test_exe.setExecCmd(&.{
+ "valgrind",
+ "--error-exitcode=2",
+ null,
+ });
+ }
if (no_exec) {
const install = b.addInstallArtifact(test_exe, .{});
step.dependOn(&install.step);