-
Notifications
You must be signed in to change notification settings - Fork 0
/
devenv.nix
338 lines (322 loc) · 9.56 KB
/
devenv.nix
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
{ pkgs, lib, ... }:
{
packages =
[
pkgs.binaryen
pkgs.cargo-binstall
pkgs.cargo-run-bin
pkgs.chromedriver
pkgs.curl
pkgs.dprint
pkgs.geckodriver
pkgs.jq
pkgs.libiconv
pkgs.nixfmt-rfc-style
pkgs.openssl
pkgs.protobuf # needed for `solana-test-validator` in tests
pkgs.rustup
pkgs.shfmt
]
++ lib.optionals pkgs.stdenv.isDarwin (
with pkgs.darwin.apple_sdk;
[
pkgs.coreutils
frameworks.CoreFoundation
frameworks.Security
frameworks.System
frameworks.SystemConfiguration
]
);
# disable dotenv since it breaks the variable interpolation supported by `direnv`
dotenv.disableHint = true;
scripts.anchor = {
exec = ''
set -e
cargo bin anchor $@
'';
description = "The `anchor` executable";
};
scripts."release-plz" = {
exec = ''
set -e
cargo bin release-plz $@
'';
description = "The `release-plz` executable";
};
scripts."wasm-bindgen-test-runner" = {
exec = ''
set -e
cargo bin wasm-bindgen-test-runner $@
'';
description = "The `wasm-bindgen-test-runner` executable";
};
scripts."install:all" = {
exec = ''
set -e
install:cargo:bin
install:solana
'';
description = "Install all packages.";
};
scripts."generate:keypair" = {
exec = ''
set -e
solana-keygen new -s -o $DEVENV_ROOT/$1.json --no-bip39-passphrase || true
'';
description = "Generate a local solana keypair. Must provide a name.";
};
scripts."install:cargo:bin" = {
exec = ''
set -e
cargo bin --install
'';
description = "Install cargo binaries locally.";
};
scripts."update:deps" = {
exec = ''
set -e
cargo update
devenv update
'';
description = "Update dependencies.";
};
scripts."build:all" = {
exec = ''
set -e
if [ -z "$CI" ]; then
echo "Builing project locally"
cargo build --all-features
else
echo "Building in CI"
cargo build --all-features --locked
fi
'';
description = "Build all crates with all features activated.";
};
scripts."build:docs" = {
exec = ''
RUSTDOCFLAGS="--cfg docsrs" cargo doc --workspace --exclude example_program --exclude example_client --exclude test_utils_solana --exclude test_utils_anchor
'';
description = "Build documentation site.";
};
scripts."test:all" = {
exec = ''
set -e
cargo test_memory_wallet_ssr
cargo test_memory_wallet_docs
cargo test_wasm_client_solana_ssr
cargo test_wasm_client_solana_docs
cargo test_streams
cargo test_example_client
test:validator
'';
description = "Run all tests across the crates";
};
scripts."test:validator" = {
exec = ''
set -e
validator:bg &
pid=$!
function cleanup {
validator:kill
kill -9 $pid
}
trap cleanup EXIT
export WASM_BINDGEN_TEST_TIMEOUT=90
cargo bin wait-for-them -t 10000 127.0.0.1:8899
sleep 5
echo "running tests in chrome..."
CHROMEDRIVER=$DEVENV_DOTFILE/profile/bin/chromedriver cargo test_wasm
echo "running tests in firefox..."
GECKODRIVER=$DEVENV_DOTFILE/profile/bin/geckodriver cargo test_wasm
'';
description = "Run tests with a validator in the background.";
};
scripts."coverage:all" = {
exec = ''
set -e
cargo coverage_memory_wallet_ssr
cargo coverage_memory_wallet_docs
cargo coverage_wasm_client_solana_ssr
cargo coverage_wasm_client_solana_docs
cargo coverage_streams
cargo coverage_example_client
cargo coverage_codecov_report
'';
description = "Run coverage across the crates";
};
scripts."fix:all" = {
exec = ''
set -e
fix:clippy
fix:format
'';
description = "Fix all autofixable problems.";
};
scripts."fix:format" = {
exec = ''
set -e
dprint fmt --config "$DEVENV_ROOT/dprint.json"
'';
description = "Format files with dprint.";
};
scripts."fix:clippy" = {
exec = ''
set -e
cargo clippy --fix --allow-dirty --allow-staged --all-features
'';
description = "Fix clippy lints for rust.";
};
scripts."lint:all" = {
exec = ''
set -e
lint:clippy
lint:format
'';
description = "Run all checks.";
};
scripts."lint:format" = {
exec = ''
set -e
dprint check
'';
description = "Check that all files are formatted.";
};
scripts."lint:clippy" = {
exec = ''
set -e
cargo clippy --all-features
'';
description = "Check that all rust lints are passing.";
};
scripts."validator:run" = {
exec = ''
set -e
solana-test-validator --warp-slot 1000 --reset --quiet
'';
description = "Run the solana validator.";
};
scripts."validator:bg" = {
exec = ''
set -e
validator:kill
validator:run
'';
description = "Run the solana validator in the background";
};
scripts."validator:kill" = {
exec = ''
pids=$(lsof -i :8899 -t)
if [ -n "$pids" ]; then
kill $pids
echo "Killed processes listening on port $port: $pids"
else
echo "No processes found listening on port $port"
fi
'';
description = "Kill any running validator";
};
scripts."setup:vscode" = {
exec = ''
set -e
rm -rf .vscode
cp -r $DEVENV_ROOT/setup/editors/vscode .vscode
'';
description = "Setup the environment for vscode.";
};
scripts."setup:helix" = {
exec = ''
set -e
rm -rf .helix
cp -r $DEVENV_ROOT/setup/editors/helix .helix
'';
description = "Setup for the helix editor.";
};
scripts."setup:ci" = {
exec = ''
set -e
# update github ci path
echo "$DEVENV_PROFILE/bin" >> $GITHUB_PATH
echo "$GITHUB_WORKSPACE/.local-cache/solana-release/bin" >> $GITHUB_PATH
# update github ci environment
echo "DEVENV_PROFILE=$DEVENV_PROFILE" >> $GITHUB_ENV
# prepend common compilation lookup paths
echo "PKG_CONFIG_PATH=$PKG_CONFIG_PATH" >> $GITHUB_ENV
echo "LD_LIBRARY_PATH=$LD_LIBRARY_PATH" >> $GITHUB_ENV
echo "LIBRARY_PATH=$LIBRARY_PATH" >> $GITHUB_ENV
echo "C_INCLUDE_PATH=$C_INCLUDE_PATH" >> $GITHUB_ENV
# these provide shell completions / default config options
echo "XDG_DATA_DIRS=$XDG_DATA_DIRS" >> $GITHUB_ENV
echo "XDG_CONFIG_DIRS=$XDG_CONFIG_DIRS" >> $GITHUB_ENV
echo "DEVENV_DOTFILE=$DEVENV_DOTFILE" >> $GITHUB_ENV
echo "DEVENV_PROFILE=$DEVENV_PROFILE" >> $GITHUB_ENV
echo "DEVENV_ROOT=$DEVENV_ROOT" >> $GITHUB_ENV
echo "DEVENV_STATE=$DEVENV_STATE" >> $GITHUB_ENV
# Temporary fix for a bug in [email protected] https://github.com/coral-xyz/anchor/issues/3042
echo "ANCHOR_IDL_BUILD_PROGRAM_PATH=$DEVENV_ROOT/programs/example_program" >> $GITHUB_ENV
'';
description = "Setup devenv for GitHub Actions";
};
scripts."setup:docker" = {
exec = ''
set -e
# update path
echo "export PATH=$DEVENV_PROFILE/bin:\$PATH" >> /etc/profile
echo "export PATH=$DEVENV_ROOT/.local-cache/solana-release/bin:\$PATH" >> /etc/profile
echo "export DEVENV_PROFILE=$DEVENV_PROFILE" >> /etc/profile
echo "export PKG_CONFIG_PATH=$PKG_CONFIG_PATH" >> /etc/profile
echo "export LD_LIBRARY_PATH=$LD_LIBRARY_PATH" >> /etc/profile
echo "export LIBRARY_PATH=$LIBRARY_PATH" >> /etc/profile
echo "export C_INCLUDE_PATH=$C_INCLUDE_PATH" >> /etc/profile
echo "export XDG_DATA_DIRS=$XDG_DATA_DIRS" >> /etc/profile
echo "export XDG_CONFIG_DIRS=$XDG_CONFIG_DIRS" >> /etc/profile
echo "export DEVENV_DOTFILE=$DEVENV_DOTFILE" >> /etc/profile
echo "export DEVENV_PROFILE=$DEVENV_PROFILE" >> /etc/profile
echo "export DEVENV_ROOT=$DEVENV_ROOT" >> /etc/profile
echo "export DEVENV_STATE=$DEVENV_STATE" >> /etc/profile
# Temporary fix for a bug in [email protected] https://github.com/coral-xyz/anchor/issues/3042
echo "export ANCHOR_IDL_BUILD_PROGRAM_PATH=$DEVENV_ROOT/programs/example_program" >> /etc/profile
'';
description = "Setup devenv shell for docker.";
};
scripts."install:solana" = {
exec = ''
set -e
SOLANA_DOWNLOAD_ROOT="https://github.com/anza-xyz/agave/releases/download"
LOCAL_CACHE="$DEVENV_ROOT/.local-cache"
VERSION=`cat $DEVENV_ROOT/setup/cache-versions.json | jq -r '.solana'`
OS_TYPE="$(uname -s)"
CPU_TYPE="$(uname -m)"
case "$OS_TYPE" in
Linux)
OS_TYPE=unknown-linux-gnu
;;
Darwin)
if [[ $CPU_TYPE = arm64 ]]; then
CPU_TYPE=aarch64
fi
OS_TYPE=apple-darwin
;;
*)
err "machine architecture is currently unsupported"
;;
esac
TARGET="$CPU_TYPE-$OS_TYPE"
mkdir -p $LOCAL_CACHE
TARBALL_PATH=solana-release-$TARGET.tar.bz2
LOCAL_TARBALL_PATH=solana-$VERSION-release-$TARGET.tar.bz2
FULL_TARBALL_PATH="$LOCAL_CACHE/$LOCAL_TARBALL_PATH"
if [[ -e $FULL_TARBALL_PATH ]]
then
echo "Using cached solana release"
else
DOWNLOAD_URL="$SOLANA_DOWNLOAD_ROOT/$VERSION/$TARBALL_PATH"
echo "Downloading $DOWNLOAD_URL to the local cache $FULL_TARBALL_PATH"
curl --header "Authorization: Bearer $TEST_GITHUB_ACCESS_TOKEN" -sSfL "$DOWNLOAD_URL" -O
mv $TARBALL_PATH $FULL_TARBALL_PATH
tar jxf $FULL_TARBALL_PATH -C $LOCAL_CACHE
fi
'';
description = "Install the version of solana or use one from the cache.";
};
}