-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.zig
More file actions
57 lines (47 loc) · 2.04 KB
/
build.zig
File metadata and controls
57 lines (47 loc) · 2.04 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
const std = @import("std");
const deps = @import("deps.zig");
pub fn build(b: *std.build.Builder) void {
const target = b.standardTargetOptions(.{});
const mode = b.standardReleaseOptions();
const exe = b.addExecutable("wala", "src/main.zig");
const exe_tests = b.addTest("src/main.zig");
const exe_cases = b.addExecutable("cases", "test/cases.zig");
for (&[_]*std.build.LibExeObjStep{ exe, exe_tests }) |e| {
e.setTarget(target);
e.setBuildMode(mode);
e.single_threaded = true;
deps.addAllTo(e);
}
exe.install();
const fmt = b.addFmt(&[_][]const u8{ "src", "test", "build.zig" });
const fmt_step = b.step("fmt", "Format all code");
fmt_step.dependOn(&fmt.step);
const run_cmd = exe.run();
run_cmd.step.dependOn(b.getInstallStep());
if (b.args) |args| {
run_cmd.addArgs(args);
}
const run_step = b.step("run", "Run the app");
run_step.dependOn(&run_cmd.step);
const coverage = b.option(bool, "coverage", "Generate coverage with kcov") orelse false;
const kcov_args = &[_][]const u8{ "kcov", "--include-path=src", "--path-strip-level=1", b.getInstallPath(.prefix, "coverage") };
if (coverage) {
b.makePath(kcov_args[kcov_args.len - 1]) catch unreachable;
var args: [kcov_args.len + 1]?[]const u8 = undefined;
for (kcov_args) |arg, i| args[i] = arg;
// to get zig to use the --test-cmd-bin flag
args[kcov_args.len] = null;
exe_tests.setExecCmd(&args);
}
const unit_test_step = b.step("unit-test", "Run unit tests");
unit_test_step.dependOn(&exe_tests.step);
const cases_run = exe_cases.run();
if (coverage) cases_run.addArgs(kcov_args);
cases_run.addArg(b.getInstallPath(.bin, exe.name));
cases_run.step.dependOn(&exe.install_step.?.step);
const cases_step = b.step("cases-test", "Run behavioral tests");
cases_step.dependOn(&cases_run.step);
const test_step = b.step("test", "Run all tests");
test_step.dependOn(unit_test_step);
test_step.dependOn(cases_step);
}