-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.zig
More file actions
128 lines (109 loc) · 4.24 KB
/
Copy pathbuild.zig
File metadata and controls
128 lines (109 loc) · 4.24 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
const std = @import("std");
const version = @import("build.zig.zon").version;
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const mod_sqlite = b.dependency("sqlite", .{
.target = target,
.optimize = optimize,
}).module("sqlite");
const module = b.addModule("zcode", .{
.root_source_file = b.path("src/root.zig"),
.target = target,
.imports = &.{
.{ .name = "sqlite", .module = mod_sqlite },
},
});
const exe = b.addExecutable(.{
.name = "zcode",
.root_module = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "zcode", .module = module },
.{ .name = "sqlite", .module = mod_sqlite },
},
}),
});
const log_level: std.log.Level = blk: {
if (b.option(
std.log.Level,
"log-level",
"Override log level (debug, info, warn, err). " ++
"Default: debug in Debug mode, info in ReleaseSafe, err in ReleaseFast/ReleaseSmall.",
)) |level| break :blk level;
break :blk switch (optimize) {
.Debug => std.log.Level.debug,
.ReleaseSafe => std.log.Level.info,
.ReleaseFast, .ReleaseSmall => std.log.Level.err,
};
};
const build_opts = b.addOptions();
build_opts.addOption(std.log.Level, "log_level", log_level);
exe.root_module.addImport("build_options", build_opts.createModule());
const version_opts = b.addOptions();
version_opts.addOption([]const u8, "version", version);
exe.root_module.addImport("version", version_opts.createModule());
b.installArtifact(exe);
const run_cmd = b.addRunArtifact(exe);
b.step("run", "Run the app").dependOn(&run_cmd.step);
run_cmd.step.dependOn(b.getInstallStep());
if (b.args) |args| run_cmd.addArgs(args);
// Custom test runner enables std.log.debug output during tests.
// Default: on. Use -Ddebug-test-log=false to use the standard test runner.
const debug_test_log = b.option(
bool,
"debug-test-log",
"Enable std.log.debug output in tests via custom test runner. " ++
"Default: true (debug logs visible). Use -Ddebug-test-log=false to restore " ++
"the standard test runner behaviour (only warn/err visible).",
) orelse true;
const test_runner_opt: ?std.Build.Step.Compile.TestRunner = if (debug_test_log)
.{ .path = b.path("test_runner.zig"), .mode = .server }
else
null;
const mod_tests = b.addTest(.{
.root_module = module,
.test_runner = test_runner_opt,
});
const run_mod_tests = b.addRunArtifact(mod_tests);
const exe_tests = b.addTest(.{
.root_module = exe.root_module,
.test_runner = test_runner_opt,
});
const run_exe_tests = b.addRunArtifact(exe_tests);
const test_step = b.step("test", "Run tests");
test_step.dependOn(&run_mod_tests.step);
test_step.dependOn(&run_exe_tests.step);
const example_step = b.step("examples", "Build examples");
for ([_][]const u8{
"help",
"io",
"json",
"time",
"uuid",
}) |example_name| {
const example = b.addExecutable(.{
.name = example_name,
.root_module = b.createModule(.{
.root_source_file = b.path(b.fmt("examples/{s}.zig", .{example_name})),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "zcode", .module = module },
},
}),
});
const install_example = b.addInstallArtifact(example, .{});
example_step.dependOn(&example.step);
example_step.dependOn(&install_example.step);
const run_example = b.addRunArtifact(example);
if (b.args) |args| run_example.addArgs(args);
run_example.step.dependOn(&install_example.step);
b.step(
b.fmt("run-{s}", .{example_name}),
b.fmt("Run the {s} example", .{example_name}),
).dependOn(&run_example.step);
}
}