solana/sdk/bpf/scripts/install.sh

133 lines
2.8 KiB
Bash
Raw Normal View History

2018-11-26 10:35:24 -08:00
#!/usr/bin/env bash
2021-02-18 11:30:08 -08:00
mkdir -p "$(dirname "$0")"/../dependencies
2019-06-17 11:04:38 -07:00
cd "$(dirname "$0")"/../dependencies
2018-11-26 10:35:24 -08:00
unameOut="$(uname -s)"
case "${unameOut}" in
Linux*)
criterion_suffix=
machine=linux;;
Darwin*)
criterion_suffix=
machine=osx;;
MINGW*)
criterion_suffix=-mingw
machine=windows;;
*)
criterion_suffix=
machine=linux
esac
2018-12-02 21:07:44 -08:00
download() {
declare url="$1/$2/$3"
2020-04-28 21:06:04 -07:00
declare filename=$3
2020-10-27 22:43:34 -07:00
declare wget_args=(
"$url" -O "$filename"
2020-10-27 22:43:34 -07:00
"--progress=dot:giga"
"--retry-connrefused"
"--read-timeout=30"
)
2020-10-27 22:43:34 -07:00
declare curl_args=(
-L "$url" -o "$filename"
)
if hash wget 2>/dev/null; then
wget_or_curl="wget ${wget_args[*]}"
elif hash curl 2>/dev/null; then
wget_or_curl="curl ${curl_args[*]}"
else
echo "Error: Neither curl nor wget were found" >&2
return 1
fi
set -x
2020-10-27 22:43:34 -07:00
if $wget_or_curl; then
tar --strip-components 1 -jxf "$filename" || return 1
{ set +x; } 2>/dev/null
rm -rf "$filename"
return 0
fi
return 1
}
2020-10-27 22:43:34 -07:00
get() {
declare version=$1
declare dirname=$2
declare job=$3
declare cache_root=~/.cache/solana
declare cache_dirname="$cache_root/$version/$dirname"
declare cache_partial_dirname="$cache_dirname"_partial
if [[ -r $cache_dirname ]]; then
2020-10-27 22:43:34 -07:00
ln -sf "$cache_dirname" "$dirname" || return 1
return 0
fi
2020-10-27 22:43:34 -07:00
rm -rf "$cache_partial_dirname" || return 1
mkdir -p "$cache_partial_dirname" || return 1
pushd "$cache_partial_dirname"
if $job; then
popd
2020-10-27 22:43:34 -07:00
mv "$cache_partial_dirname" "$cache_dirname" || return 1
ln -sf "$cache_dirname" "$dirname" || return 1
2020-04-06 20:16:58 -07:00
return 0
fi
2020-10-27 22:43:34 -07:00
popd
2020-04-06 20:16:58 -07:00
return 1
}
2018-12-02 21:07:44 -08:00
# Install Criterion
2020-12-07 13:53:28 -08:00
if [[ $machine == "linux" ]]; then
version=v2.3.3
else
version=v2.3.2
fi
2020-10-27 22:43:34 -07:00
if [[ ! -e criterion-$version.md || ! -e criterion ]]; then
(
set -e
rm -rf criterion*
2020-10-27 22:43:34 -07:00
job="download \
https://github.com/Snaipe/Criterion/releases/download \
$version \
criterion-$version-$machine$criterion_suffix-x86_64.tar.bz2 \
2020-10-27 22:43:34 -07:00
criterion"
get $version criterion "$job"
)
exitcode=$?
if [[ $exitcode -ne 0 ]]; then
exit 1
fi
2020-10-27 22:43:34 -07:00
touch criterion-$version.md
fi
# Install Rust-BPF
2022-07-29 14:11:33 -07:00
version=v1.29
2021-02-18 11:30:08 -08:00
if [[ ! -e bpf-tools-$version.md || ! -e bpf-tools ]]; then
(
set -e
2021-02-18 11:30:08 -08:00
rm -rf bpf-tools*
rm -rf xargo
2020-10-27 22:43:34 -07:00
job="download \
2021-02-18 11:30:08 -08:00
https://github.com/solana-labs/bpf-tools/releases/download \
2020-10-27 22:43:34 -07:00
$version \
2021-02-18 11:30:08 -08:00
solana-bpf-tools-$machine.tar.bz2 \
bpf-tools"
get $version bpf-tools "$job"
)
exitcode=$?
if [[ $exitcode -ne 0 ]]; then
exit 1
fi
2021-02-18 11:30:08 -08:00
touch bpf-tools-$version.md
set -ex
./bpf-tools/rust/bin/rustc --version
./bpf-tools/rust/bin/rustc --print sysroot
set +e
rustup toolchain uninstall bpf
set -e
rustup toolchain link bpf bpf-tools/rust
fi
2018-12-11 15:20:40 -08:00
exit 0