aboutsummaryrefslogtreecommitdiffstats
path: root/build.zig
diff options
context:
space:
mode:
authorsadbeast <sadbeast@sadbeast.com>2024-04-15 18:08:28 -0700
committersadbeast <sadbeast@sadbeast.com>2024-05-18 17:23:35 -0700
commita4711cad923d6c7480e596685d9dcaefa241fe3b (patch)
treef0c36edea9b32b8a1825270436868bb020689657 /build.zig
downloadtmz-a4711cad923d6c7480e596685d9dcaefa241fe3b.tar.gz
tmz-a4711cad923d6c7480e596685d9dcaefa241fe3b.tar.bz2
initial mistakeHEADmain
Diffstat (limited to 'build.zig')
-rw-r--r--build.zig57
1 files changed, 57 insertions, 0 deletions
diff --git a/build.zig b/build.zig
new file mode 100644
index 0000000..15e51a4
--- /dev/null
+++ b/build.zig
@@ -0,0 +1,57 @@
+const std = @import("std");
+
+pub fn build(b: *std.Build) void {
+ const target = b.standardTargetOptions(.{});
+
+ const optimize = b.standardOptimizeOption(.{});
+
+ const root_source_file = b.path("src/tmz.zig");
+
+ _ = b.addModule("tmz", .{ .root_source_file = root_source_file });
+
+ const tests = b.addTest(.{
+ .root_source_file = root_source_file,
+ .target = target,
+ .optimize = optimize,
+ });
+
+ const test_step = b.step("test", "Run unit tests");
+ test_step.dependOn(&b.addRunArtifact(tests).step);
+
+ const coverage = b.option(bool, "cover", "Generate test coverage") orelse false;
+
+ if (coverage) {
+ const coverage_output_dir = b.makeTempPath();
+
+ const args = &[_]std.Build.Step.Run.Arg{
+ .{ .bytes = b.dupe("kcov") },
+ .{ .bytes = b.dupe("--collect-only") },
+ .{ .bytes = b.dupe("--include-pattern=src/") },
+ .{ .bytes = b.dupe("--exclude-pattern=_test") },
+ .{ .bytes = b.dupe(coverage_output_dir) },
+ };
+
+ const tests_run = b.addRunArtifact(tests);
+ tests_run.has_side_effects = true;
+
+ tests_run.argv.insertSlice(0, args) catch @panic("OOM");
+
+ const merge_step = std.Build.Step.Run.create(b, "merge kcov");
+ merge_step.has_side_effects = true;
+ merge_step.addArgs(&.{
+ "kcov",
+ "--merge",
+ b.pathJoin(&.{ coverage_output_dir, "output" }),
+ b.pathJoin(&.{ coverage_output_dir, "test" }),
+ });
+ merge_step.step.dependOn(&tests_run.step);
+
+ const install_coverage = b.addInstallDirectory(.{
+ .source_dir = .{ .cwd_relative = b.pathJoin(&.{ coverage_output_dir, "output" }) },
+ .install_dir = .{ .custom = "coverage" },
+ .install_subdir = "",
+ });
+ install_coverage.step.dependOn(&merge_step.step);
+ test_step.dependOn(&install_coverage.step);
+ }
+}