-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.zig
116 lines (94 loc) · 3.6 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
const std = @import("std");
/// Generate documentation if the user requests it
pub fn doc(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode) void {
const autodoc_test = b.addObject(.{
.name = "ecez",
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
const install_docs = b.addInstallDirectory(.{
.source_dir = autodoc_test.getEmittedDocs(),
.install_dir = .prefix,
.install_subdir = "doc/ecez",
});
const docs_step = b.step("docs", "Build and install documentation");
docs_step.dependOn(&install_docs.step);
}
/// Builds the project for testing and to run simple examples
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
// initialize tracy
const enable_tracy = b.option(bool, "enable_tracy", "Enable Tracy profiler") orelse false;
const ztracy = b.dependency("ztracy", .{
.enable_ztracy = enable_tracy,
.enable_fibers = true,
});
const imports = [_]std.Build.Module.Import{
.{
.name = "ztracy",
.module = ztracy.module("root"),
},
};
const main_path = b.path("src/main.zig");
const ecez = b.addModule("ecez", std.Build.Module.CreateOptions{
.root_source_file = main_path,
.imports = &imports,
});
// create a debuggable test executable
{
const main_tests = b.addTest(.{
.name = "main_tests",
.root_source_file = main_path,
.optimize = optimize,
});
main_tests.root_module.addImport("ecez", ecez);
main_tests.root_module.addImport("ztracy", ztracy.module("root"));
b.installArtifact(main_tests);
}
// generate documentation on demand
doc(b, target, optimize);
// add library tests to the main tests
const main_tests = b.addTest(.{
.root_source_file = main_path,
.optimize = optimize,
});
main_tests.root_module.addImport("ecez", ecez);
main_tests.root_module.addImport("ztracy", ztracy.module("root"));
const test_step = b.step("test", "Run all tests");
const main_tests_run = b.addRunArtifact(main_tests);
test_step.dependOn(&main_tests_run.step);
const Example = struct {
name: []const u8,
};
inline for ([_]Example{
.{ .name = "game-of-life" },
.{ .name = "readme" },
}) |example| {
const path = b.path("examples/" ++ example.name ++ "/main.zig");
const exe = b.addExecutable(.{
.name = example.name,
.root_source_file = path,
.target = target,
.optimize = optimize,
});
exe.root_module.addImport("ecez", ecez);
exe.root_module.addImport("ztracy", ztracy.module("root"));
exe.linkLibrary(ztracy.artifact("tracy"));
b.installArtifact(exe);
const run_step = b.step("run-" ++ example.name, "Run '" ++ example.name ++ "' demo");
const run_cmd = b.addRunArtifact(exe);
run_cmd.step.dependOn(b.getInstallStep());
run_step.dependOn(&run_cmd.step);
// add any tests that are define inside each example
const example_tests = b.addTest(.{
.root_source_file = path,
.optimize = optimize,
});
example_tests.root_module.addImport("ecez", ecez);
example_tests.root_module.addImport("ztracy", ztracy.module("root"));
const example_test_run = b.addRunArtifact(example_tests);
test_step.dependOn(&example_test_run.step);
}
}