rust-version.sh 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #
  2. # This file maintains the rust versions for use by CI.
  3. #
  4. # Obtain the environment variables without any automatic toolchain updating:
  5. # $ source ci/rust-version.sh
  6. #
  7. # Obtain the environment variables updating both stable and nightly, only stable, or
  8. # only nightly:
  9. # $ source ci/rust-version.sh all
  10. # $ source ci/rust-version.sh stable
  11. # $ source ci/rust-version.sh nightly
  12. # Then to build with either stable or nightly:
  13. # $ cargo +"$rust_stable" build
  14. # $ cargo +"$rust_nightly" build
  15. #
  16. if [[ -n ${RUST_STABLE_VERSION:-} ]]; then
  17. stable_version="$RUST_STABLE_VERSION"
  18. else
  19. # read rust version from rust-toolchain.toml file
  20. base="$(dirname "${BASH_SOURCE[0]}")"
  21. # pacify shellcheck: cannot follow dynamic path
  22. # shellcheck disable=SC1090,SC1091
  23. source "$base/../scripts/read-cargo-variable.sh"
  24. stable_version=$(readCargoVariable channel "$base/../rust-toolchain.toml")
  25. fi
  26. if [[ -n ${RUST_NIGHTLY_VERSION:-} ]]; then
  27. nightly_version="$RUST_NIGHTLY_VERSION"
  28. else
  29. nightly_version=2025-08-02
  30. fi
  31. export rust_stable="$stable_version"
  32. export rust_nightly=nightly-"$nightly_version"
  33. if [[ -n ${NO_INSTALL:-} ]]; then
  34. return
  35. fi
  36. [[ -z $1 ]] || (
  37. rustup_install() {
  38. declare toolchain=$1
  39. if ! cargo +"$toolchain" -V > /dev/null; then
  40. echo "$0: Missing toolchain? Installing...: $toolchain" >&2
  41. rustup install "$toolchain" --no-self-update
  42. cargo +"$toolchain" -V
  43. fi
  44. }
  45. set -e
  46. cd "$(dirname "${BASH_SOURCE[0]}")"
  47. case $1 in
  48. stable)
  49. rustup_install "$rust_stable"
  50. ;;
  51. nightly)
  52. rustup_install "$rust_nightly"
  53. ;;
  54. all)
  55. rustup_install "$rust_stable"
  56. rustup_install "$rust_nightly"
  57. ;;
  58. *)
  59. echo "$0: Note: ignoring unknown argument: $1" >&2
  60. ;;
  61. esac
  62. )