forked from o1-labs/proof-systems
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
351 lines (307 loc) · 12.1 KB
/
Makefile
File metadata and controls
351 lines (307 loc) · 12.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
# Variables
# Known coverage limitations and issues:
# - https://github.com/rust-lang/rust/issues/79417
# - https://github.com/nextest-rs/nextest/issues/16
# FIXME: Update or remove the `codecov.yml` file to enable the `patch` coverage
# report and the corresponding PR check, once situation with the Rust's Doctests
# will be improved.
COVERAGE_ENV = CARGO_INCREMENTAL=0 RUSTFLAGS='-Cinstrument-coverage' RUSTDOCFLAGS="-Cinstrument-coverage" LLVM_PROFILE_FILE=$(shell pwd)/target/profraw/cargo-test-%p-%m.profraw
# FIXME: In latest 0.8.19+ -t CLI argument can accept comma separated list of
# custom output types, hence, no need in double invocation
GRCOV_CALL = grcov ./target/profraw --binary-path ./target/release/deps/ -s . --branch --ignore-not-existing --ignore "**/tests/**"
RISCV32_TOOLCHAIN_PATH = $(shell pwd)/_riscv32-gnu-toolchain
O1VM_RESOURCES_PATH = $(shell pwd)/o1vm/resources/programs
O1VM_RISCV32IM_SOURCE_DIR = ${O1VM_RESOURCES_PATH}/riscv32im/src
O1VM_RISCV32IM_SOURCE_FILES = $(wildcard ${O1VM_RISCV32IM_SOURCE_DIR}/*.S)
O1VM_RISCV32IM_BIN_DIR = ${O1VM_RESOURCES_PATH}/riscv32im/bin
O1VM_RISCV32IM_BIN_FILES = $(patsubst ${O1VM_RISCV32IM_SOURCE_DIR}/%.S,${O1VM_RISCV32IM_BIN_DIR}/%.o,${O1VM_RISCV32IM_SOURCE_FILES})
RISCV32_AS_FLAGS = --warn --fatal-warnings
OPTIMISM_MIPS_SOURCE_DIR = $(shell pwd)/o1vm/ethereum-optimism/cannon/mipsevm/open_mips_tests/test
OPTIMISM_MIPS_SOURCE_FILES = $(wildcard ${OPTIMISM_MIPS_SOURCE_DIR}/*.asm)
O1VM_MIPS_SOURCE_DIR = ${O1VM_RESOURCES_PATH}/mips/src
O1VM_MIPS_SOURCE_FILES = $(patsubst ${OPTIMISM_MIPS_SOURCE_DIR}/%.asm,${O1VM_MIPS_SOURCE_DIR}/%.asm,${OPTIMISM_MIPS_SOURCE_FILES})
O1VM_MIPS_BIN_DIR = ${O1VM_RESOURCES_PATH}/mips/bin
O1VM_MIPS_BIN_FILES = $(patsubst ${O1VM_MIPS_SOURCE_DIR}/%.asm,${O1VM_MIPS_BIN_DIR}/%.o,${O1VM_MIPS_SOURCE_FILES})
# MIPS toolchain configuration (can be overridden for different platforms)
MIPS_AS ?= mips-linux-gnu-as
MIPS_LD ?= mips-linux-gnu-ld
# This should be updated if rust-toolchain.toml is updated, and the nightly
# version should be close to the date of the release of the stable version used
# in rust-toolchain.toml.
# In addition to that, the version in the CI (see file
# .github/workflows/wasm.yml) should be changed accordingly.
# Can be overridden via environment variable, e.g.:
# NIGHTLY_RUST_VERSION=nightly make build-web
NIGHTLY_RUST_VERSION ?= nightly-2025-12-11
PLONK_WASM_NODEJS_OUTDIR ?= target/nodejs
PLONK_WASM_WEB_OUTDIR ?= target/web
# Feature flags for building with all features except no-std.
# The no-std feature conflicts with std-dependent code.
# See https://github.com/o1-labs/mina-rust/issues/1984
WORKSPACE_FEATURES = \
arkworks/std,\
arkworks/wasm,\
internal-tracing/enabled,\
internal-tracing/ocaml_types,\
kimchi/bn254,\
kimchi/check_feature_flags,\
kimchi/diagnostics,\
kimchi/internal_tracing,\
kimchi/ocaml_types,\
kimchi/wasm_types,\
mina-curves/asm,\
mina-poseidon/ocaml_types,\
o1-utils/diagnostics,\
o1vm/open_mips,\
poly-commitment/ocaml_types
# Default target
.PHONY: all
all: release
.PHONY: setup
setup: setup-git setup-wasm-toolchain
.PHONY: setup-git
setup-git:
@echo ""
@echo "Syncing the Git submodules."
@echo ""
git submodule sync
git submodule update --init --recursive
@echo ""
@echo "Git submodules synced."
.PHONY: setup-wasm-toolchain
setup-wasm-toolchain:
@ARCH=$$(uname -m); \
OS=$$(uname -s | tr A-Z a-z); \
case $$OS in \
linux) OS_PART="unknown-linux-gnu" ;; \
darwin) OS_PART="apple-darwin" ;; \
*) echo "Unsupported OS: $$OS" && exit 1 ;; \
esac; \
case $$ARCH in \
x86_64) ARCH_PART="x86_64" ;; \
aarch64) ARCH_PART="aarch64" ;; \
arm64) ARCH_PART="aarch64" ;; \
*) echo "Unsupported architecture: $$ARCH" && exit 1 ;; \
esac; \
TARGET="$$ARCH_PART-$$OS_PART"; \
echo "Installing rust-src for ${NIGHTLY_RUST_VERSION}-$$TARGET"; \
rustup component add rust-src --toolchain ${NIGHTLY_RUST_VERSION}-$$TARGET
# https://nexte.st/book/pre-built-binaries.html#using-nextest-in-github-actions
# FIXME: update to 0.9.68 when we get rid of 1.71 and 1.72.
# FIXME: latest 0.8.19+ requires rustc 1.74+
.PHONY: install-test-deps
install-test-deps: ## Install test dependencies
@echo ""
@echo "Installing the test dependencies."
@echo ""
rustup component add llvm-tools-preview
cargo install cargo-nextest@=0.9.67 --locked
cargo install grcov@=0.8.13 --locked
@echo ""
@echo "Test dependencies installed."
@echo ""
.PHONY: clean
clean: ## Clean the project
@cargo clean
@rm -rf $(O1VM_RISCV32IM_BIN_FILES)
@rm -rf $(O1VM_MIPS_BIN_DIR)
.PHONY: build
build: ## Build the project
cargo build \
--all-targets \
--features "$(WORKSPACE_FEATURES)" \
--exclude plonk_wasm \
--workspace
.PHONY: release
release: ## Build the project in release mode
cargo build \
--all-targets \
--features "$(WORKSPACE_FEATURES)" \
--exclude plonk_wasm \
--release \
--workspace
.PHONY: test-doc
test-doc: ## Test the project's docs comments
cargo test \
--features "$(WORKSPACE_FEATURES)" \
--doc \
--exclude plonk_wasm \
--release \
--workspace
.PHONY: test-doc-with-coverage
test-doc-with-coverage:
$(COVERAGE_ENV) $(MAKE) test-doc
.PHONY: test
test: ## Test the project with non-heavy tests and using native cargo test runner
cargo test \
--features "$(WORKSPACE_FEATURES)" \
--exclude plonk_wasm \
--release $(CARGO_EXTRA_ARGS) \
-- --nocapture \
--skip heavy $(BIN_EXTRA_ARGS)
.PHONY: test-with-coverage
test-with-coverage:
$(COVERAGE_ENV) CARGO_EXTRA_ARGS="$(CARGO_EXTRA_ARGS)" BIN_EXTRA_ARGS="$(BIN_EXTRA_ARGS)" $(MAKE) test
.PHONY: test-heavy
test-heavy: ## Test the project with heavy tests and using native cargo test runner
cargo test \
--features "$(WORKSPACE_FEATURES)" \
--exclude plonk_wasm \
--release $(CARGO_EXTRA_ARGS) \
-- --nocapture heavy $(BIN_EXTRA_ARGS)
.PHONY: test-heavy-with-coverage
test-heavy-with-coverage:
$(COVERAGE_ENV) CARGO_EXTRA_ARGS="$(CARGO_EXTRA_ARGS)" BIN_EXTRA_ARGS="$(BIN_EXTRA_ARGS)" $(MAKE) test-heavy
.PHONY: test-all
test-all: ## Test the project with all tests and using native cargo test runner
cargo test \
--features "$(WORKSPACE_FEATURES)" \
--exclude plonk_wasm \
--release $(CARGO_EXTRA_ARGS) \
-- --nocapture $(BIN_EXTRA_ARGS)
.PHONY: test-all-with-coverage
test-all-with-coverage:
$(COVERAGE_ENV) CARGO_EXTRA_ARGS="$(CARGO_EXTRA_ARGS)" BIN_EXTRA_ARGS="$(BIN_EXTRA_ARGS)" $(MAKE) test-all
.PHONY: nextest
nextest: ## Test the project with non-heavy tests and using nextest test runner
cargo nextest run \
--all \
--features "$(WORKSPACE_FEATURES)" \
--exclude plonk_wasm \
--release $(CARGO_EXTRA_ARGS) \
--profile ci \
-E "not test(heavy)" $(BIN_EXTRA_ARGS)
.PHONY: nextest-with-coverage
nextest-with-coverage:
$(COVERAGE_ENV) CARGO_EXTRA_ARGS="$(CARGO_EXTRA_ARGS)" BIN_EXTRA_ARGS="$(BIN_EXTRA_ARGS)" $(MAKE) nextest
.PHONY: nextest-heavy
nextest-heavy: ## Test the project with heavy tests and using nextest test runner
cargo nextest run \
--features "$(WORKSPACE_FEATURES)" \
--exclude plonk_wasm \
--release $(CARGO_EXTRA_ARGS) \
--profile ci \
-E "test(heavy)" $(BIN_EXTRA_ARGS)
.PHONY: nextest-heavy-with-coverage
nextest-heavy-with-coverage:
$(COVERAGE_ENV) CARGO_EXTRA_ARGS="$(CARGO_EXTRA_ARGS)" BIN_EXTRA_ARGS="$(BIN_EXTRA_ARGS)" $(MAKE) nextest-heavy
.PHONY: nextest-all
nextest-all: ## Test the project with all tests and using nextest test runner
cargo nextest run \
--workspace \
--features "$(WORKSPACE_FEATURES)" \
--exclude plonk_wasm \
--release $(CARGO_EXTRA_ARGS) \
--profile ci $(BIN_EXTRA_ARGS)
.PHONY: nextest-all-with-coverage
nextest-all-with-coverage:
$(COVERAGE_ENV) CARGO_EXTRA_ARGS="$(CARGO_EXTRA_ARGS)" BIN_EXTRA_ARGS="$(BIN_EXTRA_ARGS)" $(MAKE) nextest-all
.PHONY: check-format
check-format: ## Check the code formatting
cargo +nightly fmt -- --check
taplo fmt --check
.PHONY: format
format: ## Format the code
cargo +nightly fmt
taplo fmt
.PHONY: check-format-md
check-format-md: ## Check markdown formatting
npx prettier --check '**/*.md'
.PHONY: format-md
format-md: ## Format markdown files
npx prettier --write '**/*.md'
.PHONY: lint
lint: ## Lint the code
cargo clippy --all --features "$(WORKSPACE_FEATURES)" --all-targets --tests \
$(CARGO_EXTRA_ARGS) -- -W clippy::all -D warnings
.PHONY: generate-test-coverage-report
generate-test-coverage-report: ## Generate the code coverage report
@echo ""
@echo "Generating the test coverage report."
@echo ""
mkdir -p ./target/coverage
GRCOV_OUTPUT_TYPE=html GRCOV_OUTPUT_PATH=./target/coverage
$(eval GRCOV_HTML_CMD=$(GRCOV_CALL) -t html -o ./target/coverage)
$(GRCOV_HTML_CMD)
$(eval GRCOV_LCOV_CMD=$(GRCOV_CALL) -t lcov -o ./target/coverage/lcov.info)
$(GRCOV_LCOV_CMD)
@echo ""
@echo "The test coverage report is available at: ./target/coverage"
@echo ""
.PHONY: generate-doc
generate-doc: ## Generate the Rust documentation
@echo ""
@echo "Generating the documentation."
@echo ""
RUSTDOCFLAGS="--enable-index-page -Zunstable-options" cargo +nightly doc \
--document-private-items \
--features "$(WORKSPACE_FEATURES)" \
--no-deps \
--exclude plonk_wasm \
--workspace
@echo ""
@echo "The documentation is available at: ./target/doc"
@echo ""
.PHONY: help
help: ## Ask for help!
@grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
.PHONY: setup-riscv32-toolchain
setup-riscv32-toolchain: ## Download and compile the RISC-V 32bits toolchain
@echo ""
@echo "Setting up the RISC-V 32-bit toolchain"
@echo ""
if [ ! -d $(RISCV32_TOOLCHAIN_PATH) ]; then \
git clone https://github.com/riscv-collab/riscv-gnu-toolchain ${RISCV32_TOOLCHAIN_PATH}; \
fi
cd ${RISCV32_TOOLCHAIN_PATH} && ./configure --with-arch=rv32gc --with-abi=ilp32d --prefix=${RISCV32_TOOLCHAIN_PATH}/build
cd ${RISCV32_TOOLCHAIN_PATH} && make -j 32 # require a good internet connection and some minutes
@echo ""
@echo "RISC-V 32-bits toolchain is ready in ${RISCV32_TOOLCHAIN_PATH}/build"
@echo ""
.PHONY: build-riscv32-programs
build-riscv32-programs: setup-riscv32-toolchain ${O1VM_RISCV32IM_BIN_FILES} ## Build all RISC-V 32 bits programs written for the o1vm
${O1VM_RISCV32IM_BIN_DIR}/%.o: ${O1VM_RISCV32IM_SOURCE_DIR}/%.S
@echo ""
@echo "Building the RISC-V 32-bits binary: $@ using $<"
@echo ""
mkdir -p ${O1VM_RISCV32IM_BIN_DIR}
${RISCV32_TOOLCHAIN_PATH}/build/bin/riscv32-unknown-elf-as ${RISCV32_AS_FLAGS} -o $@ $<
${RISCV32_TOOLCHAIN_PATH}/build/bin/riscv32-unknown-elf-ld -s -o $(basename $@) $@
@echo ""
.PHONY: build-mips-programs
build-mips-programs: ${O1VM_MIPS_SOURCE_FILES} ${O1VM_MIPS_BIN_FILES} ## Build all MIPS programs written for the o1vm
${O1VM_MIPS_SOURCE_DIR}/%.asm: ${OPTIMISM_MIPS_SOURCE_DIR}/%.asm
@mkdir -p ${O1VM_MIPS_SOURCE_DIR}
@echo "Transforming $< to $@, making it compatible for o1vm"
@sed \
-e '/\.balign 4/d' \
-e 's/^\s*\.set\s*noreorder/.set noreorder/' \
-e '/\.ent\s*test/d' \
-e '/\.end test/d' \
-e 's/\.section .test, "x"/.section .text/' \
-e 's/\s*\.section .text/.section .text/' \
-e 's/\.global test/.global __start/' \
-e "s/^\s*\.global __start/.global __start/" \
-e "s/test\:/__start:/" \
-e "/\.global __start/a\\" \
$< > $@
${O1VM_MIPS_BIN_DIR}/%.o: ${O1VM_MIPS_SOURCE_DIR}/%.asm
@echo "Building the MIPS binary: $(basename $@) using $<"
@mkdir -p ${O1VM_MIPS_BIN_DIR}
@${MIPS_AS} -defsym big_endian=1 -march=mips32r2 -o $@ $<
@${MIPS_LD} -s -o $(basename $@) $@
.PHONY: fclean
fclean: clean ## Clean the tooling artefacts in addition to running clean
rm -rf ${RISCV32_TOOLCHAIN_PATH}
.PHONY: build-nodejs
build-nodejs: ## Compile the Kimchi library into WebAssembly to be used in NodeJS
cargo +$(NIGHTLY_RUST_VERSION) run --package xtask -- build-wasm \
--target nodejs \
--out-dir ${PLONK_WASM_NODEJS_OUTDIR} \
--rust-version $(NIGHTLY_RUST_VERSION)
.PHONY: build-web
build-web: ## Compile the Kimchi library into WebAssembly to be used in the browser
cargo +$(NIGHTLY_RUST_VERSION) run --package xtask -- build-wasm \
--target web \
--out-dir ${PLONK_WASM_WEB_OUTDIR} \
--rust-version $(NIGHTLY_RUST_VERSION)