Skip to content

Commit f4d970e

Browse files
nvsriramjohnsaiglenonergodic
authored
Makefile: Add Solana Makefile targets to top-level dir (#502)
* solana: Add build, test, and lint targets to top-level dir Adds Makefile targets for common Solana tasks in the top-level directory. This allows the test and build pipeline to be run from the main directory for both the EVM and Solana implementations. This also helps to capture the Solana commands that are configured in the .github/workflows/solana.yml file. In case this codebase is merged or adapted into the Wormhole monorepo, the GitHub workflow may be removed for modified. Therefore it is beneficial to track the expected test configurations here. * solana: Update Makefile targets and clippy command * Makefile: Remove all target * Makefile: Update .PHONY target names Co-authored-by: Andreas <41449730+nonergodic@users.noreply.github.com> * Makefile: Add Solana prod build and general targets to build/test/lint * CI: Update Forge fmt to use new Makefile target * chore: Readd newlines * solana: Add build, test, and lint targets to top-level dir Adds Makefile targets for common Solana tasks in the top-level directory. This allows the test and build pipeline to be run from the main directory for both the EVM and Solana implementations. This also helps to capture the Solana commands that are configured in the .github/workflows/solana.yml file. In case this codebase is merged or adapted into the Wormhole monorepo, the GitHub workflow may be removed for modified. Therefore it is beneficial to track the expected test configurations here. * solana: Update Makefile targets and clippy command * Makefile: Remove all target * Makefile: Update .PHONY target names Co-authored-by: Andreas <41449730+nonergodic@users.noreply.github.com> * Makefile: Add Solana prod build and general targets to build/test/lint * CI: Update Forge fmt to use new Makefile target * chore: Readd newlines * solana: Update Makefile to include CI commands * evm: Add Makefile with build, tests, and lint targets * CI: Update evm.yml to use new targets * Makefile: Add generic build, test, and lint targets * CI: Set evm.yml working directory to ./evm * CI: Untar echidna to echidna-bin to avoid name conflicts * CI: Fix untar location from PATH to echidna-bin --------- Co-authored-by: John Saigle <john@asymmetric.re> Co-authored-by: Andreas <41449730+nonergodic@users.noreply.github.com>
1 parent e07f088 commit f4d970e

File tree

4 files changed

+109
-56
lines changed

4 files changed

+109
-56
lines changed

.github/workflows/evm.yml

+14-10
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ on:
1010
env:
1111
FOUNDRY_PROFILE: ci
1212

13+
defaults:
14+
run:
15+
working-directory: ./evm
16+
1317
jobs:
1418
check:
1519
strategy:
@@ -29,44 +33,44 @@ jobs:
2933

3034
- name: Run Forge build
3135
run: |
32-
make test-push0
36+
make push0-test
3337
id: build
3438

3539
- name: Run Forge tests
3640
run: |
37-
make test-evm
41+
make forge-test
3842
id: test
3943

4044
- name: Run Forge fmt
4145
run: |
42-
make check-format
46+
make lint
4347
id: check
44-
48+
4549
echidna:
4650
name: echidna
4751
runs-on: ubuntu-latest
4852
steps:
4953
- uses: actions/checkout@v4
5054
with:
5155
submodules: recursive
52-
56+
5357
- name: Install Foundry
5458
uses: foundry-rs/foundry-toolchain@v1
5559
with:
5660
version: nightly
5761

5862
- name: Run Forge build
5963
run: |
60-
make test-push0
64+
make build
6165
id: build
6266

6367
- name: Install Echidna
6468
run: |
6569
curl -LO https://github.com/crytic/echidna/releases/download/v2.2.3/echidna-2.2.3-x86_64-linux.tar.gz
66-
tar -xzf echidna-2.2.3-x86_64-linux.tar.gz
70+
mkdir echidna-bin
71+
tar -xzf echidna-2.2.3-x86_64-linux.tar.gz -C echidna-bin
6772
pip install crytic-compile
68-
73+
6974
- name: Run Echidna
7075
run: |
71-
cd evm
72-
../echidna ./echidna --config echidna.yaml
76+
echidna-bin/echidna ./echidna --config echidna.yaml

Makefile

+5-38
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,7 @@
1-
all: build
1+
PLATFORM_DIRS := evm solana
22

3-
#######################
4-
## BUILD
3+
TARGETS := build test lint
54

6-
.PHONY: build
7-
build-evm:
8-
cd evm && forge build
9-
10-
.PHONY: clean-evm
11-
clean-evm:
12-
cd evm && forge clean
13-
14-
.PHONY: build-evm-prod
15-
build-evm-prod: clean-evm
16-
cd evm && docker build --target foundry-export -f Dockerfile -o out .
17-
18-
.PHONY: gen-evm-bindings
19-
gen-evm-bindings: build-evm-prod
20-
npm ci && cd evm/ts && npm run generate
21-
22-
#######################
23-
## TESTS
24-
25-
.PHONY: check-format
26-
check-format:
27-
cd evm && forge fmt --check
28-
29-
.PHONY: fix-format
30-
fix-format:
31-
cd evm && forge fmt
32-
33-
.PHONY: test
34-
test-evm:
35-
cd evm && forge test -vvv
36-
37-
# Verify that the contracts do not include PUSH0 opcodes
38-
test-push0:
39-
cd evm && forge build --extra-output evm.bytecode.opcodes
40-
@if grep -qr --include \*.json PUSH0 ./evm/out; then echo "Contract uses PUSH0 instruction" 1>&2; exit 1; else echo "PUSH0 Verification Succeeded"; fi
5+
.PHONY: $(TARGETS)
6+
$(TARGETS):
7+
$(foreach dir,$(PLATFORM_DIRS), make -C $(dir) $@ &&) true

evm/Makefile

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
.DEFAULT_GOAL = build
2+
.PHONY: build prod-build clean gen-bindings test forge-test push0-test lint fix-lint
3+
4+
5+
#######################
6+
## BUILD
7+
8+
build:
9+
forge build
10+
11+
12+
prod-build: clean
13+
docker build --target foundry-export -f Dockerfile -o out .
14+
15+
clean:
16+
forge clean
17+
18+
gen-bindings: prod-build
19+
npm ci && cd ts && npm run generate
20+
21+
22+
#######################
23+
## TESTS
24+
25+
test: forge-test push0-test
26+
27+
28+
forge-test:
29+
forge test -vvv
30+
31+
# Verify that the contracts do not include PUSH0 opcodes
32+
push0-test:
33+
forge build --extra-output evm.bytecode.opcodes
34+
@if grep -qr --include \*.json PUSH0 ./evm/out; then echo "Contract uses PUSH0 instruction" 1>&2; exit 1; else echo "PUSH0 Verification Succeeded"; fi
35+
36+
37+
#######################
38+
## LINT
39+
40+
lint:
41+
forge fmt --check
42+
43+
44+
fix-lint:
45+
forge fmt

solana/Makefile

+45-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
.DEFAULT_GOAL = build
2-
.PHONY: build test idl sdk clean
2+
.PHONY: build cargo-build anchor-build prod-build test cargo-test anchor-test idl sdk clean node_modules lint fix-lint
33

44
#find and convert version line:
55
# turn `const VERSION: &str = "major.minor.patch";` into `major_minor_patch`
@@ -8,18 +8,27 @@ VERSION = $(subst .,_,$(subst ;,,$(subst ",,$(lastword \
88
$(shell grep "const VERSION" programs/example-native-token-transfers/src/lib.rs) \
99
))))
1010

