-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.zig
More file actions
305 lines (280 loc) · 11.8 KB
/
build.zig
File metadata and controls
305 lines (280 loc) · 11.8 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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const use_secp256k1 = b.option(bool, "secp256k1", "Link against libsecp256k1 for ECDSA verification") orelse true;
const experimental = b.option(bool, "experimental", "Include experimental node subsystems (consensus, network, p2p)") orelse false;
const gate_e_fuzz_cases = b.option(u32, "gate_e_fuzz_cases", "Gate E fuzz case budget") orelse 25000;
const gate_e_profile = b.option([]const u8, "gate_e_profile", "Gate E profile label") orelse "pr";
const build_options = b.addOptions();
build_options.addOption(bool, "has_secp256k1", use_secp256k1);
build_options.addOption(bool, "experimental", experimental);
build_options.addOption(u32, "gate_e_fuzz_cases", gate_e_fuzz_cases);
build_options.addOption([]const u8, "gate_e_profile", gate_e_profile);
// ── Main executable (toolkit CLI by default, full node with -Dexperimental) ──
const main_module = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
main_module.addOptions("build_options", build_options);
const exe = b.addExecutable(.{
.name = "rippled-zig",
.root_module = main_module,
});
exe.linkLibC();
if (use_secp256k1) {
exe.linkSystemLibrary("secp256k1");
}
b.installArtifact(exe);
// Run command
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("run", "Run rippled-zig (toolkit CLI by default)");
run_step.dependOn(&run_cmd.step);
// ── Tests ──
const test_module = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
test_module.addOptions("build_options", build_options);
const unit_tests = b.addTest(.{
.root_module = test_module,
});
unit_tests.linkLibC();
if (use_secp256k1) {
unit_tests.linkSystemLibrary("secp256k1");
}
const run_unit_tests = b.addRunArtifact(unit_tests);
const test_step = b.step("test", "Run unit tests");
test_step.dependOn(&run_unit_tests.step);
// ── Gate B: deterministic serialization/hash checks ──
const gate_b_module = b.createModule(.{
.root_source_file = b.path("src/determinism_check.zig"),
.target = target,
.optimize = optimize,
});
gate_b_module.addOptions("build_options", build_options);
const gate_b_exe = b.addExecutable(.{
.name = "gate-b-check",
.root_module = gate_b_module,
});
gate_b_exe.linkLibC();
if (use_secp256k1) {
gate_b_exe.linkSystemLibrary("secp256k1");
}
const run_gate_b_tests = b.addRunArtifact(gate_b_exe);
const gate_b_step = b.step("gate-b", "Run Gate B deterministic checks");
gate_b_step.dependOn(&run_gate_b_tests.step);
// ── Gate C: parity and contract checks ──
const gate_c_module = b.createModule(.{
.root_source_file = b.path("src/parity_check.zig"),
.target = target,
.optimize = optimize,
});
gate_c_module.addOptions("build_options", build_options);
const gate_c_exe = b.addExecutable(.{
.name = "gate-c-check",
.root_module = gate_c_module,
});
gate_c_exe.linkLibC();
if (use_secp256k1) {
gate_c_exe.linkSystemLibrary("secp256k1");
}
const run_gate_c_tests = b.addRunArtifact(gate_c_exe);
const gate_c_step = b.step("gate-c", "Run Gate C parity checks");
gate_c_step.dependOn(&run_gate_c_tests.step);
// ── Gate E: security checks ──
const gate_e_module = b.createModule(.{
.root_source_file = b.path("src/security_check.zig"),
.target = target,
.optimize = optimize,
});
gate_e_module.addOptions("build_options", build_options);
const gate_e_exe = b.addExecutable(.{
.name = "gate-e-check",
.root_module = gate_e_module,
});
gate_e_exe.linkLibC();
if (use_secp256k1) {
gate_e_exe.linkSystemLibrary("secp256k1");
}
const run_gate_e_tests = b.addRunArtifact(gate_e_exe);
const gate_e_step = b.step("gate-e", "Run Gate E security checks");
gate_e_step.dependOn(&run_gate_e_tests.step);
// ── WASM: Protocol kernel ──
const wasm_target = b.resolveTargetQuery(.{
.cpu_arch = .wasm32,
.os_tag = .freestanding,
});
const kernel_module = b.createModule(.{
.root_source_file = b.path("src/protocol_kernel.zig"),
.target = wasm_target,
.optimize = optimize,
});
const kernel_exe = b.addExecutable(.{
.name = "protocol_kernel",
.root_module = kernel_module,
});
kernel_exe.entry = .disabled;
const kernel_install = b.addInstallArtifact(kernel_exe, .{
.dest_dir = .{ .override = .{ .custom = "wasm" } },
});
const kernel_step = b.step("wasm-kernel", "Build protocol kernel as WASM");
kernel_step.dependOn(&kernel_install.step);
// ── WASM: Hooks template ──
const hook_module = b.createModule(.{
.root_source_file = b.path("examples/hook_template.zig"),
.target = wasm_target,
.optimize = .ReleaseSmall,
});
const hook_exe = b.addExecutable(.{
.name = "hook_template",
.root_module = hook_module,
});
hook_exe.entry = .disabled;
hook_exe.rdynamic = true;
const hook_install = b.addInstallArtifact(hook_exe, .{
.dest_dir = .{ .override = .{ .custom = "wasm" } },
});
const hook_step = b.step("wasm-hook", "Build Hooks template as WASM");
hook_step.dependOn(&hook_install.step);
const wasm_step = b.step("wasm", "Build all WASM targets (kernel + hook)");
wasm_step.dependOn(&kernel_install.step);
wasm_step.dependOn(&hook_install.step);
// ── Cross-compilation release builds ──
const release_step = b.step("release", "Build release binaries for all platforms");
const CrossTarget = struct {
name: []const u8,
cpu_arch: std.Target.Cpu.Arch,
os_tag: std.Target.Os.Tag,
abi: ?std.Target.Abi = null,
is_wasm: bool = false,
};
const cross_targets = [_]CrossTarget{
.{ .name = "x86_64-linux", .cpu_arch = .x86_64, .os_tag = .linux, .abi = .musl },
.{ .name = "aarch64-linux", .cpu_arch = .aarch64, .os_tag = .linux, .abi = .musl },
.{ .name = "x86_64-macos", .cpu_arch = .x86_64, .os_tag = .macos },
.{ .name = "aarch64-macos", .cpu_arch = .aarch64, .os_tag = .macos },
.{ .name = "x86_64-windows", .cpu_arch = .x86_64, .os_tag = .windows },
.{ .name = "wasm32-freestanding", .cpu_arch = .wasm32, .os_tag = .freestanding, .is_wasm = true },
};
for (cross_targets) |ct| {
var query: std.Target.Query = .{
.cpu_arch = ct.cpu_arch,
.os_tag = ct.os_tag,
};
if (ct.abi) |abi| {
query.abi = abi;
}
const resolved = b.resolveTargetQuery(query);
if (ct.is_wasm) {
// WASM: build protocol library only (no CLI, no libc)
const wasm_lib_module = b.createModule(.{
.root_source_file = b.path("src/wasm_lib.zig"),
.target = resolved,
.optimize = .ReleaseSafe,
});
const wasm_lib_exe = b.addExecutable(.{
.name = "rippled-zig-lib",
.root_module = wasm_lib_module,
});
wasm_lib_exe.entry = .disabled;
wasm_lib_exe.rdynamic = true;
const wasm_lib_install = b.addInstallArtifact(wasm_lib_exe, .{
.dest_dir = .{ .override = .{ .custom = "release/wasm32-freestanding" } },
});
release_step.dependOn(&wasm_lib_install.step);
} else {
// Native CLI binary
const rel_build_options = b.addOptions();
rel_build_options.addOption(bool, "has_secp256k1", false);
rel_build_options.addOption(bool, "experimental", false);
rel_build_options.addOption(u32, "gate_e_fuzz_cases", 25000);
rel_build_options.addOption([]const u8, "gate_e_profile", "release");
const rel_module = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.target = resolved,
.optimize = .ReleaseSafe,
});
rel_module.addOptions("build_options", rel_build_options);
const rel_exe = b.addExecutable(.{
.name = "rippled-zig",
.root_module = rel_module,
});
// Link libc for native targets (use default libc for cross targets)
rel_exe.linkLibC();
const rel_install = b.addInstallArtifact(rel_exe, .{
.dest_dir = .{ .override = .{ .custom = b.fmt("release/{s}", .{ct.name}) } },
});
release_step.dependOn(&rel_install.step);
}
}
// ── Release checksums ──
const checksums_step = b.step("release-checksums", "Build all release targets and generate SHA256SUMS");
checksums_step.dependOn(release_step);
const checksums_run = b.addSystemCommand(&.{
"sh", "-c",
"cd zig-out/release && find . -type f \\( -name 'rippled-zig' -o -name 'rippled-zig.exe' -o -name 'rippled-zig-lib.wasm' \\) -exec shasum -a 256 {} \\; > SHA256SUMS && cat SHA256SUMS",
});
checksums_run.step.dependOn(release_step);
checksums_step.dependOn(&checksums_run.step);
// ── Experimental-only build steps ──
if (experimental) {
// Consensus experiment harness
const consensus_exp_module = b.createModule(.{
.root_source_file = b.path("tools/consensus_experiment.zig"),
.target = target,
.optimize = optimize,
});
consensus_exp_module.addImport("consensus", b.createModule(.{
.root_source_file = b.path("src/consensus.zig"),
.target = target,
.optimize = optimize,
}));
const consensus_exp_exe = b.addExecutable(.{
.name = "consensus-experiment",
.root_module = consensus_exp_module,
});
consensus_exp_exe.linkLibC();
if (use_secp256k1) {
consensus_exp_exe.linkSystemLibrary("secp256k1");
}
const run_consensus_exp = b.addRunArtifact(consensus_exp_exe);
if (b.args) |args| {
run_consensus_exp.addArgs(args);
}
const consensus_exp_step = b.step("consensus-experiment", "Run parameterized consensus experiment harness");
consensus_exp_step.dependOn(&run_consensus_exp.step);
}
// Control-plane policy snapshot (always available — it's a conformance tool)
const policy_snapshot_module = b.createModule(.{
.root_source_file = b.path("tools/control_plane_policy_snapshot.zig"),
.target = target,
.optimize = optimize,
});
policy_snapshot_module.addOptions("build_options", build_options);
policy_snapshot_module.addImport("rpc_methods", b.createModule(.{
.root_source_file = b.path("src/rpc_methods.zig"),
.target = target,
.optimize = optimize,
}));
const policy_snapshot_exe = b.addExecutable(.{
.name = "control-plane-policy-snapshot",
.root_module = policy_snapshot_module,
});
policy_snapshot_exe.linkLibC();
if (use_secp256k1) {
policy_snapshot_exe.linkSystemLibrary("secp256k1");
}
const run_policy_snapshot = b.addRunArtifact(policy_snapshot_exe);
if (b.args) |args| {
run_policy_snapshot.addArgs(args);
}
const policy_snapshot_step = b.step("control-plane-policy-snapshot", "Emit deterministic control-plane policy snapshot JSON");
policy_snapshot_step.dependOn(&run_policy_snapshot.step);
}