forked from Syndica/sig
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.zig
181 lines (155 loc) · 7.2 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
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
const std = @import("std");
const Build = std.Build;
pub fn build(b: *Build) void {
defer makeZlsNotInstallAnythingDuringBuildOnSave(b);
// CLI options
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const filters = b.option([]const []const u8, "filter", "List of filters, used for example to filter unit tests by name"); // specified as a series like `-Dfilter="filter1" -Dfilter="filter2"`
const enable_tsan = b.option(bool, "enable-tsan", "Enable TSan for the test suite");
// CLI build steps
const run_step = b.step("run", "Run the sig executable");
const test_step = b.step("test", "Run library tests");
const fuzz_step = b.step("fuzz", "Gossip fuzz testing");
const benchmark_step = b.step("benchmark", "Benchmark client");
const geyser_reader_step = b.step("geyser_reader", "read data from geyser");
// Dependencies
const dep_opts = .{ .target = target, .optimize = optimize };
const base58_dep = b.dependency("base58-zig", dep_opts);
const base58_module = base58_dep.module("base58-zig");
const zig_network_dep = b.dependency("zig-network", dep_opts);
const zig_network_module = zig_network_dep.module("network");
const zig_cli_dep = b.dependency("zig-cli", dep_opts);
const zig_cli_module = zig_cli_dep.module("zig-cli");
const httpz_dep = b.dependency("httpz", dep_opts);
const httpz_mod = httpz_dep.module("httpz");
const zstd_dep = b.dependency("zstd", dep_opts);
const zstd_mod = zstd_dep.module("zstd");
const curl_dep = b.dependency("curl", dep_opts);
const curl_mod = curl_dep.module("curl");
const rocksdb_dep = b.dependency("rocksdb", dep_opts);
const rocksdb_mod = rocksdb_dep.module("rocksdb-bindings");
// expose Sig as a module
const sig_mod = b.addModule("sig", .{
.root_source_file = b.path("src/sig.zig"),
});
sig_mod.addImport("zig-network", zig_network_module);
sig_mod.addImport("base58-zig", base58_module);
sig_mod.addImport("zig-cli", zig_cli_module);
sig_mod.addImport("httpz", httpz_mod);
sig_mod.addImport("zstd", zstd_mod);
sig_mod.addImport("curl", curl_mod);
sig_mod.addImport("rocksdb", rocksdb_mod);
// main executable
const sig_exe = b.addExecutable(.{
.name = "sig",
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
b.installArtifact(sig_exe);
sig_exe.root_module.addImport("base58-zig", base58_module);
sig_exe.root_module.addImport("curl", curl_mod);
sig_exe.root_module.addImport("httpz", httpz_mod);
sig_exe.root_module.addImport("zig-cli", zig_cli_module);
sig_exe.root_module.addImport("zig-network", zig_network_module);
sig_exe.root_module.addImport("zstd", zstd_mod);
sig_exe.root_module.addImport("rocksdb", rocksdb_mod);
sig_exe.linkLibC();
const main_exe_run = b.addRunArtifact(sig_exe);
main_exe_run.addArgs(b.args orelse &.{});
run_step.dependOn(&main_exe_run.step);
// docs for the Sig library
const sig_obj = b.addObject(.{
.name = "sig",
.root_source_file = b.path("src/sig.zig"),
.target = target,
.optimize = .Debug,
});
const docs_step = b.step("docs", "Generate and install documentation for the Sig Library");
const install_sig_docs = b.addInstallDirectory(.{
.source_dir = sig_obj.getEmittedDocs(),
.install_dir = .prefix,
.install_subdir = "docs",
});
docs_step.dependOn(&install_sig_docs.step);
// unit tests
const unit_tests_exe = b.addTest(.{
.root_source_file = b.path("src/tests.zig"),
.target = target,
.optimize = optimize,
.filters = filters orelse &.{},
.sanitize_thread = enable_tsan,
});
b.installArtifact(unit_tests_exe);
unit_tests_exe.root_module.addImport("base58-zig", base58_module);
unit_tests_exe.root_module.addImport("curl", curl_mod);
unit_tests_exe.root_module.addImport("httpz", httpz_mod);
unit_tests_exe.root_module.addImport("zig-network", zig_network_module);
unit_tests_exe.root_module.addImport("zstd", zstd_mod);
unit_tests_exe.root_module.addImport("rocksdb", rocksdb_mod);
unit_tests_exe.linkLibC();
const unit_tests_exe_run = b.addRunArtifact(unit_tests_exe);
test_step.dependOn(&unit_tests_exe_run.step);
// fuzz test
const fuzz_exe = b.addExecutable(.{
.name = "fuzz",
.root_source_file = b.path("src/fuzz.zig"),
.target = target,
.optimize = optimize,
});
b.installArtifact(fuzz_exe);
fuzz_exe.root_module.addImport("base58-zig", base58_module);
fuzz_exe.root_module.addImport("zig-network", zig_network_module);
fuzz_exe.root_module.addImport("httpz", httpz_mod);
fuzz_exe.root_module.addImport("zstd", zstd_mod);
fuzz_exe.linkLibC();
const fuzz_exe_run = b.addRunArtifact(fuzz_exe);
fuzz_exe_run.addArgs(b.args orelse &.{});
fuzz_step.dependOn(&fuzz_exe_run.step);
// benchmarks
const benchmark_exe = b.addExecutable(.{
.name = "benchmark",
.root_source_file = b.path("src/benchmarks.zig"),
.target = target,
.optimize = optimize,
});
b.installArtifact(benchmark_exe);
benchmark_exe.root_module.addImport("base58-zig", base58_module);
benchmark_exe.root_module.addImport("zig-network", zig_network_module);
benchmark_exe.root_module.addImport("httpz", httpz_mod);
benchmark_exe.root_module.addImport("zstd", zstd_mod);
benchmark_exe.linkLibC();
const benchmark_exe_run = b.addRunArtifact(benchmark_exe);
benchmark_exe_run.addArgs(b.args orelse &.{});
benchmark_step.dependOn(&benchmark_exe_run.step);
// geyser reader
const geyser_reader_exe = b.addExecutable(.{
.name = "geyser_reader",
.root_source_file = b.path("src/geyser/reader.zig"),
.target = target,
.optimize = optimize,
});
b.installArtifact(geyser_reader_exe);
geyser_reader_exe.root_module.addImport("sig", sig_mod);
const geyser_reader_exe_run = b.addRunArtifact(geyser_reader_exe);
geyser_reader_exe_run.addArgs(b.args orelse &.{});
geyser_reader_step.dependOn(&geyser_reader_exe_run.step);
}
/// Reference/inspiration: https://kristoff.it/blog/improving-your-zls-experience/
fn makeZlsNotInstallAnythingDuringBuildOnSave(b: *Build) void {
const zls_is_build_runner = b.option(bool, "zls-is-build-runner", "" ++
"Option passed by zls to indicate that it's the one running this build script (configured in the local zls.json). " ++
"This should not be specified on the command line nor as a dependency argument.") orelse false;
if (!zls_is_build_runner) return;
for (b.install_tls.step.dependencies.items) |*install_step_dep| {
const install_artifact = install_step_dep.*.cast(Build.Step.InstallArtifact) orelse continue;
const artifact = install_artifact.artifact;
install_step_dep.* = &artifact.step;
// this will make it so `-fno-emit-bin` is passed, meaning
// that the compiler will only go as far as semantically
// analyzing the code, without sending it to any backend,
// namely the slow-to-compile LLVM.
artifact.generated_bin = null;
}
}