11+
12+
#######################
13+
## BUILD
14+
15+
build: cargo-build anchor-build
16+
17+
18+
cargo-build:
19+
BPF_OUT_DIR="$(pwd)/target/deploy" cargo build-sbf
20+
1121
# after building, remove the generics from the idl file. This is necessary as of anchor 0.29.0,
1222
# because the javascript library does not support generics yet, and just panics
13-
build:
23+
anchor-build:
1424
anchor build --arch sbf
1525
@echo "Removing generics from target/idl/example_native_token_transfers.json"
1626
./scripts/patch-idl target/idl/example_native_token_transfers.json
1727

28+
prod-build:
29+
anchor build --verifiable
1830

19-
test: idl sdk node_modules
20-
anchor test --skip-build
21-
22-
idl: build
31+
idl: anchor-build
2332
@echo "IDL Version: $(VERSION)"
2433
mkdir -p ts/idl/$(VERSION)/json
2534
mkdir -p ts/idl/$(VERSION)/ts
@@ -29,7 +38,7 @@ idl: build
2938
tsx scripts/regenerateIdl.ts $$jsonfile > $$tsfile; \
3039
done
3140

32-
sdk: build
41+
sdk: anchor-build
3342
@echo "Building SDK"
3443
cd .. && npm ci && npm run build:solana
3544

@@ -38,4 +47,32 @@ clean:
3847
rm -rf .anchor node_modules
3948

4049
node_modules:
41-
npm install
50+
npm install
51+
52+
53+
#######################
54+
## TESTS
55+
56+
test: cargo-test anchor-test
57+
58+
59+
cargo-test:
60+
cargo build-sbf --features "mainnet"
61+
cargo test-sbf --features "mainnet"
62+
cargo test
63+
64+
anchor-test: idl sdk node_modules
65+
anchor test --skip-build
66+
67+
68+
#######################
69+
## LINT
70+
71+
lint:
72+
cargo fmt --check --all --manifest-path Cargo.toml
73+
cargo check --workspace --tests --manifest-path Cargo.toml
74+
cargo clippy --workspace --tests --manifest-path Cargo.toml -- -Dclippy::cast_possible_truncation
75+
76+
77+
fix-lint:
78+
cargo fmt --all --manifest-path Cargo.toml

0 commit comments

Comments
 (0)