aboutsummaryrefslogtreecommitdiff
path: root/ci/install-component.sh
diff options
context:
space:
mode:
Diffstat (limited to 'ci/install-component.sh')
-rwxr-xr-x[-rw-r--r--]ci/install-component.sh31
1 files changed, 18 insertions, 13 deletions
diff --git a/ci/install-component.sh b/ci/install-component.sh
index 9aaa5ce..dbba7b1 100644..100755
--- a/ci/install-component.sh
+++ b/ci/install-component.sh
@@ -1,22 +1,27 @@
#!/bin/bash
+# Install nightly Rust with a given component.
+#
+# If the component is unavailable on the latest nightly,
+# use the latest toolchain with the component available.
+#
+# When using stable Rust, this script is basically unnecessary as almost components available.
+#
+# Refs: https://github.com/rust-lang/rustup-components-history#the-web-part
+
set -euo pipefail
-component="${1}"
+package="${1:?}"
+target="${2:-x86_64-unknown-linux-gnu}"
-if ! rustup component add "${component}" 2>/dev/null; then
- # If the component is unavailable on the latest nightly,
- # use the latest toolchain with the component available.
- # Refs: https://github.com/rust-lang/rustup-components-history#the-web-part
- target=$(curl -sSf "https://rust-lang.github.io/rustup-components-history/x86_64-unknown-linux-gnu/${component}")
- echo "'${component}' is unavailable on the default toolchain, use the toolchain 'nightly-${target}' instead"
+date=$(curl -sSf https://rust-lang.github.io/rustup-components-history/"${target}"/"${package}")
- . ci/install-rust.sh "nightly-${target}"
+# shellcheck disable=1090
+"$(cd "$(dirname "${0}")" && pwd)"/install-rust.sh nightly-"${date}"
- rustup component add "${component}"
-fi
+rustup component add "${package}"
-case "${component}" in
- rustfmt) "${component}" -V ;;
- *) cargo "${component}" -V ;;
+case "${package}" in
+ rustfmt) "${package}" -V ;;
+ *) cargo "${package}" -V ;;
esac