cargo-install-all.sh 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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 = --release-with-lto ]]; then
  51. buildProfileArg='--profile release-with-lto'
  52. buildProfile='release-with-lto'
  53. shift
  54. elif [[ $1 = --validator-only ]]; then
  55. validatorOnly=true
  56. shift
  57. else
  58. usage "Unknown option: $1"
  59. fi
  60. elif [[ ${1:0:1} = \+ ]]; then
  61. maybeRustVersion=$1
  62. shift
  63. else
  64. installDir=$1
  65. shift
  66. fi
  67. done
  68. if [[ -z "$installDir" ]]; then
  69. usage "Install directory not specified"
  70. exit 1
  71. fi
  72. installDir="$(mkdir -p "$installDir"; cd "$installDir"; pwd)"
  73. mkdir -p "$installDir/bin/deps"
  74. echo "Install location: $installDir ($buildProfile)"
  75. cd "$(dirname "$0")"/..
  76. SECONDS=0
  77. source "$SOLANA_ROOT"/scripts/agave-build-lists.sh
  78. BINS=()
  79. DCOU_BINS=()
  80. if [[ -n "$validatorOnly" ]]; then
  81. echo "Building binaries for net.sh deploys: ${AGAVE_BINS_END_USER[*]} ${AGAVE_BINS_VAL_OP[*]} ${AGAVE_BINS_DCOU[*]}"
  82. BINS+=("${AGAVE_BINS_END_USER[@]}" "${AGAVE_BINS_VAL_OP[@]}")
  83. DCOU_BINS+=("${AGAVE_BINS_DCOU[@]}")
  84. else
  85. echo "Building binaries for all platforms: ${AGAVE_BINS_DEV[*]} ${AGAVE_BINS_END_USER[*]} ${AGAVE_BINS_DEPRECATED[*]}"
  86. BINS+=("${AGAVE_BINS_DEV[@]}" "${AGAVE_BINS_END_USER[@]}" "${AGAVE_BINS_DEPRECATED[@]}")
  87. if [[ $CI_OS_NAME != windows ]]; then
  88. echo "Building binaries for linux and osx only: ${AGAVE_BINS_VAL_OP[*]}, ${AGAVE_BINS_DCOU[*]}"
  89. BINS+=("${AGAVE_BINS_VAL_OP[@]}")
  90. DCOU_BINS+=("${AGAVE_BINS_DCOU[@]}")
  91. fi
  92. fi
  93. binArgs=()
  94. for bin in "${BINS[@]}"; do
  95. binArgs+=(--bin "$bin")
  96. done
  97. dcouBinArgs=()
  98. for bin in "${DCOU_BINS[@]}"; do
  99. dcouBinArgs+=(--bin "$bin")
  100. done
  101. excludeArgs=()
  102. for package in "${DCOU_TAINTED_PACKAGES[@]}"; do
  103. excludeArgs+=(--exclude "$package")
  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 "${excludeArgs[@]}"; 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 "${excludeArgs[@]}"
  135. # Finally, build the remaining dev tools with dcou.
  136. if [[ ${#dcouBinArgs[@]} -gt 0 ]]; then
  137. if ! check_dcou "${dcouBinArgs[@]}"; then
  138. echo 'dcou feature activation is incorrectly remain to be deactivated!'
  139. exit 1
  140. fi
  141. cargo_build "${dcouBinArgs[@]}"
  142. fi
  143. # Exclude `spl-token` binary for net.sh builds
  144. if [[ -z "$validatorOnly" ]]; 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[@]}" "${DCOU_BINS[@]}"; do
  152. cp -fv "target/$buildProfile/$bin" "$installDir"/bin
  153. done
  154. if [[ $CI_OS_NAME != windows ]]; then
  155. ./fetch-perf-libs.sh
  156. if [[ -d target/perf-libs ]]; then
  157. cp -a target/perf-libs "$installDir"/bin/perf-libs
  158. fi
  159. fi
  160. if [[ -z "$validatorOnly" ]]; then
  161. # shellcheck disable=SC2086 # Don't want to double quote $rust_version
  162. "$cargo" $maybeRustVersion build --manifest-path syscalls/gen-syscall-list/Cargo.toml
  163. # shellcheck disable=SC2086 # Don't want to double quote $rust_version
  164. "$cargo" $maybeRustVersion run --bin gen-headers
  165. mkdir -p "$installDir"/bin/platform-tools-sdk/sbf
  166. cp -a platform-tools-sdk/sbf/* "$installDir"/bin/platform-tools-sdk/sbf
  167. fi
  168. (
  169. set -x
  170. # deps dir can be empty
  171. shopt -s nullglob
  172. for dep in target/"$buildProfile"/deps/libsolana*program.*; do
  173. cp -fv "$dep" "$installDir"/bin/deps
  174. done
  175. )
  176. echo "Done after $SECONDS seconds"
  177. echo
  178. echo "To use these binaries:"
  179. echo " export PATH=\"$installDir\"/bin:\"\$PATH\""