-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbuild.zig
More file actions
92 lines (78 loc) · 2.86 KB
/
build.zig
File metadata and controls
92 lines (78 loc) · 2.86 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
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{
.preferred_optimize_mode = .ReleaseSafe,
});
const strip = b.option(bool, "strip", "Strip debug information") orelse false;
const lto = b.option(bool, "lto", "Enable link time optimization") orelse false;
const no_bin = b.option(bool, "no-bin", "skip emitting binary for incremental compilation checks") orelse false;
//Add lmdb library for embeded key/value store
const lmdb_dep = b.dependency("lmdb", .{
.target = target,
.optimize = optimize,
});
const target_name = target.query.allocDescription(b.allocator) catch unreachable;
const exe_name = std.fmt.allocPrint(
b.allocator,
"{[program]s}-{[target]s}",
.{
.program = "recblock",
.target = target_name,
},
) catch unreachable;
const exe = b.addExecutable(.{
.name = exe_name,
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
.strip = strip,
});
exe.want_lto = lto;
const s2s_dep = b.dependency("s2s", .{
.target = target,
.optimize = optimize,
});
const s2s = s2s_dep.module("s2s");
const liblmdb = lmdb_dep.artifact("lmdb");
const lmdb = lmdb_dep.module("lmdb");
exe.root_module.addImport("s2s", s2s);
exe.root_module.addImport("mdb", lmdb);
exe.linkLibrary(liblmdb);
b.installArtifact(exe);
const check = b.addExecutable(.{
.name = "check",
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
check.root_module.addImport("s2s", s2s);
check.root_module.addImport("mdb", lmdb);
check.linkLibrary(liblmdb);
// zls with build_on_save_args = ["check", "--watch", "-fincremental"]
// for ultra fast zig error reporting using incremental compilation
const check_step = b.step("check", "Zls: Check if recblock compiles");
check_step.dependOn(&check.step);
// For use with incremental compilation checks
// zig build -Dno-bin -fincremental --watch
if (no_bin) {
b.getInstallStep().dependOn(&exe.step);
} else {
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 exe_tests = b.addTest(.{
.root_source_file = b.path("src/main.zig"),
});
exe_tests.root_module.addImport("s2s", s2s);
exe_tests.root_module.addImport("mdb", lmdb);
exe_tests.linkLibrary(liblmdb);
const test_step = b.step("test", "Run unit tests");
test_step.dependOn(&exe_tests.step);
}