-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.zig
More file actions
170 lines (147 loc) · 6.97 KB
/
Copy pathbuild.zig
File metadata and controls
170 lines (147 loc) · 6.97 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
const std = @import("std");
const Bundle = struct {
quic_shim: *std.Build.Module,
zquic: *std.Build.Module,
compat: *std.Build.Module,
zig_varint: *std.Build.Module,
};
fn addZquicQuicModule(
b: *std.Build,
target: std.Build.ResolvedTarget,
optimize: std.builtin.OptimizeMode,
shadow: bool,
) Bundle {
// Forward `.shadow` to zquic so this instantiation's option set matches the
// one zig-libp2p passes (`b.dependency("zquic", .{..., .shadow })`). Zig
// keys dependency deduplication on the option set, so an identical set lets
// a downstream that pulls both zig-ethp2p and zig-libp2p resolve a single
// shared zquic module instead of two colliding ones.
const zquic_pkg = b.dependency("zquic", .{ .target = target, .optimize = optimize, .shadow = shadow });
const zquic_mod = zquic_pkg.module("zquic");
// Shared multiformats/QUIC varint codec (see `src/wire/varint.zig`).
const zig_varint_pkg = b.dependency("zig_varint", .{ .target = target, .optimize = optimize });
const zig_varint_mod = zig_varint_pkg.module("zig_varint");
// Zig 0.15 → 0.16 std-library compatibility shims (see `src/compat.zig`).
const compat = b.createModule(.{
.root_source_file = b.path("src/compat.zig"),
.target = target,
.optimize = optimize,
});
const quic_shim = b.addModule("quic", .{
.root_source_file = b.path("src/transport/zquic_quic_shim.zig"),
.target = target,
.optimize = optimize,
});
quic_shim.addImport("zquic", zquic_mod);
quic_shim.addImport("compat", compat);
return .{ .quic_shim = quic_shim, .zquic = zquic_mod, .compat = compat, .zig_varint = zig_varint_mod };
}
fn wireModule(m: *std.Build.Module, bundle: Bundle) void {
m.addImport("quic", bundle.quic_shim);
m.addImport("compat", bundle.compat);
m.addImport("zig_varint", bundle.zig_varint);
}
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
// Forwarded verbatim to the zquic dependency (mirrors zig-libp2p's
// `-Dshadow`); keep the option name/default identical so both instantiate
// zquic with the same option set and Zig deduplicates it to one module.
const shadow = b.option(bool, "shadow", "Forward -Dshadow to the zquic dependency (Shadow simulator build)") orelse false;
if (target.result.os.tag == .windows) {
std.debug.panic("zig-ethp2p does not support Windows targets (zquic QUIC stack is tested on Unix).", .{});
}
const bundle = addZquicQuicModule(b, target, optimize, shadow);
const mod = b.addModule("zig_ethp2p", .{
.root_source_file = b.path("src/root.zig"),
.target = target,
.optimize = optimize,
});
wireModule(mod, bundle);
const lib = b.addLibrary(.{
.name = "zig_ethp2p",
.root_module = mod,
});
b.installArtifact(lib);
const lib_tests_mod = b.createModule(.{
.root_source_file = b.path("src/root.zig"),
.target = target,
.optimize = optimize,
});
wireModule(lib_tests_mod, bundle);
const lib_tests = b.addTest(.{ .root_module = lib_tests_mod });
const run_lib_tests = b.addRunArtifact(lib_tests);
const test_step = b.step("test", "Run library tests (full suite, same as local dev)");
test_step.dependOn(&run_lib_tests.step);
const simtest_step = b.step("simtest", "Abstract RS mesh (simnet-parity); same binary as test");
simtest_step.dependOn(&run_lib_tests.step);
const run_stress = b.addRunArtifact(lib_tests);
run_stress.setEnvironmentVariable("ZIG_ETHP2P_STRESS", "1");
run_stress.has_side_effects = true;
const stress_step = b.step("test-stress", "Run tests with ZIG_ETHP2P_STRESS=1 (longer RS mesh, 8-/16-node rings)");
stress_step.dependOn(&run_stress.step);
// --- CI splits ---
const ci_target = target;
const ci_opt: std.builtin.OptimizeMode = .Debug;
const ci_tsan = true;
const bundle_ci = addZquicQuicModule(b, ci_target, ci_opt, shadow);
const broadcast_tests_mod = b.createModule(.{
.root_source_file = b.path("src/ci_root_broadcast.zig"),
.target = ci_target,
.optimize = ci_opt,
.sanitize_thread = ci_tsan,
});
wireModule(broadcast_tests_mod, bundle_ci);
const broadcast_tests = b.addTest(.{ .root_module = broadcast_tests_mod });
const run_broadcast_tests = b.addRunArtifact(broadcast_tests);
run_broadcast_tests.has_side_effects = true;
const test_broadcast_step = b.step("test-broadcast", "Wire + layer + broadcast tests (ethp2p broadcast/ parity; TSan ≈ go -race)");
test_broadcast_step.dependOn(&run_broadcast_tests.step);
const sim_rs_tests_mod = b.createModule(.{
.root_source_file = b.path("src/ci_root_sim_rs.zig"),
.target = ci_target,
.optimize = ci_opt,
.sanitize_thread = ci_tsan,
});
wireModule(sim_rs_tests_mod, bundle_ci);
const sim_rs_tests = b.addTest(.{ .root_module = sim_rs_tests_mod });
const run_sim_rs = b.addRunArtifact(sim_rs_tests);
run_sim_rs.has_side_effects = true;
const test_sim_rs_step = b.step("test-sim-rs", "RS abstract mesh tests (ethp2p sim RS simnet job parity; TSan)");
test_sim_rs_step.dependOn(&run_sim_rs.step);
const sim_gs_tests_mod = b.createModule(.{
.root_source_file = b.path("src/ci_root_sim_gossipsub.zig"),
.target = ci_target,
.optimize = ci_opt,
.sanitize_thread = ci_tsan,
});
wireModule(sim_gs_tests_mod, bundle_ci);
const sim_gs_tests = b.addTest(.{ .root_module = sim_gs_tests_mod });
const run_sim_gs = b.addRunArtifact(sim_gs_tests);
run_sim_gs.has_side_effects = true;
const test_sim_gs_step = b.step("test-sim-gossipsub", "Gossipsub sim tests (ethp2p sim Gossipsub simnet job parity; TSan)");
test_sim_gs_step.dependOn(&run_sim_gs.step);
const stress_ci_mod = b.createModule(.{
.root_source_file = b.path("src/root.zig"),
.target = ci_target,
.optimize = ci_opt,
.sanitize_thread = ci_tsan,
});
wireModule(stress_ci_mod, bundle_ci);
const run_stress_ci = b.addTest(.{ .root_module = stress_ci_mod });
const run_stress_ci_run = b.addRunArtifact(run_stress_ci);
run_stress_ci_run.setEnvironmentVariable("ZIG_ETHP2P_STRESS", "1");
run_stress_ci_run.has_side_effects = true;
const stress_ci_step = b.step("test-stress-ci", "Full suite + ZIG_ETHP2P_STRESS (for main-only large-network job; TSan)");
stress_ci_step.dependOn(&run_stress_ci_run.step);
const quic_ci_mod = b.createModule(.{
.root_source_file = b.path("src/ci_root_quic.zig"),
.target = ci_target,
.optimize = ci_opt,
});
wireModule(quic_ci_mod, bundle_ci);
const quic_ci_tests = b.addTest(.{ .root_module = quic_ci_mod });
const run_quic_ci = b.addRunArtifact(quic_ci_tests);
const test_quic_step = b.step("test-quic", "Transport QUIC tests (zquic handshake + stream framing)");
test_quic_step.dependOn(&run_quic_ci.step);
}