install.sh 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. version=v1.43
  103. if [[ ! -e platform-tools-$version.md || ! -e platform-tools ]]; then
  104. (
  105. set -e
  106. rm -rf platform-tools*
  107. job="download \
  108. https://github.com/anza-xyz/platform-tools/releases/download \
  109. $version \
  110. platform-tools-${machine}-${arch}.tar.bz2 \
  111. platform-tools"
  112. get $version platform-tools "$job"
  113. )
  114. exitcode=$?
  115. if [[ $exitcode -ne 0 ]]; then
  116. exit 1
  117. fi
  118. touch platform-tools-$version.md
  119. set -ex
  120. ./platform-tools/rust/bin/rustc --version
  121. ./platform-tools/rust/bin/rustc --print sysroot
  122. set +e
  123. rustup toolchain uninstall solana
  124. set -e
  125. rustup toolchain link solana platform-tools/rust
  126. fi
  127. exit 0