install.sh 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. #!/usr/bin/env bash
  2. mkdir -p "$(dirname "$0")"/../dependencies
  3. cd "$(dirname "$0")"/../dependencies
  4. unameOut="$(uname -s)"
  5. case "${unameOut}" in
  6. Linux*)
  7. criterion_suffix=
  8. machine=linux;;
  9. Darwin*)
  10. criterion_suffix=
  11. machine=osx;;
  12. MINGW*)
  13. criterion_suffix=-mingw
  14. machine=windows;;
  15. *)
  16. criterion_suffix=
  17. machine=linux
  18. esac
  19. unameOut="$(uname -m)"
  20. case "${unameOut}" in
  21. arm64*)
  22. arch=aarch64;;
  23. *)
  24. arch=x86_64
  25. esac
  26. download() {
  27. declare url="$1/$2/$3"
  28. declare filename=$3
  29. declare wget_args=(
  30. "$url" -O "$filename"
  31. "--progress=dot:giga"
  32. "--retry-connrefused"
  33. "--read-timeout=30"
  34. )
  35. declare curl_args=(
  36. -L "$url" -o "$filename"
  37. )
  38. if hash wget 2>/dev/null; then
  39. wget_or_curl="wget ${wget_args[*]}"
  40. elif hash curl 2>/dev/null; then
  41. wget_or_curl="curl ${curl_args[*]}"
  42. else
  43. echo "Error: Neither curl nor wget were found" >&2
  44. return 1
  45. fi
  46. set -x
  47. if $wget_or_curl; then
  48. tar --strip-components 1 -jxf "$filename" || return 1
  49. { set +x; } 2>/dev/null
  50. rm -rf "$filename"
  51. return 0
  52. fi
  53. return 1
  54. }
  55. get() {
  56. declare version=$1
  57. declare dirname=$2
  58. declare job=$3
  59. declare cache_root=~/.cache/solana
  60. declare cache_dirname="$cache_root/$version/$dirname"
  61. declare cache_partial_dirname="$cache_dirname"_partial
  62. if [[ -r $cache_dirname ]]; then
  63. ln -sf "$cache_dirname" "$dirname" || return 1
  64. return 0
  65. fi
  66. rm -rf "$cache_partial_dirname" || return 1
  67. mkdir -p "$cache_partial_dirname" || return 1
  68. pushd "$cache_partial_dirname"
  69. if $job; then
  70. popd
  71. mv "$cache_partial_dirname" "$cache_dirname" || return 1
  72. ln -sf "$cache_dirname" "$dirname" || return 1
  73. return 0
  74. fi
  75. popd
  76. return 1
  77. }
  78. # Install Criterion
  79. if [[ $machine == "linux" ]]; then
  80. version=v2.3.3
  81. else
  82. version=v2.3.2
  83. fi
  84. if [[ ! -e criterion-$version.md || ! -e criterion ]]; then
  85. (
  86. set -e
  87. rm -rf criterion*
  88. job="download \
  89. https://github.com/Snaipe/Criterion/releases/download \
  90. $version \
  91. criterion-$version-$machine$criterion_suffix-x86_64.tar.bz2 \
  92. criterion"
  93. get $version criterion "$job"
  94. )
  95. exitcode=$?
  96. if [[ $exitcode -ne 0 ]]; then
  97. exit 1
  98. fi
  99. touch criterion-$version.md
  100. fi
  101. # Install platform tools
  102. tools_version=v1.52
  103. rust_version=1.89.0
  104. if [[ ! -e platform-tools-$tools_version.md || ! -e platform-tools ]]; then
  105. (
  106. set -e
  107. rm -rf platform-tools*
  108. job="download \
  109. https://github.com/anza-xyz/platform-tools/releases/download \
  110. $tools_version \
  111. platform-tools-${machine}-${arch}.tar.bz2 \
  112. platform-tools"
  113. get $tools_version platform-tools "$job"
  114. )
  115. exitcode=$?
  116. if [[ $exitcode -ne 0 ]]; then
  117. exit 1
  118. fi
  119. touch platform-tools-$tools_version.md
  120. set -ex
  121. ./platform-tools/rust/bin/rustc --version
  122. ./platform-tools/rust/bin/rustc --print sysroot
  123. if [[ "${BASH_VERSINFO[0]}" -lt 4 ]]; then
  124. # MacOS has an outdated version of bash and does not support the safer 'mapfile' alternative
  125. toolchains=()
  126. while IFS='' read -r line; do toolchains+=("$line"); done < <(rustup toolchain list)
  127. else
  128. mapfile -t toolchains < <(rustup toolchain list)
  129. fi
  130. set +e
  131. for item in "${toolchains[@]}"
  132. do
  133. if [[ $item == *"solana"* ]]; then
  134. rustup toolchain uninstall "$item"
  135. fi
  136. done
  137. set -e
  138. rustup toolchain link "$rust_version-sbpf-solana-$tools_version" platform-tools/rust
  139. fi
  140. exit 0