-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbuild.zig
More file actions
200 lines (180 loc) · 6.4 KB
/
build.zig
File metadata and controls
200 lines (180 loc) · 6.4 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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
const std = @import("std");
const zine = @import("zine");
pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
// the zine dev server needs this option!!!
const opt_debug = b.option(bool, "debug", "zine debug, unused") orelse true;
const pcre2_dep = b.dependency("pcre2", .{
.target = target,
.optimize = optimize,
.@"code-unit-width" = .@"8",
});
const docs_wasm = try buildDocsWasm(b, optimize);
const website_step, const serve_step = try buildWebSite(b, docs_wasm, opt_debug);
// has to be run with zig build website
_ = website_step;
// has to be run with zig build serve
_ = serve_step;
const tool_exe = try buildTool(b, target, optimize);
tool_exe.linkLibrary(pcre2_dep.artifact("pcre2-8")); // for unicode 8
b.installArtifact(tool_exe);
//
// TESTS
//
addTests(b, target, optimize, pcre2_dep);
}
/// build the WASM docs target
fn buildDocsWasm(b: *std.Build, optimize: std.builtin.OptimizeMode) !*std.Build.Step.Compile {
const wasm_target = b.resolveTargetQuery(.{
.cpu_arch = .wasm32,
.os_tag = .freestanding,
});
// Vendored version of https://github.com/ziglang/zig/tree/0.13.0/lib/docs/wasm
const docs_wasm = b.addExecutable(.{
.name = "main",
.target = wasm_target,
.optimize = optimize,
.root_source_file = .{ .cwd_relative = "zig_docs/main.zig" },
});
docs_wasm.entry = .disabled;
docs_wasm.rdynamic = true;
const Walk = b.addModule("Walk", .{
.root_source_file = .{ .cwd_relative = "zig_docs/Walk.zig" },
});
docs_wasm.root_module.addImport("Walk", Walk);
return docs_wasm;
}
fn buildWebSite(b: *std.Build, docs_wasm: *std.Build.Step.Compile, debug: bool) !struct {
*std.Build.Step,
*std.Build.Step,
} {
const site: zine.Site =
.{
.title = "ZML Documentation Website",
.host_url = "https://docs.zml.ai",
.content_dir_path = "content",
.layouts_dir_path = "layouts",
.assets_dir_path = "assets",
.static_assets = &.{
"zml.no_light.svg",
"zml_api.js",
"sources.tar",
"CNAME",
"fonts/jbm/JetBrainsMono-Light.woff2",
"fonts/jbm/JetBrainsMono-ThinItalic.woff2",
"fonts/jbm/JetBrainsMono-BoldItalic.woff2",
"fonts/jbm/JetBrainsMono-Regular.woff2",
"fonts/jbm/JetBrainsMono-SemiBold.woff2",
"fonts/jbm/JetBrainsMono-MediumItalic.woff2",
"fonts/jbm/JetBrainsMono-ExtraLightItalic.woff2",
"fonts/jbm/JetBrainsMono-Medium.woff2",
"fonts/jbm/JetBrainsMono-LightItalic.woff2",
"fonts/jbm/JetBrainsMono-ExtraLight.woff2",
"fonts/jbm/JetBrainsMono-Bold.woff2",
"fonts/jbm/JetBrainsMono-Thin.woff2",
"fonts/jbm/JetBrainsMono-SemiBoldItalic.woff2",
"fonts/jbm/JetBrainsMono-ExtraBoldItalic.woff2",
"fonts/jbm/JetBrainsMono-ExtraBold.woff2",
"fonts/jbm/JetBrainsMono-Italic.woff2",
},
.build_assets = &.{
.{
.name = "main.wasm",
.lp = docs_wasm.getEmittedBin(),
.install_path = "main.wasm",
.install_always = true,
},
},
.debug = debug,
};
// Setup debug flags if the user enabled Zine debug.
const opts: zine.ZineOptions = .{
.optimize = if (site.debug) .Debug else .ReleaseFast,
};
const website_step = b.step(
"website",
"Builds the website",
);
zine.addWebsite(b, opts, website_step, site);
const serve_step = b.step(
"serve",
"Starts the Zine development server",
);
const port = b.option(
u16,
"port",
"port to listen on for the development server",
) orelse 1990;
zine.addDevelopmentServer(b, opts, serve_step, .{
.website_step = website_step,
.host = "localhost",
.port = port,
.input_dirs = &.{
site.layouts_dir_path,
site.content_dir_path,
site.assets_dir_path,
},
});
return .{ website_step, serve_step };
}
/// build the Workspace Preparation tool
fn buildTool(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode) !*std.Build.Step.Compile {
// text pre- and post-processor
const exe = b.addExecutable(.{
.name = "tool",
.root_source_file = b.path("tools/tool.zig"),
.target = target,
.optimize = optimize,
});
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("tool", "Run the workspace preparation tool");
run_step.dependOn(&run_cmd.step);
return exe;
}
fn addTests(
b: *std.Build,
target: std.Build.ResolvedTarget,
optimize: std.builtin.OptimizeMode,
pcre2_dep: *std.Build.Dependency,
) void {
// tools/processor.zig
const exe_test_processor = b.addTest(.{
.root_source_file = b.path("tools/processor.zig"),
.target = target,
.optimize = optimize,
});
exe_test_processor.linkLibrary(pcre2_dep.artifact("pcre2-8")); // for unicode 8
const run_test_processor = b.addRunArtifact(exe_test_processor);
// tools/regex.zig
const exe_test_regex = b.addTest(.{
.root_source_file = b.path("tools/regex.zig"),
.target = target,
.optimize = optimize,
});
exe_test_regex.linkLibrary(pcre2_dep.artifact("pcre2-8")); // for unicode 8
const run_test_regex = b.addRunArtifact(exe_test_regex);
// tools/shell.zig
const exe_test_shell = b.addTest(.{
.root_source_file = b.path("tools/shell.zig"),
.target = target,
.optimize = optimize,
});
const run_test_shell = b.addRunArtifact(exe_test_shell);
// tools/tool.zig
const exe_test_tool = b.addTest(.{
.root_source_file = b.path("tools/tool.zig"),
.target = target,
.optimize = optimize,
});
const run_test_tool = b.addRunArtifact(exe_test_tool);
const test_step = b.step("test", "Run unit tests");
test_step.dependOn(&run_test_processor.step);
test_step.dependOn(&run_test_regex.step);
test_step.dependOn(&run_test_shell.step);
test_step.dependOn(&run_test_tool.step);
}