Skip to content

Commit df455af

Browse files
scripts
1 parent 5dee0f0 commit df455af

File tree

3 files changed

+138
-1
lines changed

3 files changed

+138
-1
lines changed

ci/cargo-command.sh

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#!/bin/bash
2+
3+
# Function to display help message
4+
show_help() {
5+
echo "Usage: $0 [stable|nightly] [command]"
6+
echo
7+
echo "This script is used to run a specified cargo command with either the stable or nightly Rust toolchain."
8+
echo
9+
echo "Arguments:"
10+
echo " stable - Use the stable Rust toolchain."
11+
echo " nightly - Use the nightly Rust toolchain."
12+
echo " command - The cargo command to run (e.g., clippy, build)."
13+
echo
14+
echo "Examples:"
15+
echo " $0 stable clippy - Run clippy with the stable Rust version."
16+
echo " $0 nightly build - Build with the nightly Rust version."
17+
}
18+
19+
# Function to run a specified cargo command with a specified toolchain
20+
run_cargo_command() {
21+
local toolchain=$1
22+
local command=$2
23+
echo "Running cargo $command with Rust $toolchain version..."
24+
cargo +"$toolchain" "$command"
25+
}
26+
27+
# Check if the first argument is -h or --help
28+
if [[ $1 == "-h" || $1 == "--help" ]]; then
29+
show_help
30+
exit 0
31+
fi
32+
33+
# Check if the second argument is not provided
34+
if [[ -z $2 ]]; then
35+
echo "Error: No command specified."
36+
show_help
37+
exit 1
38+
fi
39+
40+
# Path to the rust-version.sh script
41+
rust_version_script="./ci/rust-version.sh"
42+
43+
# Check if rust-version.sh exists and is executable
44+
if [[ -f "$rust_version_script" && -x "$rust_version_script" ]]; then
45+
# Source the rust-version.sh script
46+
source "$rust_version_script"
47+
else
48+
echo "Error: rust-version.sh not found or not executable."
49+
exit 1
50+
fi
51+
52+
53+
# Main execution logic based on passed arguments
54+
case $1 in
55+
stable)
56+
# Check if Rust stable version is set
57+
if [[ -z $rust_stable ]]; then
58+
echo "Error: Rust stable version is not set."
59+
exit 1
60+
fi
61+
run_cargo_command "$rust_stable" "$2"
62+
;;
63+
nightly)
64+
# Check if Rust nightly version is set
65+
if [[ -z $rust_nightly ]]; then
66+
echo "Error: Rust nightly version is not set."
67+
exit 1
68+
fi
69+
run_cargo_command "$rust_nightly" "$2"
70+
;;
71+
*)
72+
echo "Usage: $0 [stable|nightly] [command]"
73+
exit 1
74+
;;
75+
esac

ci/rust-version.sh

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
readCargoVariable() {
2+
declare variable="$1"
3+
declare Cargo_toml="$2"
4+
5+
while read -r name equals value _; do
6+
if [[ $name = "$variable" && $equals = = ]]; then
7+
echo "${value//\"/}"
8+
return
9+
fi
10+
done < <(cat "$Cargo_toml")
11+
echo "Unable to locate $variable in $Cargo_toml" 1>&2
12+
}
13+
14+
if [[ -n $RUST_STABLE_VERSION ]]; then
15+
stable_version="$RUST_STABLE_VERSION"
16+
else
17+
# read rust version from rust-toolchain.toml file
18+
base="$(dirname "${BASH_SOURCE[0]}")"
19+
stable_version=$(readCargoVariable channel "$base/../rust-toolchain.toml")
20+
fi
21+
22+
if [[ -n $RUST_NIGHTLY_VERSION ]]; then
23+
nightly_version="$RUST_NIGHTLY_VERSION"
24+
else
25+
nightly_version=2023-11-16
26+
fi
27+
28+
echo "stable_version: $stable_version"
29+
echo "nightly_version: $nightly_version"
30+
31+
export rust_stable="$stable_version"
32+
export rust_nightly=nightly-"$nightly_version"
33+
34+
[[ -z $1 ]] || (
35+
36+
rustup_install() {
37+
declare toolchain=$1
38+
if ! cargo +"$toolchain" -V > /dev/null; then
39+
echo "$0: Missing toolchain? Installing...: $toolchain" >&2
40+
rustup install "$toolchain"
41+
cargo +"$toolchain" -V
42+
fi
43+
}
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+
)

rust-toolchain.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
[toolchain]
2-
channel = "1.70.0"
2+
channel = "1.73.0"

0 commit comments

Comments
 (0)