cargo-install-all.sh 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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] [--no-spl-token] <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. noSPLToken=
  41. while [[ -n $1 ]]; do
  42. if [[ ${1:0:1} = - ]]; then
  43. if [[ $1 = --debug ]]; then
  44. buildProfileArg= # the default cargo profile is 'debug'
  45. buildProfile='debug'
  46. shift
  47. elif [[ $1 = --release-with-debug ]]; then
  48. buildProfileArg='--profile release-with-debug'
  49. buildProfile='release-with-debug'
  50. shift
  51. elif [[ $1 = --release-with-lto ]]; then
  52. buildProfileArg='--profile release-with-lto'
  53. buildProfile='release-with-lto'
  54. shift
  55. elif [[ $1 = --validator-only ]]; then
  56. validatorOnly=true
  57. shift
  58. elif [[ $1 = --no-spl-token ]]; then
  59. noSPLToken=true
  60. shift
  61. else
  62. usage "Unknown option: $1"
  63. fi
  64. elif [[ ${1:0:1} = \+ ]]; then
  65. maybeRustVersion=$1
  66. shift
  67. else
  68. installDir=$1
  69. shift
  70. fi
  71. done
  72. if [[ -z "$installDir" ]]; then
  73. usage "Install directory not specified"
  74. exit 1
  75. fi
  76. installDir="$(mkdir -p "$installDir"; cd "$installDir"; pwd)"
  77. mkdir -p "$installDir/bin/deps"
  78. echo "Install location: $installDir ($buildProfile)"
  79. cd "$(dirname "$0")"/..
  80. SECONDS=0
  81. source "$SOLANA_ROOT"/scripts/agave-build-lists.sh
  82. BINS=()
  83. DCOU_BINS=()
  84. if [[ -n "$validatorOnly" ]]; then
  85. echo "Building binaries for net.sh deploys: ${AGAVE_BINS_END_USER[*]} ${AGAVE_BINS_VAL_OP[*]} ${AGAVE_BINS_DCOU[*]}"
  86. BINS+=("${AGAVE_BINS_END_USER[@]}" "${AGAVE_BINS_VAL_OP[@]}")
  87. DCOU_BINS+=("${AGAVE_BINS_DCOU[@]}")
  88. else
  89. echo "Building binaries for all platforms: ${AGAVE_BINS_DEV[*]} ${AGAVE_BINS_END_USER[*]} ${AGAVE_BINS_DEPRECATED[*]}"
  90. BINS+=("${AGAVE_BINS_DEV[@]}" "${AGAVE_BINS_END_USER[@]}" "${AGAVE_BINS_DEPRECATED[@]}")
  91. if [[ $OSTYPE != msys ]]; then
  92. echo "Building binaries for linux and osx only: ${AGAVE_BINS_VAL_OP[*]}, ${AGAVE_BINS_DCOU[*]}"
  93. BINS+=("${AGAVE_BINS_VAL_OP[@]}")
  94. DCOU_BINS+=("${AGAVE_BINS_DCOU[@]}")
  95. fi
  96. fi
  97. binArgs=()
  98. for bin in "${BINS[@]}"; do
  99. binArgs+=(--bin "$bin")
  100. done
  101. dcouBinArgs=()
  102. for bin in "${DCOU_BINS[@]}"; do
  103. dcouBinArgs+=(--bin "$bin")
  104. done
  105. cargo_build() {
  106. # shellcheck disable=SC2086 # Don't want to double quote $maybeRustVersion
  107. "$cargo" $maybeRustVersion build $buildProfileArg "$@"
  108. }
  109. # This is called to detect both of unintended activation AND deactivation of
  110. # dcou, in order to make this rather fragile grep more resilient to bitrot...
  111. check_dcou() {
  112. RUSTC_BOOTSTRAP=1 \
  113. cargo_build -Z unstable-options --build-plan "$@" | \
  114. grep -q -F '"feature=\"dev-context-only-utils\""'
  115. }
  116. # Some binaries (like the notable agave-ledger-tool) need to activate
  117. # the dev-context-only-utils feature flag to build.
  118. # Build those binaries separately to avoid the unwanted feature unification.
  119. # Note that `--workspace --exclude <dcou tainted packages>` is needed to really
  120. # inhibit the feature unification due to a cargo bug. Otherwise, feature
  121. # unification happens even if cargo build is run only with `--bin` targets
  122. # which don't depend on dcou as part of dependencies at all.
  123. (
  124. set -x
  125. # Make sure dcou is really disabled by peeking the (unstable) build plan
  126. # output after turning rustc into the nightly mode with RUSTC_BOOTSTRAP=1.
  127. # In this way, additional requirement of nightly rustc toolchian is avoided.
  128. # Note that `cargo tree` can't be used, because it doesn't support `--bin`.
  129. if check_dcou "${binArgs[@]}" --workspace; then
  130. echo 'dcou feature activation is incorrectly activated!'
  131. exit 1
  132. fi
  133. # Build our production binaries without dcou.
  134. cargo_build "${binArgs[@]}" --workspace
  135. # Finally, build the remaining dev tools with dcou.
  136. if [[ ${#dcouBinArgs[@]} -gt 0 ]]; then
  137. if ! check_dcou --manifest-path "dev-bins/Cargo.toml" "${dcouBinArgs[@]}"; then
  138. echo 'dcou feature activation is incorrectly remain to be deactivated!'
  139. exit 1
  140. fi
  141. cargo_build --manifest-path "dev-bins/Cargo.toml" "${dcouBinArgs[@]}"
  142. fi
  143. # Exclude `spl-token` if requested
  144. if [[ -z "$noSPLToken" ]]; then
  145. # shellcheck source=scripts/spl-token-cli-version.sh
  146. source "$SOLANA_ROOT"/scripts/spl-token-cli-version.sh
  147. # shellcheck disable=SC2086
  148. "$cargo" $maybeRustVersion install --locked spl-token-cli --root "$installDir" $maybeSplTokenCliVersionArg
  149. fi
  150. )
  151. for bin in "${BINS[@]}"; do
  152. cp -fv "target/$buildProfile/$bin" "$installDir"/bin
  153. done
  154. for bin in "${DCOU_BINS[@]}"; do
  155. cp -fv "dev-bins/target/$buildProfile/$bin" "$installDir"/bin
  156. done
  157. if [[ $OSTYPE != msys ]]; then
  158. ./fetch-perf-libs.sh
  159. if [[ -d target/perf-libs ]]; then
  160. cp -a target/perf-libs "$installDir"/bin/perf-libs
  161. fi
  162. fi
  163. if [[ -z "$validatorOnly" ]]; then
  164. # shellcheck disable=SC2086 # Don't want to double quote $rust_version
  165. "$cargo" $maybeRustVersion build --manifest-path syscalls/gen-syscall-list/Cargo.toml
  166. # shellcheck disable=SC2086 # Don't want to double quote $rust_version
  167. "$cargo" $maybeRustVersion run --bin gen-headers
  168. mkdir -p "$installDir"/bin/platform-tools-sdk/sbf
  169. cp -a platform-tools-sdk/sbf/* "$installDir"/bin/platform-tools-sdk/sbf
  170. fi
  171. (
  172. set -x
  173. # deps dir can be empty
  174. shopt -s nullglob
  175. for dep in target/"$buildProfile"/deps/libsolana*program.*; do
  176. cp -fv "$dep" "$installDir"/bin/deps
  177. done
  178. )
  179. echo "Done after $SECONDS seconds"
  180. echo
  181. echo "To use these binaries:"
  182. echo " export PATH=\"$installDir\"/bin:\"\$PATH\""