cargo-install-all.sh 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. #!/usr/bin/env bash
  2. #
  3. # |cargo install| of the top-level crate will not install binaries for
  4. # other workspace crates or native program crates.
  5. here="$(dirname "$0")"
  6. readlink_cmd="readlink"
  7. echo "OSTYPE IS: $OSTYPE"
  8. if [[ $OSTYPE == darwin* ]]; then
  9. # Mac OS X's version of `readlink` does not support the -f option,
  10. # But `greadlink` does, which you can get with `brew install coreutils`
  11. readlink_cmd="greadlink"
  12. if ! command -v ${readlink_cmd} &> /dev/null
  13. then
  14. echo "${readlink_cmd} could not be found. You may need to install coreutils: \`brew install coreutils\`"
  15. exit 1
  16. fi
  17. fi
  18. SOLANA_ROOT="$("${readlink_cmd}" -f "${here}/..")"
  19. cargo="${SOLANA_ROOT}/cargo"
  20. set -e
  21. usage() {
  22. exitcode=0
  23. if [[ -n "$1" ]]; then
  24. exitcode=1
  25. echo "Error: $*"
  26. fi
  27. cat <<EOF
  28. usage: $0 [+<cargo version>] [--debug] [--validator-only] [--release-with-debug] <install directory>
  29. EOF
  30. exit $exitcode
  31. }
  32. maybeRustVersion=
  33. installDir=
  34. # buildProfileArg and buildProfile duplicate some information because cargo
  35. # doesn't allow '--profile debug' but we still need to know that the binaries
  36. # will be in target/debug
  37. buildProfileArg='--profile release'
  38. buildProfile='release'
  39. validatorOnly=
  40. while [[ -n $1 ]]; do
  41. if [[ ${1:0:1} = - ]]; then
  42. if [[ $1 = --debug ]]; then
  43. buildProfileArg= # the default cargo profile is 'debug'
  44. buildProfile='debug'
  45. shift
  46. elif [[ $1 = --release-with-debug ]]; then
  47. buildProfileArg='--profile release-with-debug'
  48. buildProfile='release-with-debug'
  49. shift
  50. elif [[ $1 = --validator-only ]]; then
  51. validatorOnly=true
  52. shift
  53. else
  54. usage "Unknown option: $1"
  55. fi
  56. elif [[ ${1:0:1} = \+ ]]; then
  57. maybeRustVersion=$1
  58. shift
  59. else
  60. installDir=$1
  61. shift
  62. fi
  63. done
  64. if [[ -z "$installDir" ]]; then
  65. usage "Install directory not specified"
  66. exit 1
  67. fi
  68. installDir="$(mkdir -p "$installDir"; cd "$installDir"; pwd)"
  69. mkdir -p "$installDir/bin/deps"
  70. echo "Install location: $installDir ($buildProfile)"
  71. cd "$(dirname "$0")"/..
  72. SECONDS=0
  73. if [[ $CI_OS_NAME = windows ]]; then
  74. # Limit windows to end-user command-line tools. Full validator support is not
  75. # yet available on windows
  76. BINS=(
  77. cargo-build-sbf
  78. cargo-test-sbf
  79. solana
  80. agave-install
  81. agave-install-init
  82. solana-keygen
  83. solana-stake-accounts
  84. solana-test-validator
  85. solana-tokens
  86. )
  87. DCOU_BINS=()
  88. else
  89. ./fetch-perf-libs.sh
  90. BINS=(
  91. solana
  92. solana-faucet
  93. solana-genesis
  94. solana-gossip
  95. agave-install
  96. solana-keygen
  97. solana-log-analyzer
  98. solana-net-shaper
  99. agave-validator
  100. rbpf-cli
  101. )
  102. DCOU_BINS=(
  103. agave-ledger-tool
  104. solana-bench-tps
  105. )
  106. # Speed up net.sh deploys by excluding unused binaries
  107. if [[ -z "$validatorOnly" ]]; then
  108. BINS+=(
  109. cargo-build-sbf
  110. cargo-test-sbf
  111. agave-install-init
  112. solana-stake-accounts
  113. solana-test-validator
  114. solana-tokens
  115. agave-watchtower
  116. )
  117. DCOU_BINS+=(
  118. solana-dos
  119. )
  120. fi
  121. fi
  122. binArgs=()
  123. for bin in "${BINS[@]}"; do
  124. binArgs+=(--bin "$bin")
  125. done
  126. dcouBinArgs=()
  127. for bin in "${DCOU_BINS[@]}"; do
  128. dcouBinArgs+=(--bin "$bin")
  129. done
  130. source "$SOLANA_ROOT"/scripts/dcou-tainted-packages.sh
  131. excludeArgs=()
  132. for package in "${dcou_tainted_packages[@]}"; do
  133. excludeArgs+=(--exclude "$package")
  134. done
  135. mkdir -p "$installDir/bin"
  136. cargo_build() {
  137. # shellcheck disable=SC2086 # Don't want to double quote $maybeRustVersion
  138. "$cargo" $maybeRustVersion build $buildProfileArg "$@"
  139. }
  140. # This is called to detect both of unintended activation AND deactivation of
  141. # dcou, in order to make this rather fragile grep more resilient to bitrot...
  142. check_dcou() {
  143. RUSTC_BOOTSTRAP=1 \
  144. cargo_build -Z unstable-options --build-plan "$@" | \
  145. grep -q -F '"feature=\"dev-context-only-utils\""'
  146. }
  147. # Some binaries (like the notable agave-ledger-tool) need to acitivate
  148. # the dev-context-only-utils feature flag to build.
  149. # Build those binaries separately to avoid the unwanted feature unification.
  150. # Note that `--workspace --exclude <dcou tainted packages>` is needed to really
  151. # inhibit the feature unification due to a cargo bug. Otherwise, feature
  152. # unification happens even if cargo build is run only with `--bin` targets
  153. # which don't depend on dcou as part of dependencies at all.
  154. (
  155. set -x
  156. # Make sure dcou is really disabled by peeking the (unstable) build plan
  157. # output after turning rustc into the nightly mode with RUSTC_BOOTSTRAP=1.
  158. # In this way, additional requirement of nightly rustc toolchian is avoided.
  159. # Note that `cargo tree` can't be used, because it doesn't support `--bin`.
  160. if check_dcou "${binArgs[@]}" --workspace "${excludeArgs[@]}"; then
  161. echo 'dcou feature activation is incorrectly activated!'
  162. exit 1
  163. fi
  164. # Build our production binaries without dcou.
  165. cargo_build "${binArgs[@]}" --workspace "${excludeArgs[@]}"
  166. # Finally, build the remaining dev tools with dcou.
  167. if [[ ${#dcouBinArgs[@]} -gt 0 ]]; then
  168. if ! check_dcou "${dcouBinArgs[@]}"; then
  169. echo 'dcou feature activation is incorrectly remain to be deactivated!'
  170. exit 1
  171. fi
  172. cargo_build "${dcouBinArgs[@]}"
  173. fi
  174. # Exclude `spl-token` binary for net.sh builds
  175. if [[ -z "$validatorOnly" ]]; then
  176. # shellcheck source=scripts/spl-token-cli-version.sh
  177. source "$SOLANA_ROOT"/scripts/spl-token-cli-version.sh
  178. # shellcheck disable=SC2086
  179. "$cargo" $maybeRustVersion install --locked spl-token-cli --root "$installDir" $maybeSplTokenCliVersionArg
  180. fi
  181. )
  182. for bin in "${BINS[@]}" "${DCOU_BINS[@]}"; do
  183. cp -fv "target/$buildProfile/$bin" "$installDir"/bin
  184. done
  185. if [[ -d target/perf-libs ]]; then
  186. cp -a target/perf-libs "$installDir"/bin/perf-libs
  187. fi
  188. if [[ -z "$validatorOnly" ]]; then
  189. # shellcheck disable=SC2086 # Don't want to double quote $rust_version
  190. "$cargo" $maybeRustVersion build --manifest-path programs/bpf_loader/gen-syscall-list/Cargo.toml
  191. # shellcheck disable=SC2086 # Don't want to double quote $rust_version
  192. "$cargo" $maybeRustVersion run --bin gen-headers
  193. mkdir -p "$installDir"/bin/platform-tools-sdk/sbf
  194. cp -a platform-tools-sdk/sbf/* "$installDir"/bin/platform-tools-sdk/sbf
  195. fi
  196. (
  197. set -x
  198. # deps dir can be empty
  199. shopt -s nullglob
  200. for dep in target/"$buildProfile"/deps/libsolana*program.*; do
  201. cp -fv "$dep" "$installDir/bin/deps"
  202. done
  203. )
  204. echo "Done after $SECONDS seconds"
  205. echo
  206. echo "To use these binaries:"
  207. echo " export PATH=\"$installDir\"/bin:\"\$PATH\""