@@ -5,6 +5,8 @@ requested_toolchain="${1:-1.92.0}"
55fallback_toolchain=" ${2:- stable} "
66strict_mode_raw=" ${3:- ${ENSURE_CARGO_COMPONENT_STRICT:- false} } "
77strict_mode=" $( printf ' %s' " ${strict_mode_raw} " | tr ' [:upper:]' ' [:lower:]' ) "
8+ required_components_raw=" ${4:- ${ENSURE_RUST_COMPONENTS:- auto} } "
9+ job_name=" $( printf ' %s' " ${GITHUB_JOB:- } " | tr ' [:upper:]' ' [:lower:]' ) "
810
911is_truthy () {
1012 local value=" ${1:- } "
@@ -36,19 +38,25 @@ probe_rustdoc() {
3638
3739ensure_required_tooling () {
3840 local toolchain=" $1 "
41+ local required_components=" ${2:- } "
3942
40- # Lint and doctest jobs require both rustfmt and rustdoc to be available.
41- rustup component add --toolchain " ${toolchain} " rustfmt rust-docs || true
43+ if [ -z " ${required_components} " ]; then
44+ return 0
45+ fi
46+
47+ for component in ${required_components} ; do
48+ rustup component add --toolchain " ${toolchain} " " ${component} " || true
49+ done
4250
43- if ! probe_rustfmt " ${toolchain} " ; then
51+ if [[ " ${required_components} " == * " rustfmt " * ]] && ! probe_rustfmt " ${toolchain} " ; then
4452 echo " ::error::rustfmt is unavailable for toolchain ${toolchain} ."
4553 rustup component add --toolchain " ${toolchain} " rustfmt || true
4654 if ! probe_rustfmt " ${toolchain} " ; then
4755 return 1
4856 fi
4957 fi
5058
51- if ! probe_rustdoc " ${toolchain} " ; then
59+ if [[ " ${required_components} " == * " rust-docs " * ]] && ! probe_rustdoc " ${toolchain} " ; then
5260 echo " ::error::rustdoc is unavailable for toolchain ${toolchain} ."
5361 rustup component add --toolchain " ${toolchain} " rust-docs || true
5462 if ! probe_rustdoc " ${toolchain} " ; then
@@ -57,6 +65,15 @@ ensure_required_tooling() {
5765 fi
5866}
5967
68+ default_required_components () {
69+ local normalized_job_name=" ${1:- } "
70+ case " ${normalized_job_name} " in
71+ * lint* ) echo " rustfmt" ;;
72+ * test* ) echo " rust-docs" ;;
73+ * ) echo " " ;;
74+ esac
75+ }
76+
6077export_toolchain_for_next_steps () {
6178 local toolchain=" $1 "
6279 if [ -z " ${GITHUB_ENV:- } " ]; then
@@ -129,7 +146,16 @@ if is_truthy "${strict_mode}" && [ "${selected_toolchain}" != "${requested_toolc
129146 exit 1
130147fi
131148
132- if ! ensure_required_tooling " ${selected_toolchain} " ; then
149+ required_components=" ${required_components_raw} "
150+ if [ " ${required_components} " = " auto" ]; then
151+ required_components=" $( default_required_components " ${job_name} " ) "
152+ fi
153+
154+ if [ -n " ${required_components} " ]; then
155+ echo " Ensuring Rust components for job '${job_name:- unknown} ': ${required_components} "
156+ fi
157+
158+ if ! ensure_required_tooling " ${selected_toolchain} " " ${required_components} " ; then
133159 echo " Required Rust tooling unavailable for ${selected_toolchain} " >&2
134160 rustup toolchain list || true
135161 exit 1
0 commit comments