-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbuild.zig
More file actions
153 lines (123 loc) · 4.87 KB
/
build.zig
File metadata and controls
153 lines (123 loc) · 4.87 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const build_options = b.addOptions();
const exe_mod = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
const exe = b.addExecutable(.{
.name = "xtxf",
.root_module = exe_mod,
});
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},
.version = version(b),
.help_docs_config = .{
.section = '6',
},
.tab_complete_config = .{
.include_opts = true,
.add_cova_lib_msg = false,
.add_install_instructions = false,
},
});
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([]const u8, "version", version(b));
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_mod = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
const unit_tests = b.addTest(.{
.root_module = unit_tests_mod,
.use_llvm = true, //temp
});
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_mod = b.createModule(.{
.root_source_file = b.path("test/cli.zig"),
.target = target,
.optimize = optimize,
});
const integration_tests = b.addTest(.{
.root_module = integration_tests_mod,
.use_llvm = true, //temp
});
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,test" });
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.path("meta")).step);
clean_step.dependOn(&b.addRemoveDirTree(b.path("zig-out")).step);
clean_step.dependOn(&b.addRemoveDirTree(b.path(".zig-cache")).step);
}
fn version(b: *std.Build) []const u8 {
const semver = manifest.version;
const os = @tagName(builtin.target.os.tag);
var gxt = Ghext.init(std.heap.page_allocator) catch return semver;
const hash = gxt.hash(Ghext.HashLen.Short, Ghext.Worktree.Checked);
return b.fmt("{s} ({s}) {s}", .{ semver, os, hash });
}
const manifest: struct {
const Dependency = struct {
url: []const u8,
hash: []const u8,
lazy: bool = false,
};
name: enum { xtxf },
version: []const u8,
fingerprint: u64,
paths: []const []const u8,
minimum_zig_version: []const u8,
dependencies: struct {
termbox2: Dependency,
cova: Dependency,
ghext: Dependency,
},
} = @import("build.zig.zon");
const std = @import("std");
const builtin = @import("builtin");
const Ghext = @import("ghext").Ghext;