-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.zig
More file actions
292 lines (265 loc) · 11.1 KB
/
build.zig
File metadata and controls
292 lines (265 loc) · 11.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
const std = @import("std");
/// Link Metal frameworks on a module (Apple Silicon only).
fn linkMetalFrameworks(module: *std.Build.Module) void {
const opts: std.Build.Module.LinkFrameworkOptions = .{};
module.linkFramework("Metal", opts);
module.linkFramework("CoreGraphics", opts);
module.linkFramework("Foundation", opts);
}
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const is_apple_silicon = target.result.os.tag == .macos and
target.result.cpu.arch == .aarch64;
// Main library
const lib = b.addLibrary(.{
.name = "zolt",
.root_module = b.createModule(.{
.root_source_file = b.path("src/root.zig"),
.target = target,
.optimize = optimize,
}),
});
if (is_apple_silicon) linkMetalFrameworks(lib.root_module);
b.installArtifact(lib);
// Export zolt module for dependency consumption
_ = b.addModule("zolt", .{
.root_source_file = b.path("src/root.zig"),
.target = target,
.optimize = optimize,
});
// Main executable (for testing/demo)
const exe = b.addExecutable(.{
.name = "zolt",
.root_module = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
}),
});
if (is_apple_silicon) linkMetalFrameworks(exe.root_module);
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 the zolt executable");
run_step.dependOn(&run_cmd.step);
// Unit tests for the library
const lib_unit_tests = b.addTest(.{
.root_module = b.createModule(.{
.root_source_file = b.path("src/root.zig"),
.target = target,
.optimize = optimize,
}),
});
if (is_apple_silicon) linkMetalFrameworks(lib_unit_tests.root_module);
const run_lib_unit_tests = b.addRunArtifact(lib_unit_tests);
// Unit tests for the executable
const exe_unit_tests = b.addTest(.{
.root_module = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
}),
});
if (is_apple_silicon) linkMetalFrameworks(exe_unit_tests.root_module);
const run_exe_unit_tests = b.addRunArtifact(exe_unit_tests);
// Test step
const test_step = b.step("test", "Run unit tests");
test_step.dependOn(&run_lib_unit_tests.step);
test_step.dependOn(&run_exe_unit_tests.step);
// Example: Field Arithmetic
const field_example = b.addExecutable(.{
.name = "example-field",
.root_module = b.createModule(.{
.root_source_file = b.path("examples/field_arithmetic.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "zolt", .module = lib.root_module },
},
}),
});
const run_field_example = b.addRunArtifact(field_example);
const field_example_step = b.step("example-field", "Run field arithmetic example");
field_example_step.dependOn(&run_field_example.step);
// Example: Simple Proof
const proof_example = b.addExecutable(.{
.name = "example-proof",
.root_module = b.createModule(.{
.root_source_file = b.path("examples/simple_proof.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "zolt", .module = lib.root_module },
},
}),
});
const run_proof_example = b.addRunArtifact(proof_example);
const proof_example_step = b.step("example-proof", "Run simple proof example");
proof_example_step.dependOn(&run_proof_example.step);
// Benchmark: ThreadPool vs Rayon
const bench_tp = b.addExecutable(.{
.name = "bench-tp",
.root_module = b.createModule(.{
.root_source_file = b.path("bench/threadpool_vs_rayon/main.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "zolt", .module = lib.root_module },
},
}),
});
b.installArtifact(bench_tp);
const run_bench_tp = b.addRunArtifact(bench_tp);
const bench_tp_step = b.step("bench-tp", "Run ThreadPool micro-benchmark");
bench_tp_step.dependOn(&run_bench_tp.step);
// Example: RISC-V Emulation
const riscv_example = b.addExecutable(.{
.name = "example-riscv",
.root_module = b.createModule(.{
.root_source_file = b.path("examples/risc_v_emulation.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "zolt", .module = lib.root_module },
},
}),
});
const run_riscv_example = b.addRunArtifact(riscv_example);
const riscv_example_step = b.step("example-riscv", "Run RISC-V emulation example");
riscv_example_step.dependOn(&run_riscv_example.step);
// Example: HyperKZG Commitment
const hyperkzg_example = b.addExecutable(.{
.name = "example-hyperkzg",
.root_module = b.createModule(.{
.root_source_file = b.path("examples/hyperkzg_commitment.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "zolt", .module = lib.root_module },
},
}),
});
const run_hyperkzg_example = b.addRunArtifact(hyperkzg_example);
const hyperkzg_example_step = b.step("example-hyperkzg", "Run HyperKZG commitment example");
hyperkzg_example_step.dependOn(&run_hyperkzg_example.step);
// Example: Sumcheck Protocol
const sumcheck_example = b.addExecutable(.{
.name = "example-sumcheck",
.root_module = b.createModule(.{
.root_source_file = b.path("examples/sumcheck_protocol.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "zolt", .module = lib.root_module },
},
}),
});
const run_sumcheck_example = b.addRunArtifact(sumcheck_example);
const sumcheck_example_step = b.step("example-sumcheck", "Run sumcheck protocol example");
sumcheck_example_step.dependOn(&run_sumcheck_example.step);
// Example: Full Pipeline
const pipeline_example = b.addExecutable(.{
.name = "example-pipeline",
.root_module = b.createModule(.{
.root_source_file = b.path("examples/full_pipeline.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "zolt", .module = lib.root_module },
},
}),
});
const run_pipeline_example = b.addRunArtifact(pipeline_example);
const pipeline_example_step = b.step("example-pipeline", "Run full proving pipeline example");
pipeline_example_step.dependOn(&run_pipeline_example.step);
// Benchmark: Field Arithmetic
const field_bench = b.addExecutable(.{
.name = "field-bench",
.root_module = b.createModule(.{
.root_source_file = b.path("examples/field_bench.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "zolt", .module = lib.root_module },
},
}),
});
const run_field_bench = b.addRunArtifact(field_bench);
const field_bench_step = b.step("bench-field", "Run field arithmetic benchmark");
field_bench_step.dependOn(&run_field_bench.step);
// Benchmark: ARM64 field verification
const arm64_verify = b.addExecutable(.{
.name = "arm64-verify",
.root_module = b.createModule(.{
.root_source_file = b.path("examples/arm64_verify.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "zolt", .module = lib.root_module },
},
}),
});
const run_arm64_verify = b.addRunArtifact(arm64_verify);
const arm64_verify_step = b.step("bench-arm64", "Run ARM64 field verification benchmark");
arm64_verify_step.dependOn(&run_arm64_verify.step);
// Benchmark: GPU vs CPU
const gpu_bench = b.addExecutable(.{
.name = "gpu-bench",
.root_module = b.createModule(.{
.root_source_file = b.path("examples/gpu_bench.zig"),
.target = target,
.optimize = .ReleaseFast,
.imports = &.{
.{ .name = "zolt", .module = lib.root_module },
},
}),
});
const run_gpu_bench = b.addRunArtifact(gpu_bench);
const gpu_bench_step = b.step("bench-gpu", "Run GPU vs CPU benchmark");
gpu_bench_step.dependOn(&run_gpu_bench.step);
// Optional: rebuild Metal shaders from .metal sources
// Usage: zig build metal-shaders
const metal_step = b.step("metal-shaders", "Rebuild Metal shader library from .metal sources");
if (is_apple_silicon) {
const dev_dir = "/Applications/Xcode.app/Contents/Developer";
const shader_dir = "src/gpu/shaders";
const include_flag = b.pathFromRoot(shader_dir);
const compile_smoke = b.addSystemCommand(&.{ "xcrun", "metal", "-c", "-I" });
compile_smoke.setEnvironmentVariable("DEVELOPER_DIR", dev_dir);
compile_smoke.addArg(include_flag);
compile_smoke.addFileArg(b.path(shader_dir ++ "/smoke.metal"));
compile_smoke.addArg("-o");
const smoke_air = compile_smoke.addOutputFileArg("smoke.air");
const compile_field = b.addSystemCommand(&.{ "xcrun", "metal", "-c", "-I" });
compile_field.setEnvironmentVariable("DEVELOPER_DIR", dev_dir);
compile_field.addArg(include_flag);
compile_field.addFileArg(b.path(shader_dir ++ "/field.metal"));
compile_field.addArg("-o");
const field_air = compile_field.addOutputFileArg("field.air");
const compile_poly = b.addSystemCommand(&.{ "xcrun", "metal", "-c", "-I" });
compile_poly.setEnvironmentVariable("DEVELOPER_DIR", dev_dir);
compile_poly.addArg(include_flag);
compile_poly.addFileArg(b.path(shader_dir ++ "/poly.metal"));
compile_poly.addArg("-o");
const poly_air = compile_poly.addOutputFileArg("poly.air");
const compile_msm = b.addSystemCommand(&.{ "xcrun", "metal", "-c", "-I" });
compile_msm.setEnvironmentVariable("DEVELOPER_DIR", dev_dir);
compile_msm.addArg(include_flag);
compile_msm.addFileArg(b.path(shader_dir ++ "/msm.metal"));
compile_msm.addArg("-o");
const msm_air = compile_msm.addOutputFileArg("msm.air");
const metal_link = b.addSystemCommand(&.{ "xcrun", "metallib" });
metal_link.setEnvironmentVariable("DEVELOPER_DIR", dev_dir);
metal_link.addFileArg(smoke_air);
metal_link.addFileArg(field_air);
metal_link.addFileArg(poly_air);
metal_link.addFileArg(msm_air);
metal_link.addArgs(&.{ "-o", b.pathFromRoot(shader_dir ++ "/shaders.metallib") });
metal_step.dependOn(&metal_link.step);
}
}