Repository navigation
Expand file tree
/
Copy pathbuild.zig
More file actions
173 lines (154 loc) · 6.22 KB
/
Copy pathbuild.zig
File metadata and controls
173 lines (154 loc) · 6.22 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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
const std = @import("std");
const available_dev_tools_str: []const u8 =
\\Available dev-tools are:
\\ export-units
\\ export-constants
\\ export-all
\\ prefix-units
\\ clean-units
\\ clean-constants
\\ clean-all
;
const dev_tools_invoke_str: []const u8 = "dev-tools invoked without arguments.";
const dev_tools_unknown_str: []const u8 = "Unknown dev-tools `{s}`.";
const dev_tools_no_args_msg: []const u8 = dev_tools_invoke_str ++ " " ++ available_dev_tools_str;
const dev_tools_unknown_msg: []const u8 = dev_tools_unknown_str ++ " " ++ available_dev_tools_str;
pub fn build(b: *std.Build) void {
const targetOption = b.standardTargetOptions(.{});
const optimizeOption = b.standardOptimizeOption(.{});
const module = b.addModule("zali", .{
.root_source_file = b.path("src/zali.zig"),
.target = targetOption,
.optimize = optimizeOption,
});
const lib = b.addLibrary(.{
.linkage = .static,
.name = "zali",
.root_module = module,
});
b.installArtifact(lib);
const tests = b.addTest(.{
.root_module = module,
});
const run_tests = b.addRunArtifact(tests);
const test_step = b.step("test", "Run library tests");
test_step.dependOn(&run_tests.step);
// dev-tools
{
const dev_tools = b.step("dev-tools", "Run dev tool: zig build dev-tools -- <name|all>");
// Export units
//
const exe_units = b.addExecutable(.{
.name = "reexport_units",
.root_module = b.createModule(.{
.root_source_file = b.path("dev/tools/reexport_units.zig"),
.target = targetOption,
.optimize = optimizeOption,
}),
});
exe_units.root_module.addImport("zali", module);
const run_units = b.addRunArtifact(exe_units);
// Export constants
//
const exe_constants = b.addExecutable(.{
.name = "reexport_constants",
.root_module = b.createModule(.{
.root_source_file = b.path("dev/tools/reexport_constants.zig"),
.target = targetOption,
.optimize = optimizeOption,
}),
});
exe_constants.root_module.addImport("zali", module);
const run_constants = b.addRunArtifact(exe_constants);
// Clean units export
//
const exe_clean_units = b.addExecutable(.{
.name = "clean_units",
.root_module = b.createModule(.{
.root_source_file = b.path("dev/tools/clean_export_units.zig"),
.target = targetOption,
.optimize = optimizeOption,
}),
});
const run_clean_units = b.addRunArtifact(exe_clean_units);
// Clean constants export
//
const exe_clean_constants = b.addExecutable(.{
.name = "clean_constants",
.root_module = b.createModule(.{
.root_source_file = b.path("dev/tools/clean_export_constants.zig"),
.target = targetOption,
.optimize = optimizeOption,
}),
});
const run_clean_constants = b.addRunArtifact(exe_clean_constants);
const dev_tools_no_args = b.addFail(dev_tools_no_args_msg);
const exe_prefix_units = b.addExecutable(.{
.name = "prefix_units",
.root_module = b.createModule(.{
.root_source_file = b.path("dev/tools/prefix_builder.zig"),
.target = targetOption,
.optimize = optimizeOption,
}),
});
exe_prefix_units.root_module.addImport("zali", module);
const run_prefix_units = b.addRunArtifact(exe_prefix_units);
if (b.args) |args| {
if (args.len == 0) {
dev_tools.dependOn(&dev_tools_no_args.step);
} else {
for_loop: for (args) |arg| {
if (std.mem.eql(u8, arg, "prefix-units")) {
dev_tools.dependOn(&run_prefix_units.step);
break :for_loop;
}
if (std.mem.eql(u8, arg, "export-all")) {
dev_tools.dependOn(&run_units.step);
dev_tools.dependOn(&run_constants.step);
break :for_loop;
}
if (std.mem.eql(u8, arg, "export-units")) {
dev_tools.dependOn(&run_units.step);
break :for_loop;
}
if (std.mem.eql(u8, arg, "export-constants")) {
dev_tools.dependOn(&run_constants.step);
break :for_loop;
}
if (std.mem.eql(u8, arg, "clean-all")) {
dev_tools.dependOn(&run_clean_units.step);
dev_tools.dependOn(&run_clean_constants.step);
break :for_loop;
}
if (std.mem.eql(u8, arg, "clean-units")) {
dev_tools.dependOn(&run_clean_units.step);
break :for_loop;
}
if (std.mem.eql(u8, arg, "clean-constants")) {
dev_tools.dependOn(&run_clean_constants.step);
break :for_loop;
} else {
var buf: [256]u8 = undefined;
const msg = std.fmt.bufPrint(&buf, dev_tools_unknown_msg, .{arg}) catch {
std.debug.panic(dev_tools_unknown_msg, .{arg});
};
const dev_tools_unknown_arg = b.addFail(msg);
dev_tools.dependOn(&dev_tools_unknown_arg.step);
}
}
}
} else {
dev_tools.dependOn(&dev_tools_no_args.step);
}
}
// Docs
{
const install_docs = b.addInstallDirectory(.{
.source_dir = lib.getEmittedDocs(),
.install_dir = .prefix,
.install_subdir = "docs",
});
const docs_step = b.step("docs", "Install docs into zig-out/docs");
docs_step.dependOn(&install_docs.step);
}
}