forked from getty-zig/getty
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.zig
108 lines (93 loc) · 3.52 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
const std = @import("std");
const package_name = "getty";
const src_dir = "src/";
const package_path = src_dir ++ package_name ++ ".zig";
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const protest_options = .{ .target = target, .optimize = optimize };
const protest_module = b.dependency("protest", protest_options).module("protest");
const common_module = b.createModule(.{ .root_source_file = b.path(src_dir ++ "common/root.zig") });
const imports = [_]std.Build.Module.Import{
.{
.name = "protest",
.module = protest_module,
},
// internal import required for tests
.{
.name = "common",
.module = common_module,
},
};
_ = b.addModule(package_name, .{
.root_source_file = b.path(package_path),
.imports = &imports,
});
// Tests
{
const test_all_step = b.step("test", "Run tests");
// filtered testing
if (b.args) |args| {
std.debug.assert(args.len != 0); // b.args would be null if no arguments were given.
for (args) |arg| {
const test_filtered = b.addTest(.{
.name = "filtered test",
.root_source_file = b.path(package_path),
.filter = arg,
.target = target,
.optimize = optimize,
});
inline for (imports) |import| {
test_filtered.root_module.addImport(import.name, import.module);
}
test_all_step.dependOn(&b.addRunArtifact(test_filtered).step);
}
return;
}
const test_ser_step = b.step("test-ser", "Run serialization tests");
const test_deser_step = b.step("test-deser", "Run deserialization tests");
// Serialization tests.
const test_ser = b.addTest(.{
.name = "serialization test",
.root_source_file = b.path("src/ser/ser.zig"),
.target = target,
.optimize = optimize,
});
inline for (imports) |import| {
test_ser.root_module.addImport(import.name, import.module);
}
test_ser_step.dependOn(&b.addRunArtifact(test_ser).step);
test_all_step.dependOn(test_ser_step);
// Deserialization tests.
const test_deser = b.addTest(.{
.name = "deserialization test",
.root_source_file = b.path("src/de/de.zig"),
.target = target,
.optimize = optimize,
});
inline for (imports) |import| {
test_deser.root_module.addImport(import.name, import.module);
}
test_deser_step.dependOn(&b.addRunArtifact(test_deser).step);
test_all_step.dependOn(test_deser_step);
}
// Documentation
{
const docs_step = b.step("docs", "Build the project documentation");
const doc_obj = b.addObject(.{
.name = "docs",
.root_source_file = b.path(package_path),
.target = target,
.optimize = optimize,
});
inline for (imports) |import| {
doc_obj.root_module.addImport(import.name, import.module);
}
const install_docs = b.addInstallDirectory(.{
.source_dir = doc_obj.getEmittedDocs(),
.install_dir = .prefix,
.install_subdir = "docs/getty",
});
docs_step.dependOn(&install_docs.step);
}
}