-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
build.zig
107 lines (82 loc) · 3.55 KB
/
build.zig
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
const std = @import("std");
const Ghext = @import("ghext").Ghext;
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const build_options = b.addOptions();
const exe = b.addExecutable(.{
.name = "xtxf",
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
const cova_dep = b.dependency("cova", .{
.target = target,
.optimize = optimize,
});
const cova_mod = cova_dep.module("cova");
if (target.query.cpu_arch == null) {
const cova_gen = @import("cova").addCovaDocGenStep(b, cova_dep, exe, .{
.kinds = &.{.all},
});
const meta_doc_gen = b.step("gen-doc", "Generate Meta Docs");
meta_doc_gen.dependOn(&cova_gen.step);
}
exe.addIncludePath(b.dependency("termbox2", .{}).path("."));
exe.addCSourceFile(.{ .file = b.path("src/termbox.c") });
exe.linkLibC();
exe.root_module.addImport("cova", cova_mod);
exe.root_module.addOptions("build_options", build_options);
build_options.addOption(Ghext, "gxt", try read_repo());
b.installArtifact(exe);
const run_cmd = b.addRunArtifact(exe);
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 unit_tests = b.addTest(.{
.name = "unit",
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
unit_tests.addIncludePath(b.dependency("termbox2", .{}).path("."));
unit_tests.addCSourceFile(.{ .file = b.path("src/termbox.c") });
unit_tests.linkLibC();
const test_step = b.step("test", "Run all tests");
test_step.dependOn(&b.addRunArtifact(unit_tests).step);
const test_options = b.addOptions();
const test_live = b.option(bool, "test_live", "Live integration tests") orelse false;
test_options.addOption(bool, "test_live", test_live);
test_options.addOptionPath("exe_path", exe.getEmittedBin());
const integration_tests = b.addTest(.{
.root_source_file = b.path("test/cli.zig"),
.target = target,
.optimize = optimize,
});
integration_tests.root_module.addOptions("build_options", test_options);
test_step.dependOn(&b.addRunArtifact(integration_tests).step);
const merge_step = b.addSystemCommand(&.{ "kcov", "--merge" });
merge_step.addDirectoryArg(b.path("coverage"));
merge_step.addDirectoryArg(b.path("kcov-unit"));
merge_step.addDirectoryArg(b.path("kcov-int"));
const kcov_unit = b.addSystemCommand(&.{ "kcov", "--include-path=src" });
kcov_unit.addDirectoryArg(b.path("kcov-unit"));
kcov_unit.addArtifactArg(unit_tests);
merge_step.step.dependOn(&kcov_unit.step);
const kcov_int = b.addSystemCommand(&.{ "kcov", "--include-path=src" });
kcov_int.addDirectoryArg(b.path("kcov-int"));
kcov_int.addArtifactArg(integration_tests);
merge_step.step.dependOn(&kcov_int.step);
const coverage_step = b.step("coverage", "Generate test coverage (kcov)");
coverage_step.dependOn(&merge_step.step);
const clean_step = b.step("clean", "Clean up project directory");
clean_step.dependOn(&b.addRemoveDirTree(b.pathFromRoot("zig-out")).step);
clean_step.dependOn(&b.addRemoveDirTree(b.pathFromRoot(".zig-cache")).step);
}
inline fn read_repo() !Ghext {
const gxt = Ghext.read(std.heap.page_allocator) catch unreachable;
return gxt;
}