2024-05-16 18:52:20 +01:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
2024-09-16 16:18:49 +01:00
|
|
|
echo "INPUT_ARGS: ${INPUT_ARGS}"
|
|
|
|
|
|
|
|
# split input into an array
|
|
|
|
read -ra ARGS <<<"${INPUT_ARGS}"
|
|
|
|
|
|
|
|
# default toolchain
|
|
|
|
TOOLCHAIN="stable"
|
|
|
|
echo "Default toolchain: ${TOOLCHAIN}"
|
|
|
|
|
|
|
|
# if first parameter is 'nightly'...
|
|
|
|
if test "${ARGS[0]}" == "nightly"; then
|
|
|
|
TOOLCHAIN="nightly"
|
|
|
|
ARGS=("${ARGS[@]:1}")
|
|
|
|
fi
|
|
|
|
if test "${ARGS[0]}" == "stable"; then
|
|
|
|
TOOLCHAIN="stable" # redundant as this is the default
|
|
|
|
ARGS=("${ARGS[@]:1}")
|
|
|
|
fi
|
|
|
|
if [[ "${ARGS[0]}" == v1* ]]; then
|
|
|
|
TOOLCHAIN="${ARGS[0]:1}"
|
|
|
|
ARGS=("${ARGS[@]:1}")
|
|
|
|
fi
|
|
|
|
echo "Selected toolchain: ${TOOLCHAIN}"
|
|
|
|
|
2024-09-17 10:58:08 +01:00
|
|
|
echo ">>> Update toolchain"
|
2024-09-16 16:18:49 +01:00
|
|
|
rustup update "${TOOLCHAIN}"
|
2024-09-17 10:58:08 +01:00
|
|
|
echo ">>> Install rustfmt and clippy"
|
2024-09-17 10:54:04 +01:00
|
|
|
rustup component add --toolchain "${TOOLCHAIN}" rustfmt clippy
|
2024-09-16 16:18:49 +01:00
|
|
|
|
|
|
|
if test "${ARGS[0]}" == "cargo";then
|
|
|
|
PRE_COMMAND="cargo +${TOOLCHAIN} "
|
|
|
|
else
|
|
|
|
PRE_COMMAND="${ARGS[0]}"
|
|
|
|
fi
|
|
|
|
ARGS=("${ARGS[@]:1}")
|
|
|
|
|
|
|
|
# ensure toolchain is up-to-date
|
|
|
|
# recombine remaining arguments
|
|
|
|
COMMAND=$(
|
|
|
|
IFS=" "
|
|
|
|
echo "${ARGS[*]}"
|
|
|
|
)
|
|
|
|
|
|
|
|
# execute command
|
2024-09-17 10:58:08 +01:00
|
|
|
echo ">>> ${PRE_COMMAND} ${COMMAND}"
|
2024-09-16 16:18:49 +01:00
|
|
|
${PRE_COMMAND} ${COMMAND}
|