forked from solana-labs/solana
-
Notifications
You must be signed in to change notification settings - Fork 222
/
build-downstream-anchor-projects.sh
executable file
·134 lines (113 loc) · 3.94 KB
/
build-downstream-anchor-projects.sh
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
#!/usr/bin/env bash
#
# Builds known downstream projects against local solana source
#
set -e
cd "$(dirname "$0")"/..
source ci/_
source scripts/patch-crates.sh
source scripts/read-cargo-variable.sh
source scripts/patch-spl-crates-for-anchor.sh
anchor_version=$1
solana_ver=$(readCargoVariable version Cargo.toml)
solana_dir=$PWD
cargo="$solana_dir"/cargo
cargo_build_sbf="$solana_dir"/cargo-build-sbf
cargo_test_sbf="$solana_dir"/cargo-test-sbf
mkdir -p target/downstream-projects-anchor
cd target/downstream-projects-anchor
update_anchor_dependencies() {
declare project_root="$1"
declare anchor_ver="$2"
declare tomls=()
while IFS='' read -r line; do tomls+=("$line"); done < <(find "$project_root" -name Cargo.toml)
sed -i -e "s#\(anchor-lang = \"\)[^\"]*\(\"\)#\1=$anchor_ver\2#g" "${tomls[@]}" || return $?
sed -i -e "s#\(anchor-spl = \"\)[^\"]*\(\"\)#\1=$anchor_ver\2#g" "${tomls[@]}" || return $?
sed -i -e "s#\(anchor-lang = { version = \"\)[^\"]*\(\"\)#\1=$anchor_ver\2#g" "${tomls[@]}" || return $?
sed -i -e "s#\(anchor-spl = { version = \"\)[^\"]*\(\"\)#\1=$anchor_ver\2#g" "${tomls[@]}" || return $?
}
patch_crates_io_anchor() {
declare Cargo_toml="$1"
declare anchor_dir="$2"
cat >> "$Cargo_toml" <<EOF
anchor-lang = { path = "$anchor_dir/lang" }
anchor-spl = { path = "$anchor_dir/spl" }
EOF
}
# NOTE This isn't run in a subshell to get $anchor_dir and $anchor_ver
anchor() {
set -x
rm -rf spl
git clone https://github.com/solana-labs/solana-program-library.git spl
cd spl || exit 1
./patch.crates-io.sh "$solana_dir"
spl_dir=$PWD
get_spl_versions "$spl_dir"
cd ..
rm -rf anchor
git clone https://github.com/coral-xyz/anchor.git
cd anchor || exit 1
# checkout tag
if [[ -n "$anchor_version" ]]; then
git checkout "$anchor_version"
fi
# copy toolchain file to use solana's rust version
cp "$solana_dir"/rust-toolchain.toml .
update_solana_dependencies . "$solana_ver"
patch_crates_io_solana Cargo.toml "$solana_dir"
patch_spl_crates . Cargo.toml "$spl_dir"
sed -i '/\[patch.crates-io\]/a curve25519-dalek = { git = "https://github.com/anza-xyz/curve25519-dalek.git", rev = "b500cdc2a920cd5bff9e2dd974d7b97349d61464" }' ./Cargo.toml
$cargo test
# serum_dex and mpl-token-metadata are using caret versions of solana and SPL dependencies
# rather pull and patch those as well, ignore for now
# (cd spl && $cargo_build_sbf --features dex metadata stake)
(cd spl && $cargo_build_sbf --features stake)
(cd client && $cargo test --all-features)
anchor_dir=$PWD
anchor_ver=$(readCargoVariable version "$anchor_dir"/lang/Cargo.toml)
cd "$solana_dir"/target/downstream-projects-anchor
}
openbook() {
# Openbook-v2 is still using cargo 1.70.0, which is not compatible with the latest main
rm -rf openbook-v2
git clone https://github.com/openbook-dex/openbook-v2.git
cd openbook-v2
update_solana_dependencies . "$solana_ver"
patch_crates_io_solana Cargo.toml "$solana_dir"
$cargo_build_sbf --features enable-gpl
cd programs/openbook-v2
$cargo_test_sbf --features enable-gpl
}
mango() {
(
set -x
rm -rf mango-v4
git clone https://github.com/blockworks-foundation/mango-v4.git
cd mango-v4
update_solana_dependencies . "$solana_ver"
patch_crates_io_solana_no_header Cargo.toml "$solana_dir"
$cargo_test_sbf --features enable-gpl
)
}
metaplex() {
(
set -x
rm -rf mpl-token-metadata
git clone https://github.com/metaplex-foundation/mpl-token-metadata
# copy toolchain file to use solana's rust version
cp "$solana_dir"/rust-toolchain.toml mpl-token-metadata/
cd mpl-token-metadata
./configs/program-scripts/dump.sh ./programs/bin
ROOT_DIR=$(pwd)
cd programs/token-metadata
update_solana_dependencies . "$solana_ver"
patch_crates_io_solana Cargo.toml "$solana_dir"
OUT_DIR="$ROOT_DIR"/programs/bin
export SBF_OUT_DIR="$OUT_DIR"
$cargo_test_sbf --sbf-out-dir "${OUT_DIR}"
)
}
_ anchor
#_ metaplex
#_ mango
#_ openbook