Skip to content

Commit

Permalink
scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
aniketfuryrocks committed Dec 4, 2023
1 parent 5dee0f0 commit df455af
Show file tree
Hide file tree
Showing 3 changed files with 138 additions and 1 deletion.
75 changes: 75 additions & 0 deletions ci/cargo-command.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#!/bin/bash

# Function to display help message
show_help() {
echo "Usage: $0 [stable|nightly] [command]"
echo
echo "This script is used to run a specified cargo command with either the stable or nightly Rust toolchain."
echo
echo "Arguments:"
echo " stable - Use the stable Rust toolchain."
echo " nightly - Use the nightly Rust toolchain."
echo " command - The cargo command to run (e.g., clippy, build)."
echo
echo "Examples:"
echo " $0 stable clippy - Run clippy with the stable Rust version."
echo " $0 nightly build - Build with the nightly Rust version."
}

# Function to run a specified cargo command with a specified toolchain
run_cargo_command() {
local toolchain=$1
local command=$2
echo "Running cargo $command with Rust $toolchain version..."
cargo +"$toolchain" "$command"
}

# Check if the first argument is -h or --help
if [[ $1 == "-h" || $1 == "--help" ]]; then
show_help
exit 0
fi

# Check if the second argument is not provided
if [[ -z $2 ]]; then
echo "Error: No command specified."
show_help
exit 1
fi

# Path to the rust-version.sh script
rust_version_script="./ci/rust-version.sh"

# Check if rust-version.sh exists and is executable
if [[ -f "$rust_version_script" && -x "$rust_version_script" ]]; then
# Source the rust-version.sh script
source "$rust_version_script"
else
echo "Error: rust-version.sh not found or not executable."
exit 1
fi


# Main execution logic based on passed arguments
case $1 in
stable)
# Check if Rust stable version is set
if [[ -z $rust_stable ]]; then
echo "Error: Rust stable version is not set."
exit 1
fi
run_cargo_command "$rust_stable" "$2"
;;
nightly)
# Check if Rust nightly version is set
if [[ -z $rust_nightly ]]; then
echo "Error: Rust nightly version is not set."
exit 1
fi
run_cargo_command "$rust_nightly" "$2"
;;
*)
echo "Usage: $0 [stable|nightly] [command]"
exit 1
;;
esac
62 changes: 62 additions & 0 deletions ci/rust-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
readCargoVariable() {
declare variable="$1"
declare Cargo_toml="$2"

while read -r name equals value _; do
if [[ $name = "$variable" && $equals = = ]]; then
echo "${value//\"/}"
return
fi
done < <(cat "$Cargo_toml")
echo "Unable to locate $variable in $Cargo_toml" 1>&2
}

if [[ -n $RUST_STABLE_VERSION ]]; then
stable_version="$RUST_STABLE_VERSION"
else
# read rust version from rust-toolchain.toml file
base="$(dirname "${BASH_SOURCE[0]}")"
stable_version=$(readCargoVariable channel "$base/../rust-toolchain.toml")
fi

if [[ -n $RUST_NIGHTLY_VERSION ]]; then
nightly_version="$RUST_NIGHTLY_VERSION"
else
nightly_version=2023-11-16
fi

echo "stable_version: $stable_version"
echo "nightly_version: $nightly_version"

export rust_stable="$stable_version"
export rust_nightly=nightly-"$nightly_version"

[[ -z $1 ]] || (

rustup_install() {
declare toolchain=$1
if ! cargo +"$toolchain" -V > /dev/null; then
echo "$0: Missing toolchain? Installing...: $toolchain" >&2
rustup install "$toolchain"
cargo +"$toolchain" -V
fi
}

set -e
cd "$(dirname "${BASH_SOURCE[0]}")"
case $1 in
stable)
rustup_install "$rust_stable"
;;
nightly)
rustup_install "$rust_nightly"
;;
all)
rustup_install "$rust_stable"
rustup_install "$rust_nightly"
;;
*)
echo "$0: Note: ignoring unknown argument: $1" >&2
;;
esac
)
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[toolchain]
channel = "1.70.0"
channel = "1.73.0"

0 comments on commit df455af

Please sign in to comment.