-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.zig
119 lines (97 loc) · 3.54 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
108
109
110
111
112
113
114
115
116
117
118
119
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const lib = b.addStaticLibrary(.{
.name = "rebeldb",
.root_source_file = b.path("src/root.zig"),
.target = target,
.optimize = optimize,
});
b.installArtifact(lib);
//
const exe = b.addExecutable(.{
.name = "rebeldb",
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
b.installArtifact(exe);
//
const zbench_dep = b.dependency("zbench", .{
.target = target,
.optimize = optimize,
});
// Add benchmark executable
const bench_exe = b.addExecutable(.{
.name = "bench",
.root_source_file = b.path("src/bench.zig"),
.target = target,
.optimize = optimize,
});
bench_exe.root_module.addImport("zbench", zbench_dep.module("zbench"));
//
const run_cmd = b.addRunArtifact(exe);
run_cmd.step.dependOn(b.getInstallStep());
// This allows the user to pass arguments to the application in the build
// command itself, like this: `zig build run -- arg1 arg2 etc`
if (b.args) |args| {
run_cmd.addArgs(args);
}
const run_step = b.step("run", "Run the app");
run_step.dependOn(&run_cmd.step);
//
const bench_cmd = b.addRunArtifact(bench_exe);
bench_cmd.step.dependOn(b.getInstallStep());
if (b.args) |args| {
bench_cmd.addArgs(args);
}
const bench_step = b.step("bench", "Run benchmarks");
bench_step.dependOn(&bench_cmd.step);
//
const lib_unit_tests = b.addTest(.{
.root_source_file = b.path("src/root.zig"),
.target = target,
.optimize = optimize,
});
const run_lib_unit_tests = b.addRunArtifact(lib_unit_tests);
const exe_unit_tests = b.addTest(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
const run_exe_unit_tests = b.addRunArtifact(exe_unit_tests);
const test_step = b.step("test", "Run unit tests");
test_step.dependOn(&run_lib_unit_tests.step);
test_step.dependOn(&run_exe_unit_tests.step);
// Add example executables
const basic_usage = b.addExecutable(.{
.name = "basic_usage",
.root_source_file = b.path("docs/examples/basic_usage.zig"),
.target = target,
.optimize = optimize,
});
basic_usage.root_module.addImport("rebeldb", &lib.root_module);
const page_config = b.addExecutable(.{
.name = "page_config",
.root_source_file = b.path("docs/examples/page_configuration.zig"),
.target = target,
.optimize = optimize,
});
page_config.root_module.addImport("rebeldb", &lib.root_module);
const mem_mgmt = b.addExecutable(.{
.name = "mem_mgmt",
.root_source_file = b.path("docs/examples/memory_management.zig"),
.target = target,
.optimize = optimize,
});
mem_mgmt.root_module.addImport("rebeldb", &lib.root_module);
// Add examples step
const examples_step = b.step("examples", "Build example executables");
const basic_usage_install = b.addInstallArtifact(basic_usage, .{});
const page_config_install = b.addInstallArtifact(page_config, .{});
const mem_mgmt_install = b.addInstallArtifact(mem_mgmt, .{});
examples_step.dependOn(&basic_usage_install.step);
examples_step.dependOn(&page_config_install.step);
examples_step.dependOn(&mem_mgmt_install.step);
}