-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathMakefile
87 lines (62 loc) · 2.41 KB
/
Makefile
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
.DEFAULT_GOAL = build
.PHONY: build cargo-build anchor-build prod-build test cargo-test anchor-test idl sdk clean node_modules lint cargo-lint anchor-lint fix-lint
#find and convert version line:
# turn `const VERSION: &str = "major.minor.patch";` into `major_minor_patch`
#use make functions to minimize dependence on shell
VERSION = $(subst .,_,$(subst ;,,$(subst ",,$(lastword \
$(shell grep "const VERSION" programs/native-token-transfers/src/lib.rs) \
))))
#######################
## BUILD
build: cargo-build anchor-build
cargo-build:
BPF_OUT_DIR="$(pwd)/target/deploy" cargo build-sbf
# after building, remove the generics from the idl file. This is necessary as of anchor 0.29.0,
# because the javascript library does not support generics yet, and just panics
anchor-build:
anchor build --arch sbf
@echo "Removing generics from target/idl/example_native_token_transfers.json"
./scripts/patch-idl target/idl/example_native_token_transfers.json
prod-build:
anchor build --verifiable
idl: anchor-build
@echo "IDL Version: $(VERSION)"
mkdir -p ts/idl/$(VERSION)/json
mkdir -p ts/idl/$(VERSION)/ts
cp -r target/idl/* ts/idl/$(VERSION)/json/
for jsonfile in ts/idl/$(VERSION)/json/*.json; do \
tsfile=$$(echo $$jsonfile | sed 's/json\/\(.*\)\.json/ts\/\1.ts/'); \
tsx scripts/regenerateIdl.ts $$jsonfile > $$tsfile; \
done
sdk: anchor-build
@echo "Building SDK"
cd .. && npm ci && npm run build:solana
clean:
anchor clean
rm -rf .anchor node_modules
node_modules:
npm install
#######################
## TESTS
test: cargo-test anchor-test
cargo-test:
cargo build-sbf --features "mainnet"
cargo test-sbf --features "mainnet"
cargo test
anchor-test: idl sdk node_modules
anchor test --skip-build
#######################
## LINT
lint: cargo-lint anchor-lint
cargo-lint:
cargo fmt --check --all --manifest-path Cargo.toml
cargo check --workspace --tests --manifest-path Cargo.toml
cargo clippy --workspace --tests --manifest-path Cargo.toml -- -Dclippy::cast_possible_truncation
# Run anchor's linter on all Rust files in the current directory via `anchor idl parse`
# Results written to /dev/null because we're just calling parse for the linting capabilities and we don't care about
# the JSON output.
# anchor-cli v0.29.0 doesn't seem to do linting on the command-line during the build process so this is a workaround
anchor-lint:
bash scripts/anchor-lint.sh
fix-lint:
cargo fmt --all --manifest-path Cargo.toml