-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.zig
84 lines (68 loc) · 2.53 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
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
// ----- Main module -----
const parcom = b.addModule("parcom", .{
.root_source_file = b.path("src/parcom.zig"),
.target = target,
.optimize = optimize,
});
// to test docs run:
// python -m http.server 8000 -d zig-out/docs
const docs = b.addObject(.{
.name = "parcom",
.root_source_file = b.path("src/parcom.zig"),
.target = target,
.optimize = .Debug,
});
const install_docs = b.addInstallDirectory(.{
.install_dir = .prefix,
.install_subdir = "docs",
.source_dir = docs.getEmittedDocs(),
});
b.step("docs", "Build docs").dependOn(&install_docs.step);
// ----- Unit tests -----
// -Dtest-filter=<a part of the test name>
const test_filters = b.option(
[]const []const u8,
"test-filter",
"Skip tests that do not match any filter",
) orelse &[0][]const u8{};
const parcom_tests = b.addTest(.{
.root_source_file = b.path("src/parcom.zig"),
.target = target,
.optimize = optimize,
.filters = test_filters,
});
const run_parcom_tests = b.addRunArtifact(parcom_tests);
const test_step = b.step("test", "Run unit tests");
test_step.dependOn(&run_parcom_tests.step);
// ----- Examples -----
inline for ([_][]const u8{ "expression", "json" }) |example| {
const example_source = std.fmt.comptimePrint("examples/{s}.zig", .{example});
const exe = b.addExecutable(.{
.name = example,
.root_source_file = b.path(example_source),
.target = target,
.optimize = optimize,
});
exe.root_module.addImport("parcom", parcom);
b.installArtifact(exe);
const run_exe = b.addRunArtifact(exe);
if (b.args) |args| {
run_exe.addArgs(args);
}
const run_step = b.step(example, std.fmt.comptimePrint("Run example of {s}", .{example}));
run_step.dependOn(&run_exe.step);
const example_tests = b.addTest(.{
.root_source_file = b.path(example_source),
.target = target,
.optimize = optimize,
.filters = test_filters,
});
example_tests.root_module.addImport("parcom", parcom);
const run_examples_tests = b.addRunArtifact(example_tests);
test_step.dependOn(&run_examples_tests.step);
}
}