-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
229 lines (177 loc) · 8.1 KB
/
Makefile
File metadata and controls
229 lines (177 loc) · 8.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
.PHONY: deps deps-linux deps-macos prepare-test-data compile-programs-asm compile-programs-rust compile-bench \
compile-programs clean-asm clean-rust clean-bench clean-shared clean test test-asm test-no-compile \
test-asm-no-compile test-rust test-rust-no-compile test-executor flamegraph-prover \
test-fast test-prover test-prover-all test-disk-spill test-math-cuda bench-math-cuda build check clippy fmt lint
UNAME := $(shell uname)
deps:
ifeq ($(UNAME), Linux)
deps: deps-linux
endif
ifeq ($(UNAME), Darwin)
deps: deps-macos
endif
deps-linux:
@# TODO
@echo "not yet implemented"
@exit 1
deps-macos:
brew tap riscv-software-src/riscv
brew install riscv-software-src/riscv/riscv-gnu-toolchain
ASM_PROGRAMS_DIR=./executor/programs/asm
ASM_ARTIFACTS_DIR=./executor/program_artifacts/asm
RUST_PROGRAMS_DIR=./executor/programs/rust
RUST_ARTIFACTS_DIR=./executor/program_artifacts/rust
BENCH_PROGRAMS_DIR=./executor/programs/bench
BENCH_ARTIFACTS_DIR=./executor/program_artifacts/bench
SHARED_TARGET_DIR=./executor/shared_target
ASM_PROGRAMS = $(wildcard $(ASM_PROGRAMS_DIR)/*.s)
RUST_PROGRAM_DIRS := $(dir $(wildcard $(RUST_PROGRAMS_DIR)/*/Cargo.toml))
RUST_PROGRAMS := $(notdir $(basename $(RUST_PROGRAM_DIRS:%/=%)))
RUST_ARTIFACTS := $(addprefix $(RUST_ARTIFACTS_DIR)/, $(addsuffix .elf, $(RUST_PROGRAMS)))
BENCH_PROGRAM_DIRS := $(dir $(wildcard $(BENCH_PROGRAMS_DIR)/*/Cargo.toml))
BENCH_PROGRAMS := $(notdir $(basename $(BENCH_PROGRAM_DIRS:%/=%)))
BENCH_ARTIFACTS := $(addprefix $(BENCH_ARTIFACTS_DIR)/, $(addsuffix .elf, $(BENCH_PROGRAMS)))
ETHREX_FILE := executor/tests/ethrex_hoodi.bin
ETHREX_URL := https://lambda.alignedlayer.com/ethrex_hoodi.bin
# Override with: make ... SYSROOT_DIR=$HOME/.lambda-vm-sysroot
# to install the sysroot in a user-writable location and avoid sudo.
SYSROOT_DIR ?= /opt/lambda-vm-sysroot
SYSROOT_TARBALL := /tmp/lambda-vm-sysroot-rv64im.tar.gz
SYSROOT_URL := https://lambda.alignedlayer.com/lambda-vm-sysroot-rv64im.tar.gz
# CFLAGS for ckzg / ethrex guest programs: overrides the hardcoded `/opt/lambda-vm-sysroot`
# in their .cargo/config.toml so cargo picks up our $(SYSROOT_DIR) instead.
# $(abspath ...) because the build rule cd's into the program dir before invoking cargo.
SYSROOT_CFLAGS := --target=riscv64 -march=rv64im -mabi=lp64 --sysroot=$(abspath $(SYSROOT_DIR))
# Custom RV64IM target spec location
RV64_TARGET_SPEC=$(CURDIR)/executor/programs/riscv64im-lambda-vm-elf.json
.PHONY: test prepare-test-data prepare-sysroot
prepare-test-data:
@if [ ! -f "$(ETHREX_FILE)" ]; then \
echo "Downloading ethrex_hoodi.bin..."; \
curl -L "$(ETHREX_URL)" -o "$(ETHREX_FILE)"; \
else \
echo "ethrex_hoodi.bin already exists"; \
fi
prepare-sysroot:
@if [ -d "$(SYSROOT_DIR)/include" ] && [ -d "$(SYSROOT_DIR)/lib" ]; then \
echo "Sysroot already exists at $(SYSROOT_DIR)"; \
else \
echo "Downloading lambda-vm-sysroot-rv64im.tar.gz..."; \
curl -L "$(SYSROOT_URL)" -o "$(SYSROOT_TARBALL)"; \
echo "Extracting sysroot to $(SYSROOT_DIR)..."; \
if mkdir -p "$(SYSROOT_DIR)" 2>/dev/null && [ -w "$(SYSROOT_DIR)" ]; then \
tar -xzf "$(SYSROOT_TARBALL)" -C "$(SYSROOT_DIR)" --strip-components=1 \
|| { rm -rf "$(SYSROOT_DIR)" "$(SYSROOT_TARBALL)"; exit 1; }; \
else \
echo "$(SYSROOT_DIR) is not writable; using sudo."; \
echo "Tip: re-run with SYSROOT_DIR=\$$HOME/.lambda-vm-sysroot to avoid sudo."; \
sudo mkdir -p "$(SYSROOT_DIR)" \
&& sudo tar -xzf "$(SYSROOT_TARBALL)" -C "$(SYSROOT_DIR)" --strip-components=1 \
|| { sudo rm -rf "$(SYSROOT_DIR)"; rm -f "$(SYSROOT_TARBALL)"; exit 1; }; \
fi; \
rm "$(SYSROOT_TARBALL)"; \
fi
# Note: the tarball rm above only runs on success — each error handler
# cleans up the tarball itself before `exit 1`.
compile-programs-asm:
@mkdir -p $(ASM_ARTIFACTS_DIR)
@set -e; for src in $(ASM_PROGRAMS); do \
echo "clang --target=riscv64 -fuse-ld=lld -nostdlib -Wl,-e,main $$src -o $(ASM_ARTIFACTS_DIR)/$$(basename $$src .s).elf"; \
clang --target=riscv64 -fuse-ld=lld -nostdlib -Wl,-e,main $$src -o $(ASM_ARTIFACTS_DIR)/$$(basename $$src .s).elf; \
done
compile-programs-rust: prepare-sysroot $(RUST_ARTIFACTS)
compile-bench: prepare-sysroot $(BENCH_ARTIFACTS)
compile-programs: compile-programs-asm compile-programs-rust compile-bench
# Compile rust (64-bit)
$(RUST_ARTIFACTS_DIR)/%.elf: $(RUST_PROGRAMS_DIR)/%/Cargo.toml
@mkdir -p $(RUST_ARTIFACTS_DIR)
cd $(RUST_PROGRAMS_DIR)/$* && \
CARGO_TARGET_DIR=$(abspath $(SHARED_TARGET_DIR)) \
CFLAGS_riscv64im_lambda_vm_elf="$(SYSROOT_CFLAGS)" \
rustup run nightly-2026-02-01 cargo build --release \
--target $(RV64_TARGET_SPEC) \
-Z build-std=core,alloc,std,compiler_builtins,panic_abort \
-Z build-std-features=compiler-builtins-mem \
-Z json-target-spec
cp $(SHARED_TARGET_DIR)/riscv64im-lambda-vm-elf/release/$* $@
# Compile rust benches (64-bit)
$(BENCH_ARTIFACTS_DIR)/%.elf: $(BENCH_PROGRAMS_DIR)/%/Cargo.toml
@mkdir -p $(BENCH_ARTIFACTS_DIR)
cd $(BENCH_PROGRAMS_DIR)/$* && \
CARGO_TARGET_DIR=$(abspath $(SHARED_TARGET_DIR)) \
CFLAGS_riscv64im_lambda_vm_elf="$(SYSROOT_CFLAGS)" \
rustup run nightly-2026-02-01 cargo build --release \
--target $(RV64_TARGET_SPEC) \
-Z build-std=core,alloc,std,compiler_builtins,panic_abort \
-Z build-std-features=compiler-builtins-mem \
-Z json-target-spec
cp $(SHARED_TARGET_DIR)/riscv64im-lambda-vm-elf/release/$* $@
clean-asm:
-rm -rf $(ASM_ARTIFACTS_DIR)
clean-rust:
-rm -rf $(RUST_ARTIFACTS_DIR)
clean-bench:
-rm -rf $(BENCH_ARTIFACTS_DIR)
clean-shared:
-rm -rf $(SHARED_TARGET_DIR)
clean: clean-asm clean-rust clean-bench clean-shared
test-executor: compile-programs test-no-compile
test-asm: compile-programs-asm test-asm-no-compile
test-asm-no-compile:
cargo test -p executor --test asm
test-rust: compile-programs-rust prepare-test-data
cargo test -p executor --test rust
test-rust-no-compile:
cargo test -p executor --test rust
test-no-compile: prepare-test-data
cargo test -p executor
test-flamegraph:
cargo test -p executor --test flamegraph
test: compile-programs prepare-test-data
cargo test
# === Quick test shortcuts ===
# Fast prover tests (skips ignored slow tests)
test-fast:
cargo test -p lambda-vm-prover -p stark -p executor -F stark/parallel
# Prover tests only
test-prover:
cargo test -p lambda-vm-prover
# Prover tests including slow ones
test-prover-all:
cargo test -p lambda-vm-prover -- --include-ignored
# Prover tests with debug-checks (shows bus balance report)
test-prover-debug:
cargo test -p lambda-vm-prover --features debug-checks -- --nocapture
# Disk-spill tests (stark + prover). FORCE_DISK_SPILL is required by the prover tests.
test-disk-spill:
cargo test --release -p stark --features disk-spill disk_spill
FORCE_DISK_SPILL=1 cargo test --release -p lambda-vm-prover --features disk-spill -- disk_spill count_table_lengths
# math-cuda parity tests (requires NVIDIA GPU + nvcc)
test-math-cuda:
cargo test -p math-cuda --release
# math-cuda quick microbench (median of 10 runs)
bench-math-cuda:
cargo test -p math-cuda --release --test bench_quick -- --ignored --nocapture
# Build all
build:
cargo build --workspace
# Check (faster than build, no codegen)
check:
cargo check --workspace
# === Linting ===
# op_ref: We pass big integers (U256/U384) and field elements by reference since operator
# impls delegate to &self internally, avoiding unnecessary 32-48 byte copies.
clippy:
cargo clippy --workspace --all-targets -- -D warnings -A clippy::op_ref
cargo clippy --workspace --all-targets --no-default-features --features lambda-vm-prover/debug-checks -- -D warnings -A clippy::op_ref
cargo clippy --workspace --all-targets --features lambda-vm-prover/disk-spill -- -D warnings -A clippy::op_ref
fmt:
cargo fmt --all
# Run clippy + fmt check (used by CI)
lint:
cargo fmt --check --all
cargo clippy --workspace --all-targets -- -D warnings -A clippy::op_ref
cargo clippy --workspace --all-targets --no-default-features --features lambda-vm-prover/debug-checks -- -D warnings -A clippy::op_ref
cargo clippy --workspace --all-targets --features lambda-vm-prover/disk-spill -- -D warnings -A clippy::op_ref
flamegraph-prover:
cd crypto/stark && samply record cargo bench --bench profile_prover --features parallel