-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.zig
More file actions
480 lines (425 loc) · 22.1 KB
/
build.zig
File metadata and controls
480 lines (425 loc) · 22.1 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
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
// ── Platform detection ────────────────────────────────────────────────────
const is_linux = b.graph.host.result.os.tag == .linux;
const crypto_prefix: []const u8 = if (is_linux) "/usr/local" else "/opt/homebrew";
const crypto_include = b.fmt("{s}/include", .{crypto_prefix});
const libblst_path = b.fmt("{s}/lib/libblst.a", .{crypto_prefix});
const libmcl_path = b.fmt("{s}/lib/libmcl.a", .{crypto_prefix});
// ── Crypto linking helper ─────────────────────────────────────────────────
//
// mcl: on Linux, the .a archive embeds libstdc++ references that Zig/LLD
// cannot resolve reliably against the system libstdc++. Use the .so instead
// (runtime resolution by the OS dynamic linker). On macOS, Homebrew mcl is
// compiled with clang/libc++ so static linking with linkLibCpp() works.
const addCryptoLibraries = struct {
fn add(
step: *std.Build.Step.Compile,
inc: []const u8,
blst: []const u8,
mcl: []const u8,
linux: bool,
) void {
step.root_module.addIncludePath(.{ .cwd_relative = inc });
step.root_module.linkSystemLibrary("c", .{});
step.root_module.linkSystemLibrary("m", .{});
step.root_module.linkSystemLibrary("secp256k1", .{});
step.root_module.linkSystemLibrary("ssl", .{});
step.root_module.linkSystemLibrary("crypto", .{});
step.root_module.addObjectFile(.{ .cwd_relative = blst });
if (linux) {
step.root_module.addLibraryPath(.{ .cwd_relative = "/usr/local/lib" });
step.root_module.linkSystemLibrary("mcl", .{});
} else {
step.root_module.addObjectFile(.{ .cwd_relative = mcl });
step.root_module.link_libcpp = true;
}
}
}.add;
// ── Run step helper ───────────────────────────────────────────────────────
const addRunStep = struct {
fn add(
bb: *std.Build,
name: []const u8,
desc: []const u8,
exe: *std.Build.Step.Compile,
fixed_args: []const []const u8,
) void {
const step = bb.step(name, desc);
const cmd = bb.addRunArtifact(exe);
cmd.step.dependOn(bb.getInstallStep());
cmd.addArgs(fixed_args);
if (bb.args) |args| cmd.addArgs(args);
step.dependOn(&cmd.step);
}
}.add;
// ── Foundation modules ────────────────────────────────────────────────────
// Single allocator module (std.heap.c_allocator for native). Overridden in zesu-zkvm builds.
const zesu_allocator_module = b.createModule(.{
.root_source_file = b.path("src/evm/allocator.zig"),
.target = target,
.optimize = optimize,
});
const primitives_module = b.createModule(.{
.root_source_file = b.path("src/evm/primitives/main.zig"),
.target = target,
.optimize = optimize,
});
// accel_impl: native crypto via std.crypto + C libs (libsecp256k1, OpenSSL, blst, mcl).
// Include paths and C library links are added per-exe by addCryptoLibraries.
const accel_impl_module = b.createModule(.{
.root_source_file = b.path("src/crypto/default.zig"),
.target = target,
.optimize = optimize,
});
accel_impl_module.addImport("zesu_allocator", zesu_allocator_module);
const accelerators_module = b.createModule(.{
.root_source_file = b.path("src/crypto/accelerators.zig"),
.target = target,
.optimize = optimize,
});
accelerators_module.addImport("accel_impl", accel_impl_module);
const precompile_types_module = b.createModule(.{
.root_source_file = b.path("src/evm/precompile/types.zig"),
.target = target,
.optimize = optimize,
});
// ── EVM modules ───────────────────────────────────────────────────────────
const bytecode_module = b.createModule(.{
.root_source_file = b.path("src/evm/bytecode/main.zig"),
.target = target,
.optimize = optimize,
});
bytecode_module.addImport("primitives", primitives_module);
bytecode_module.addImport("zesu_allocator", zesu_allocator_module);
const state_module = b.createModule(.{
.root_source_file = b.path("src/evm/state/main.zig"),
.target = target,
.optimize = optimize,
});
state_module.addImport("primitives", primitives_module);
state_module.addImport("bytecode", bytecode_module);
state_module.addImport("zesu_allocator", zesu_allocator_module);
const database_module = b.createModule(.{
.root_source_file = b.path("src/evm/database/main.zig"),
.target = target,
.optimize = optimize,
});
database_module.addImport("primitives", primitives_module);
database_module.addImport("state", state_module);
database_module.addImport("bytecode", bytecode_module);
const context_module = b.createModule(.{
.root_source_file = b.path("src/evm/context/main.zig"),
.target = target,
.optimize = optimize,
});
context_module.addImport("primitives", primitives_module);
context_module.addImport("bytecode", bytecode_module);
context_module.addImport("state", state_module);
context_module.addImport("database", database_module);
context_module.addImport("zesu_allocator", zesu_allocator_module);
const precompile_module = b.createModule(.{
.root_source_file = b.path("src/evm/precompile/main.zig"),
.target = target,
.optimize = optimize,
});
precompile_module.addImport("primitives", primitives_module);
precompile_module.addImport("zesu_allocator", zesu_allocator_module);
precompile_module.addImport("precompile_types", precompile_types_module);
precompile_module.addImport("accelerators", accelerators_module);
const interpreter_module = b.createModule(.{
.root_source_file = b.path("src/evm/interpreter/main.zig"),
.target = target,
.optimize = optimize,
});
interpreter_module.addImport("primitives", primitives_module);
interpreter_module.addImport("bytecode", bytecode_module);
interpreter_module.addImport("context", context_module);
interpreter_module.addImport("database", database_module);
interpreter_module.addImport("state", state_module);
interpreter_module.addImport("precompile", precompile_module);
interpreter_module.addImport("zesu_allocator", zesu_allocator_module);
interpreter_module.addImport("accelerators", accelerators_module);
const handler_module = b.createModule(.{
.root_source_file = b.path("src/evm/handler/main.zig"),
.target = target,
.optimize = optimize,
});
handler_module.addImport("primitives", primitives_module);
handler_module.addImport("bytecode", bytecode_module);
handler_module.addImport("state", state_module);
handler_module.addImport("database", database_module);
handler_module.addImport("interpreter", interpreter_module);
handler_module.addImport("context", context_module);
handler_module.addImport("precompile", precompile_module);
handler_module.addImport("zesu_allocator", zesu_allocator_module);
// ── Stateless base modules ────────────────────────────────────────────────
const input_module = b.createModule(.{
.root_source_file = b.path("src/stateless/input.zig"),
.target = target,
.optimize = optimize,
});
input_module.addImport("primitives", primitives_module);
const output_module = b.createModule(.{
.root_source_file = b.path("src/stateless/output.zig"),
.target = target,
.optimize = optimize,
});
output_module.addImport("primitives", primitives_module);
const hardfork_module = b.createModule(.{
.root_source_file = b.path("src/stateless/hardfork.zig"),
.target = target,
.optimize = optimize,
});
hardfork_module.addImport("primitives", primitives_module);
const rlp_decode_module = b.createModule(.{
.root_source_file = b.path("src/stateless/rlp_decode.zig"),
.target = target,
.optimize = optimize,
});
rlp_decode_module.addImport("primitives", primitives_module);
rlp_decode_module.addImport("input", input_module);
// ── MPT modules ───────────────────────────────────────────────────────────
const mpt_module = b.createModule(.{
.root_source_file = b.path("src/stateless/mpt/main.zig"),
.target = target,
.optimize = optimize,
});
mpt_module.addImport("primitives", primitives_module);
mpt_module.addImport("input", input_module);
mpt_module.addImport("accelerators", accelerators_module);
// Wire deferred mpt dependency into rlp_decode.
rlp_decode_module.addImport("mpt", mpt_module);
// ── Executor ──────────────────────────────────────────────────────────────
const executor_types_module = b.createModule(.{
.root_source_file = b.path("src/stateless/executor/types.zig"),
.target = target,
.optimize = optimize,
});
const db_module = b.createModule(.{
.root_source_file = b.path("src/stateless/db/main.zig"),
.target = target,
.optimize = optimize,
});
db_module.addImport("primitives", primitives_module);
db_module.addImport("state", state_module);
db_module.addImport("bytecode", bytecode_module);
db_module.addImport("mpt", mpt_module);
db_module.addImport("executor_types", executor_types_module);
const executor_module = b.createModule(.{
.root_source_file = b.path("src/stateless/executor/main.zig"),
.target = target,
.optimize = optimize,
});
executor_module.addImport("executor_types", executor_types_module);
executor_module.addImport("zesu_allocator", zesu_allocator_module);
executor_module.addImport("primitives", primitives_module);
executor_module.addImport("input", input_module);
executor_module.addImport("output", output_module);
executor_module.addImport("mpt", mpt_module);
executor_module.addImport("rlp_decode", rlp_decode_module);
executor_module.addImport("hardfork", hardfork_module);
executor_module.addImport("db", db_module);
executor_module.addImport("context", context_module);
executor_module.addImport("state", state_module);
executor_module.addImport("bytecode", bytecode_module);
executor_module.addImport("database", database_module);
executor_module.addImport("handler", handler_module);
executor_module.addImport("precompile", precompile_module);
executor_module.addImport("accelerators", accelerators_module);
// ── I/O module ────────────────────────────────────────────────────────────
const zkvm_io_module = b.createModule(.{
.root_source_file = b.path("src/io/interface.zig"),
.target = target,
.optimize = optimize,
});
// ── SSZ helper modules ────────────────────────────────────────────────────
const ssz_decode_module = b.createModule(.{
.root_source_file = b.path("src/stateless/stateless/ssz.zig"),
.target = target,
.optimize = optimize,
});
ssz_decode_module.addImport("input", input_module);
ssz_decode_module.addImport("rlp_decode", rlp_decode_module);
const ssz_output_module = b.createModule(.{
.root_source_file = b.path("src/stateless/stateless/ssz_output.zig"),
.target = target,
.optimize = optimize,
});
ssz_output_module.addImport("input", input_module);
// ── zevm_stateless binary ─────────────────────────────────────────────────
const stateless_exe = b.addExecutable(.{
.name = "zesu",
.root_module = b.createModule(.{
.root_source_file = b.path("src/stateless/stateless/main.zig"),
.target = target,
.optimize = optimize,
}),
});
stateless_exe.root_module.addImport("rlp_decode", rlp_decode_module);
stateless_exe.root_module.addImport("input", input_module);
stateless_exe.root_module.addImport("mpt", mpt_module);
stateless_exe.root_module.addImport("executor", executor_module);
stateless_exe.root_module.addImport("zesu_allocator", zesu_allocator_module);
stateless_exe.root_module.addImport("zkvm_io", zkvm_io_module);
addCryptoLibraries(stateless_exe, crypto_include, libblst_path, libmcl_path, is_linux);
b.installArtifact(stateless_exe);
addRunStep(b, "run", "Run the zevm_stateless app", stateless_exe, &.{});
// ── t8n: Ethereum State Transition Tool ───────────────────────────────────
const t8n_input_module = b.createModule(.{
.root_source_file = b.path("tools/t8n/input.zig"),
.target = target,
.optimize = optimize,
});
t8n_input_module.addImport("executor", executor_module);
const t8n_exe = b.addExecutable(.{
.name = "t8n",
.root_module = b.createModule(.{
.root_source_file = b.path("tools/t8n/main.zig"),
.target = target,
.optimize = optimize,
}),
});
t8n_exe.root_module.addImport("executor", executor_module);
t8n_exe.root_module.addImport("hardfork", hardfork_module);
addCryptoLibraries(t8n_exe, crypto_include, libblst_path, libmcl_path, is_linux);
b.installArtifact(t8n_exe);
addRunStep(b, "t8n", "Run the t8n state transition tool", t8n_exe, &.{});
// ── spec-test-runner ──────────────────────────────────────────────────────
const spec_test_exe = b.addExecutable(.{
.name = "spec-test-runner",
.root_module = b.createModule(.{
.root_source_file = b.path("tools/spec_test/main.zig"),
.target = target,
.optimize = optimize,
}),
});
spec_test_exe.root_module.addImport("t8n_input", t8n_input_module);
spec_test_exe.root_module.addImport("executor", executor_module);
spec_test_exe.root_module.addImport("hardfork", hardfork_module);
addCryptoLibraries(spec_test_exe, crypto_include, libblst_path, libmcl_path, is_linux);
b.installArtifact(spec_test_exe);
addRunStep(b, "state-tests", "Run execution-spec-tests state fixtures", spec_test_exe, &.{});
// ── blockchain-test-runner ────────────────────────────────────────────────
const blockchain_runner_module = b.createModule(.{
.root_source_file = b.path("tools/blockchain_test/runner.zig"),
.target = target,
.optimize = optimize,
});
blockchain_runner_module.addImport("primitives", primitives_module);
blockchain_runner_module.addImport("executor", executor_module);
blockchain_runner_module.addImport("mpt", mpt_module);
blockchain_runner_module.addImport("hardfork", hardfork_module);
const bc_test_exe = b.addExecutable(.{
.name = "blockchain-test-runner",
.root_module = b.createModule(.{
.root_source_file = b.path("tools/blockchain_test/main.zig"),
.target = target,
.optimize = optimize,
}),
});
bc_test_exe.root_module.addImport("runner", blockchain_runner_module);
addCryptoLibraries(bc_test_exe, crypto_include, libblst_path, libmcl_path, is_linux);
b.installArtifact(bc_test_exe);
addRunStep(b, "blockchain-tests", "Run Ethereum blockchain test fixtures", bc_test_exe, &.{});
// ── zkevm-blockchain-test-runner ──────────────────────────────────────────
const zkevm_test_exe = b.addExecutable(.{
.name = "zkevm-blockchain-test-runner",
.root_module = b.createModule(.{
.root_source_file = b.path("tools/zkevm_test/main.zig"),
.target = target,
.optimize = optimize,
}),
});
zkevm_test_exe.root_module.addImport("ssz_decode", ssz_decode_module);
zkevm_test_exe.root_module.addImport("ssz_output", ssz_output_module);
zkevm_test_exe.root_module.addImport("executor", executor_module);
addCryptoLibraries(zkevm_test_exe, crypto_include, libblst_path, libmcl_path, is_linux);
b.installArtifact(zkevm_test_exe);
addRunStep(b, "zkevm-tests", "Run zkevm blockchain test fixtures", zkevm_test_exe, &.{ "--fixtures", "spec-tests/fixtures/zkevm/blockchain_tests" });
// ── hive-rlp: Hive consume-rlp execution client ───────────────────────────
const hive_exe = b.addExecutable(.{
.name = "hive-rlp",
.root_module = b.createModule(.{
.root_source_file = b.path("tools/hive/main.zig"),
.target = target,
.optimize = optimize,
}),
});
hive_exe.root_module.addImport("primitives", primitives_module);
hive_exe.root_module.addImport("executor", executor_module);
hive_exe.root_module.addImport("hardfork", hardfork_module);
hive_exe.root_module.addImport("mpt", mpt_module);
addCryptoLibraries(hive_exe, crypto_include, libblst_path, libmcl_path, is_linux);
b.installArtifact(hive_exe);
b.step("hive-rlp", "Build and install the Hive consume-rlp client").dependOn(b.getInstallStep());
// ── Tests ─────────────────────────────────────────────────────────────────
const test_step = b.step("test", "Run all unit tests");
for ([_]struct { m: *std.Build.Module, name: []const u8 }{
.{ .m = precompile_module, .name = "precompile" },
.{ .m = interpreter_module, .name = "interpreter" },
.{ .m = handler_module, .name = "handler" },
.{ .m = mpt_module, .name = "mpt" },
}) |t| {
const tst = b.addTest(.{ .root_module = t.m });
_ = t.name;
addCryptoLibraries(tst, crypto_include, libblst_path, libmcl_path, is_linux);
test_step.dependOn(&b.addRunArtifact(tst).step);
}
// MPT integration tests
{
const m = b.createModule(.{
.root_source_file = b.path("src/stateless/mpt/test.zig"),
.target = target,
.optimize = optimize,
});
m.addImport("primitives", primitives_module);
m.addImport("mpt", mpt_module);
m.addImport("input", input_module);
const tst = b.addTest(.{ .root_module = m });
addCryptoLibraries(tst, crypto_include, libblst_path, libmcl_path, is_linux);
test_step.dependOn(&b.addRunArtifact(tst).step);
}
// WitnessDatabase integration tests
{
const m = b.createModule(.{
.root_source_file = b.path("src/stateless/db/test.zig"),
.target = target,
.optimize = optimize,
});
m.addImport("primitives", primitives_module);
m.addImport("state", state_module);
m.addImport("bytecode", bytecode_module);
m.addImport("mpt", mpt_module);
m.addImport("input", input_module);
m.addImport("db", db_module);
const tst = b.addTest(.{ .root_module = m });
addCryptoLibraries(tst, crypto_include, libblst_path, libmcl_path, is_linux);
test_step.dependOn(&b.addRunArtifact(tst).step);
}
// ── Fixture fetch steps ───────────────────────────────────────────────────
const fetch_fixtures_step = b.step("fetch-fixtures", "Download execution-spec-tests bal@v5.5.1 fixtures");
fetch_fixtures_step.dependOn(&b.addSystemCommand(&.{
"sh", "-c",
"rm -rf spec-tests/fixtures && " ++
"mkdir -p spec-tests/fixtures && " ++
"echo 'Downloading execution-spec-tests bal@v5.5.1 fixtures...' && " ++
"curl -fL " ++
"https://github.com/ethereum/execution-spec-tests/releases/download/bal%40v5.5.1/fixtures_bal.tar.gz " ++
"| tar xz --strip-components=1 -C spec-tests/fixtures/ && " ++
"echo 'Done. Fixtures extracted to spec-tests/fixtures/'",
}).step);
const fetch_zkevm_step = b.step("fetch-zkevm-fixtures", "Download zkevm@v0.3.3 execution-spec-tests fixtures");
fetch_zkevm_step.dependOn(&b.addSystemCommand(&.{
"sh", "-c",
"rm -rf spec-tests/fixtures/zkevm && " ++
"mkdir -p spec-tests/fixtures/zkevm && " ++
"echo 'Downloading zkevm@v0.3.3 fixtures...' && " ++
"curl -fL " ++
"https://github.com/ethereum/execution-spec-tests/releases/download/zkevm%40v0.3.3/fixtures_zkevm.tar.gz " ++
"| tar xz --strip-components=1 -C spec-tests/fixtures/zkevm/ && " ++
"echo 'Done. Fixtures extracted to spec-tests/fixtures/zkevm/'",
}).step);
}