Skip to content

Commit dced60e

Browse files
authored
Merge pull request #1181 from openmina/dw/unify-ci-makefile
Unify Makefile and CI
2 parents 5f0ee98 + 0b2599c commit dced60e

File tree

3 files changed

+118
-64
lines changed

3 files changed

+118
-64
lines changed

.github/workflows/ci.yaml

Lines changed: 43 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,18 @@ jobs:
2626
sudo apt update
2727
sudo apt install -y protobuf-compiler
2828
- name: Setup Rust
29-
run: |
30-
# Nightly to be able to use `--report-time` below
31-
rustup install nightly
32-
rustup override set nightly
29+
uses: dtolnay/rust-toolchain@stable
30+
with:
31+
toolchain: nightly
3332
- name: Download circuits files
3433
run: |
35-
git clone --depth 1 https://github.com/openmina/circuit-blobs.git
36-
ln -s -b $PWD/circuit-blobs/* ledger/
34+
make download-circuits
3735
- name: Build ledger tests
3836
run: |
39-
cd ledger
40-
cargo build --release --tests
37+
make build-ledger
4138
- name: Run ledger tests
4239
run: |
43-
cd ledger
44-
cargo test --release -- -Z unstable-options --report-time
40+
make test-ledger
4541
4642
ledger-32x9-tests:
4743
runs-on: ubuntu-22.04
@@ -53,14 +49,12 @@ jobs:
5349
sudo apt update
5450
sudo apt install -y protobuf-compiler
5551
- name: Setup Rust
56-
run: |
57-
# Nightly to be able to use `--report-time` below
58-
rustup install nightly
59-
rustup override set nightly
52+
uses: dtolnay/rust-toolchain@stable
53+
with:
54+
toolchain: nightly
6055
- name: Download circuits files
6156
run: |
62-
git clone --depth 1 https://github.com/openmina/circuit-blobs.git
63-
ln -s -b $PWD/circuit-blobs/* ledger/
57+
make download-circuits
6458
- name: Enable 32x9 fields implementation
6559
run: |
6660
cargo install sd
@@ -70,12 +64,10 @@ jobs:
7064
cat ./Cargo.toml
7165
- name: Build ledger tests
7266
run: |
73-
cd ledger
74-
cargo build --release --tests
67+
make build-ledger
7568
- name: Run ledger tests
7669
run: |
77-
cd ledger
78-
cargo test --release -- -Z unstable-options --report-time
70+
make test-ledger
7971
8072
vrf-tests:
8173
runs-on: ubuntu-22.04
@@ -87,18 +79,15 @@ jobs:
8779
sudo apt update
8880
sudo apt install -y protobuf-compiler
8981
- name: Setup Rust
90-
run: |
91-
# Nightly to be able to use `--report-time` below
92-
rustup install nightly
93-
rustup override set nightly
82+
uses: dtolnay/rust-toolchain@stable
83+
with:
84+
toolchain: nightly
9485
- name: Build vrf tests
9586
run: |
96-
cd vrf
97-
cargo build --release --tests
87+
make build-vrf
9888
- name: Run vrf tests
9989
run: |
100-
cd vrf
101-
cargo test --release -- -Z unstable-options --report-time
90+
make test-vrf
10291
10392
p2p-tests:
10493
runs-on: ubuntu-22.04
@@ -112,9 +101,10 @@ jobs:
112101
sudo apt install -y protobuf-compiler
113102
114103
- name: Setup Rust
115-
run: |
116-
rustup default 1.84
117-
rustup component add rustfmt
104+
uses: dtolnay/rust-toolchain@stable
105+
with:
106+
components: rustfmt
107+
toolchain: 1.84
118108

119109
- name: Setup Rust Cache
120110
uses: Swatinem/rust-cache@v2
@@ -123,8 +113,7 @@ jobs:
123113

124114
- name: Test p2p crate
125115
run: |
126-
cargo test -p p2p --tests
127-
116+
make test-p2p
128117
129118
build:
130119
runs-on: ubuntu-22.04
@@ -138,9 +127,10 @@ jobs:
138127
sudo apt install -y protobuf-compiler
139128
140129
- name: Setup Rust
141-
run: |
142-
rustup default 1.84
143-
rustup component add rustfmt
130+
uses: dtolnay/rust-toolchain@stable
131+
with:
132+
components: rustfmt
133+
toolchain: 1.84
144134

145135
- name: Setup Rust Cache
146136
uses: Swatinem/rust-cache@v2
@@ -149,7 +139,7 @@ jobs:
149139

150140
- name: Release build
151141
run: |
152-
cargo build --release --bin openmina
142+
make build-release
153143
154144
- name: Upload binaries
155145
uses: actions/upload-artifact@v4
@@ -169,9 +159,13 @@ jobs:
169159
sudo apt install -y protobuf-compiler
170160
171161
- name: Setup Rust
162+
uses: dtolnay/rust-toolchain@stable
163+
with:
164+
components: rustfmt, rust-src
165+
toolchain: nightly
166+
167+
- name: Install wasm32 and wasm-bindgen-cli
172168
run: |
173-
rustup default nightly
174-
rustup component add rustfmt rust-src
175169
rustup target add wasm32-unknown-unknown
176170
cargo install -f wasm-bindgen-cli --version 0.2.99
177171
@@ -182,10 +176,7 @@ jobs:
182176

183177
- name: Release build
184178
run: |
185-
cd node/web
186-
rustup component add rust-src rustfmt --toolchain nightly-x86_64-unknown-linux-gnu
187-
cargo +nightly build --release --target wasm32-unknown-unknown
188-
wasm-bindgen --keep-debug --web --out-dir pkg ../../target/wasm32-unknown-unknown/release/openmina_node_web.wasm
179+
make build-wasm
189180
190181
build-tests:
191182
runs-on: ubuntu-22.04
@@ -199,9 +190,10 @@ jobs:
199190
sudo apt install -y protobuf-compiler
200191
201192
- name: Setup Rust
202-
run: |
203-
rustup default 1.84
204-
rustup component add rustfmt
193+
uses: dtolnay/rust-toolchain@stable
194+
with:
195+
components: rustfmt
196+
toolchain: 1.84
205197

206198
- name: Setup Rust Cache
207199
uses: Swatinem/rust-cache@v2
@@ -235,9 +227,10 @@ jobs:
235227
sudo apt install -y protobuf-compiler
236228
237229
- name: Setup Rust
238-
run: |
239-
rustup default 1.84
240-
rustup component add rustfmt
230+
uses: dtolnay/rust-toolchain@stable
231+
with:
232+
components: rustfmt
233+
toolchain: 1.84
241234

242235
- name: Setup Rust Cache
243236
uses: Swatinem/rust-cache@v2
@@ -246,12 +239,7 @@ jobs:
246239

247240
- name: Build tests
248241
run: |
249-
mkdir -p target/release/tests
250-
251-
cargo build --release --features=scenario-generators,p2p-webrtc --package=openmina-node-testing --tests
252-
cargo build --release --features=scenario-generators,p2p-webrtc --package=openmina-node-testing --tests --message-format=json > cargo-build-test.json
253-
jq -r '. | select(.executable != null and (.target.kind | (contains(["test"])))) | [.target.name, .executable ] | @tsv' cargo-build-test.json > tests.tsv
254-
while read NAME FILE; do cp -a $FILE target/release/tests/webrtc_$NAME; done < tests.tsv
242+
make build-tests-webrtc
255243
256244
- name: Upload tests
257245
uses: actions/upload-artifact@v4

.gitignore

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
/target
22
/node/testing/res/
3+
circuit-blobs
34
.DS_Store
45
*.profraw
5-
node_modules
6+
node_modules
7+
8+
# Output of build-wasm
9+
pkg/
10+
11+
# Outputs of build-tests-webrtc
12+
cargo-build-test.json
13+
tests.tsv

Makefile

Lines changed: 66 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# OpenMina Makefile
22

3+
NIGHTLY_RUST_VERSION = "nightly"
4+
35
.PHONY: help
46
help: ## Ask for help!
57
@grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
@@ -8,17 +10,45 @@ help: ## Ask for help!
810
build: ## Build the project in debug mode
911
cargo build
1012

13+
.PHONY: build-ledger
14+
build-ledger: download-circuits ## Build the ledger binary and library, requires nightly Rust
15+
@cd ledger && cargo +nightly build --release --tests
16+
1117
.PHONY: build-release
1218
build-release: ## Build the project in release mode
1319
cargo build --release --bin openmina
1420

15-
.PHONY: build-tests
16-
build-tests: ## Build test binaries
17-
cargo build --release --tests --package=openmina-node-testing --package=cli
21+
.PHONY: build-tests-webrtc
22+
build-tests-webrtc: ## Build tests for WebRTC
23+
@mkdir -p target/release/tests
24+
@cargo build --release --tests \
25+
--package=openmina-node-testing \
26+
--package=cli
27+
# Update ./.gitignore accordingly if cargo-build-test.json is changed
28+
@cargo build --release \
29+
--features=scenario-generators,p2p-webrtc \
30+
--package=openmina-node-testing \
31+
--tests \
32+
--message-format=json \
33+
> cargo-build-test.json
34+
# Update ./.gitignore accordingly if tests.json is changed
35+
@jq -r '. | select(.executable != null and (.target.kind | (contains(["test"])))) | [.target.name, .executable ] | @tsv' cargo-build-test.json > tests.tsv
36+
@while read NAME FILE; do \
37+
cp -a $$FILE target/release/tests/webrtc_$$NAME; \
38+
done < tests.tsv
39+
40+
.PHONY: build-vrf
41+
build-vrf: ## Build the VRF package
42+
@cd vrf && cargo +nightly build --release --tests
1843

1944
.PHONY: build-wasm
2045
build-wasm: ## Build WebAssembly node
21-
cd node/web && cargo +nightly build --release --target wasm32-unknown-unknown
46+
@cd node/web && cargo +nightly build \
47+
--release --target wasm32-unknown-unknown
48+
# Update ./.gitignore accordingly if the out-dir is changed
49+
@wasm-bindgen --keep-debug --web \
50+
--out-dir pkg \
51+
target/wasm32-unknown-unknown/release/openmina_node_web.wasm
2252

2353
.PHONY: check
2454
check: ## Check code for compilation errors
@@ -42,6 +72,15 @@ check-md: ## Check if markdown files are properly formatted
4272
clean: ## Clean build artifacts
4373
cargo clean
4474

75+
.PHONY: download-circuits
76+
download-circuits: ## Download the circuits used by Mina from GitHub
77+
@if [ ! -d "circuit-blobs" ]; then \
78+
git clone --depth 1 https://github.com/openmina/circuit-blobs.git; \
79+
ln -s -b "$$PWD"/circuit-blobs/* ledger/; \
80+
else \
81+
echo "circuit-blobs already exists, skipping download."; \
82+
fi
83+
4584
.PHONY: format
4685
format: ## Format code using rustfmt
4786
cargo +nightly fmt
@@ -56,13 +95,32 @@ format-md: ## Format all markdown files to wrap at 80 characters
5695
lint: ## Run linter (clippy)
5796
cargo clippy --all-targets -- -D warnings --allow clippy::mutable_key_type
5897

98+
.PHONY: setup-wasm-toolchain
99+
setup-wasm-toolchain: ## Setup the WebAssembly toolchain, using nightly
100+
@ARCH=$$(uname -m); \
101+
OS=$$(uname -s | tr A-Z a-z); \
102+
case $$OS in \
103+
linux) OS_PART="unknown-linux-gnu" ;; \
104+
darwin) OS_PART="apple-darwin" ;; \
105+
*) echo "Unsupported OS: $$OS" && exit 1 ;; \
106+
esac; \
107+
case $$ARCH in \
108+
x86_64) ARCH_PART="x86_64" ;; \
109+
aarch64) ARCH_PART="aarch64" ;; \
110+
arm64) ARCH_PART="aarch64" ;; \
111+
*) echo "Unsupported architecture: $$ARCH" && exit 1 ;; \
112+
esac; \
113+
TARGET="$$ARCH_PART-$$OS_PART"; \
114+
echo "Installing rust-src and rustfmt for ${NIGHTLY_RUST_VERSION}-$$TARGET with wasm32 target"; \
115+
rustup target add wasm32-unknown-unknown --toolchain ${NIGHTLY_RUST_VERSION}-$$TARGET
116+
59117
.PHONY: test
60118
test: ## Run tests
61119
cargo test
62120

63121
.PHONY: test-ledger
64-
test-ledger: ## Run ledger tests
65-
cd ledger && cargo test --release
122+
test-ledger: build-ledger ## Run ledger tests in release mode, requires nightly Rust
123+
@cd ledger && cargo +nightly test --release -- -Z unstable-options --report-time
66124

67125
.PHONY: test-p2p
68126
test-p2p: ## Run P2P tests
@@ -73,5 +131,5 @@ test-release: ## Run tests in release mode
73131
cargo test --release
74132

75133
.PHONY: test-vrf
76-
test-vrf: ## Run VRF tests
77-
cd vrf && cargo test --release
134+
test-vrf: ## Run VRF tests, requires nightly Rust
135+
@cd vrf && cargo +nightly test --release -- -Z unstable-options --report-time

0 commit comments

Comments
 (0)