Repository navigation
Expand file tree
/
Copy pathbuild.zig
More file actions
114 lines (95 loc) · 4.32 KB
/
Copy pathbuild.zig
File metadata and controls
114 lines (95 loc) · 4.32 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
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
// eth.zig dependency (replaces zabi for contract interaction layer)
const eth_dep = b.dependency("eth", .{
.target = target,
.optimize = optimize,
});
const eth_module = eth_dep.module("eth");
// Main library module (includes eth for contract interaction)
const sdk_module = b.addModule("perpcity_sdk", .{
.root_source_file = b.path("src/root.zig"),
.target = target,
.optimize = optimize,
});
sdk_module.addImport("eth", eth_module);
// Math + HFT module (math_root.zig) for the fast unit-test build. It now
// depends on eth so the math layer can use eth.zig's optimized u256 limb
// arithmetic (e.g. TickMath through `uint256.divLimbsDirect`) instead of the
// builtin `u256` operators, which lower to slow software routines on aarch64.
const math_module = b.createModule(.{
.root_source_file = b.path("src/math_root.zig"),
.target = target,
.optimize = optimize,
});
math_module.addImport("eth", eth_module);
// Unit tests -- pure math, no eth
const unit_test_mod = b.createModule(.{
.root_source_file = b.path("tests/unit_tests.zig"),
.target = target,
.optimize = optimize,
});
unit_test_mod.addImport("perpcity_sdk", math_module);
const unit_tests = b.addTest(.{
.root_module = unit_test_mod,
});
const run_unit_tests = b.addRunArtifact(unit_tests);
const test_step = b.step("test", "Run unit tests");
test_step.dependOn(&run_unit_tests.step);
// Contract-layer tests -- exercise the read path through the ChainClient
// seam with an in-memory mock (no network / Anvil). Needs eth for ABI
// encoding of canned return bytes.
const contract_test_mod = b.createModule(.{
.root_source_file = b.path("tests/contract_tests.zig"),
.target = target,
.optimize = optimize,
});
contract_test_mod.addImport("perpcity_sdk", sdk_module);
contract_test_mod.addImport("eth", eth_module);
const contract_tests = b.addTest(.{
.root_module = contract_test_mod,
});
const run_contract_tests = b.addRunArtifact(contract_tests);
const contract_step = b.step("contract-test", "Run contract-layer unit tests (in-memory mock, no network)");
contract_step.dependOn(&run_contract_tests.step);
// The mock runs entirely in-process, so the default `test` step covers the
// contract-layer tests too (CI's `zig build test` picks them up).
test_step.dependOn(&run_contract_tests.step);
// Integration tests -- needs eth for contract interaction
const integration_test_mod = b.createModule(.{
.root_source_file = b.path("tests/integration_tests.zig"),
.target = target,
.optimize = optimize,
});
integration_test_mod.addImport("perpcity_sdk", sdk_module);
integration_test_mod.addImport("eth", eth_module);
const integration_tests = b.addTest(.{
.root_module = integration_test_mod,
});
const run_integration_tests = b.addRunArtifact(integration_tests);
const integration_step = b.step("integration-test", "Run integration tests (requires Anvil + compiled mocks)");
integration_step.dependOn(&run_integration_tests.step);
// Example market view module
const example_view_mod = b.createModule(.{
.root_source_file = b.path("examples/view_market.zig"),
.target = target,
.optimize = optimize,
});
example_view_mod.addImport("perpcity_sdk", sdk_module);
example_view_mod.addImport("eth", eth_module);
// First executable in the repo
const example_view = b.addExecutable(.{
.name = "view_market",
.root_module = example_view_mod,
});
// Compile target for the examples. Run by CI.
const examples_step = b.step("examples", "Build all examples");
examples_step.dependOn(&example_view.step);
// Build and run the view example. Makes a read-only network call. Needs environment vars PERP_ADDRESS
// and RPC_URL
const run_example_view = b.addRunArtifact(example_view);
const run_example_view_step = b.step("run-example-view", "Run the view_market example");
run_example_view_step.dependOn(&run_example_view.step);
}