aboutsummaryrefslogtreecommitdiff
path: root/ci/install-component.sh
blob: dbba7b18c8d979becb3c450882c6a6764416f4e6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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

package="${1:?}"
target="${2:-x86_64-unknown-linux-gnu}"

date=$(curl -sSf https://rust-lang.github.io/rustup-components-history/"${target}"/"${package}")

# shellcheck disable=1090
"$(cd "$(dirname "${0}")" && pwd)"/install-rust.sh nightly-"${date}"

rustup component add "${package}"

case "${package}" in
    rustfmt) "${package}" -V ;;
    *) cargo "${package}" -V ;;
esac