Skip to content

Commit 7a53f37

Browse files
authored
scripts: Add patching script for Agave devs (#5)
* scripts: Add patching script for Agave devs #### Problem Now that the solana-sdk is split out of the Agave repo, it will be annoying for Agave developers to make simultaneous changes to the SDK and Agave. #### Summary of changes Add a script for patching the solana-sdk in Agave, along with a CI check to make sure that the SDK doesn't break Agave. * Pacify shellcheck * Install extra requirements for agave * Simplify the check
1 parent e379e46 commit 7a53f37

File tree

6 files changed

+254
-0
lines changed

6 files changed

+254
-0
lines changed

.github/actions/setup/action.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ inputs:
2828
llvm-tools-preview:
2929
description: Install llvm-tools-preview if `true`. Defaults to `false`.
3030
required: false
31+
agave:
32+
description: Install required packages for Agave if `true`. Defaults to `false`.
33+
required: false
3134
purge:
3235
description: Purge unused directories if `true`. Defaults to `false`.
3336
required: false
@@ -105,6 +108,11 @@ runs:
105108
toolchain: ${{ env.RUST_NIGHTLY }}
106109
components: llvm-tools-preview
107110

111+
- name: Install Agave build dependencies
112+
if: ${{ inputs.agave == 'true' }}
113+
shell: bash
114+
run: sudo apt update && sudo apt install -y libudev-dev protobuf-compiler
115+
108116
- name: Cache Cargo Dependencies
109117
if: ${{ inputs.cargo-cache-key && !inputs.cargo-cache-fallback-key }}
110118
uses: actions/cache@v4

.github/workflows/main.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,25 @@ jobs:
101101
- name: Run checks
102102
run: ./scripts/check-nightly.sh
103103

104+
check-downstream-agave:
105+
name: Cargo check Agave master
106+
runs-on: ubuntu-latest
107+
needs: [sanity]
108+
steps:
109+
- name: Git Checkout
110+
uses: actions/checkout@v4
111+
112+
- name: Setup Environment
113+
uses: ./.github/actions/setup
114+
with:
115+
agave: true
116+
stable-toolchain: true
117+
cargo-cache-key: cargo-downstream-agave-check
118+
cargo-cache-fallback-key: cargo-downstream-agave
119+
120+
- name: Run checks
121+
run: ./scripts/check-downstream-agave.sh
122+
104123
clippy:
105124
name: Clippy
106125
needs: [sanity]

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# solana-sdk
2+
3+
Rust SDK for the Solana blockchain, used by on-chain programs and the Agave
4+
validator.
5+
6+
## For Agave Developers
7+
8+
### Patching a local solana-sdk repository
9+
10+
If your change to Agave also entails changes to the SDK, you will need to patch
11+
your Agave repo to use a local checkout of solana-sdk crates.
12+
13+
To patch all of the crates in this repo for Agave, just run:
14+
15+
```console
16+
./scripts/patch-crates-no-header.sh <AGAVE_PATH> <SOLANA_SDK_PATH>
17+
```

scripts/check-downstream-agave.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env bash
2+
3+
set -eo pipefail
4+
here="$(dirname "$0")"
5+
src_root="$(readlink -f "${here}/..")"
6+
cd "${src_root}"
7+
8+
rm -rf ./target/downstream/agave
9+
mkdir -p ./target/downstream
10+
cd ./target/downstream
11+
git clone --depth 1 https://github.com/anza-xyz/agave.git --single-branch --branch=master
12+
cd ./agave
13+
14+
../../../scripts/patch-crates-no-header.sh . ../../..
15+
cargo check

scripts/patch-crates-functions.sh

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
# source this file
2+
3+
base="$(dirname "${BASH_SOURCE[0]}")"
4+
# pacify shellcheck: cannot follow dynamic path
5+
# shellcheck disable=SC1090,SC1091
6+
source "$base/read-cargo-variable.sh"
7+
8+
crate_dirs=(
9+
account
10+
account-info
11+
address-lookup-table-interface
12+
atomic-u64
13+
big-mod-exp
14+
bincode
15+
blake3-hasher
16+
bn254
17+
borsh
18+
client-traits
19+
clock
20+
cluster-type
21+
commitment-config
22+
compute-budget-interface
23+
cpi
24+
decode-error
25+
define-syscall
26+
derivation-path
27+
ed25519-program
28+
epoch-info
29+
epoch-rewards
30+
epoch-rewards-hasher
31+
epoch-schedule
32+
example-mocks
33+
feature-gate-interface
34+
feature-set
35+
fee-calculator
36+
fee-structure
37+
file-download
38+
frozen-abi
39+
frozen-abi-macro
40+
genesis-config
41+
hard-forks
42+
hash
43+
inflation
44+
instruction
45+
instructions-sysvar
46+
keccak-hasher
47+
keypair
48+
last-restart-slot
49+
loader-v2-interface
50+
loader-v3-interface
51+
loader-v4-interface
52+
logger
53+
message
54+
msg
55+
native-token
56+
nonce
57+
nonce-account
58+
offchain-message
59+
package-metadata
60+
package-metadata-macro
61+
packet
62+
poh-config
63+
precompile-error
64+
precompiles
65+
presigner
66+
program
67+
program-entrypoint
68+
program-error
69+
program-memory
70+
program-option
71+
program-pack
72+
pubkey
73+
quic-definitions
74+
rent
75+
rent-collector
76+
rent-debits
77+
reserved-account-keys
78+
reward-info
79+
sanitize
80+
scripts
81+
sdk
82+
sdk-ids
83+
sdk-macro
84+
secp256k1-program
85+
secp256k1-recover
86+
secp256r1-program
87+
seed-derivable
88+
seed-phrase
89+
serde
90+
serde-varint
91+
serialize-utils
92+
sha256-hasher
93+
short-vec
94+
shred-version
95+
signature
96+
signer
97+
slot-hashes
98+
slot-history
99+
stable-layout
100+
system-transaction
101+
sysvar
102+
sysvar-id
103+
target
104+
time-utils
105+
transaction
106+
transaction-context
107+
transaction-error
108+
validator-exit
109+
vote-interface
110+
)
111+
112+
update_solana_sdk_dependencies() {
113+
declare project_root="$1"
114+
declare solana_sdk_dir="$2"
115+
declare tomls=()
116+
while IFS='' read -r line; do tomls+=("$line"); done < <(find "$project_root" -name Cargo.toml)
117+
118+
set -x
119+
for crate_dir in "${crate_dirs[@]}"; do
120+
full_path="$solana_sdk_dir/$crate_dir"
121+
crate_version=$(readCargoVariable version "$full_path/Cargo.toml")
122+
sed -E -i'' -e "s:(solana-${crate_dir} = \")([=<>]*)[0-9.]+([^\"]*)\".*:\1\2${crate_version}\3\":" "${tomls[@]}"
123+
sed -E -i'' -e "s:(solana-${crate_dir} = \{ version = \")([=<>]*)[0-9.]+([^\"]*)(\".*):\1\2${crate_version}\3\4:" "${tomls[@]}"
124+
done
125+
}
126+
127+
patch_crates_io_solana_sdk() {
128+
declare Cargo_toml="$1"
129+
declare solana_sdk_dir="$2"
130+
cat >> "$Cargo_toml" <<EOF
131+
[patch.crates-io]
132+
EOF
133+
patch_crates_io_solana_sdk_no_header "$Cargo_toml" "$solana_sdk_dir"
134+
}
135+
136+
patch_crates_io_solana_sdk_no_header() {
137+
declare Cargo_toml="$1"
138+
declare solana_sdk_dir="$2"
139+
140+
full_path_solana_sdk_dir="$(cd "$solana_sdk_dir" && pwd -P)"
141+
patch_crates=()
142+
for crate_dir in "${crate_dirs[@]}"; do
143+
full_path="$full_path_solana_sdk_dir/$crate_dir"
144+
if [[ -r "$full_path/Cargo.toml" ]]; then
145+
patch_crates+=("solana-${crate_dir} = { path = \"$full_path\" }")
146+
fi
147+
done
148+
149+
echo "Patching in crates from $solana_sdk_dir"
150+
echo
151+
if grep -q "# The following entries are auto-generated by $0" "$Cargo_toml"; then
152+
echo "$Cargo_toml is already patched"
153+
else
154+
if ! grep -q '\[patch.crates-io\]' "$Cargo_toml"; then
155+
echo "[patch.crates-io]" >> "$Cargo_toml"
156+
fi
157+
cat >> "$Cargo_toml" <<PATCH
158+
# The following entries are auto-generated by $0
159+
$(printf "%s\n" "${patch_crates[@]}")
160+
PATCH
161+
fi
162+
}

scripts/patch-crates-no-header.sh

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env bash
2+
3+
set -eo pipefail
4+
here="$(dirname "$0")"
5+
# pacify shellcheck: cannot follow dynamic path
6+
# shellcheck disable=SC1090,SC1091
7+
source "$here"/patch-crates-functions.sh
8+
9+
usage() {
10+
cat <<EOF >&2
11+
USAGE:
12+
$0 <AGAVE_PATH> <SOLANA_SDK_PATH>
13+
14+
ARGS:
15+
<AGAVE_PATH> Path to the root of an agave repo
16+
<SOLANA_SDK_PATH> Path to the root of a solana-sdk repo
17+
EOF
18+
}
19+
20+
agave_path="$1"
21+
if [ -z "$agave_path" ]; then
22+
usage
23+
exit 1
24+
fi
25+
26+
solana_sdk_path="$2"
27+
if [ -z "$solana_sdk_path" ]; then
28+
usage
29+
exit 1
30+
fi
31+
32+
update_solana_sdk_dependencies "$agave_path" "$solana_sdk_path"
33+
patch_crates_io_solana_sdk_no_header "$agave_path"/Cargo.toml "$solana_sdk_path"

0 commit comments

Comments
 (0)