Skip to content

Commit ce4e673

Browse files
authored
[cargo-zerocopy] Auto-install env var toggle (#2840)
When the environment variable `CARGO_ZEROCOPY_AUTO_INSTALL_TOOLCHAIN` is set, auto-install toolchains without prompting the user. gherrit-pr-id: Ic5070e48a9b829ca68b8356d44b42bd97543ead9
1 parent 33f6cbd commit ce4e673

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

tools/cargo-zerocopy/src/main.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,12 @@ fn is_toolchain_installed(versions: &Versions, name: &str) -> Result<bool, Error
140140

141141
fn install_toolchain_or_exit(versions: &Versions, name: &str) -> Result<(), Error> {
142142
eprintln!("[cargo-zerocopy] missing either toolchain '{name}' or component 'rust-src'");
143-
if env::vars().any(|v| v.0 == "GITHUB_RUN_ID") {
144-
eprint!("[cargo-zerocopy] detected GitHub Actions environment; auto-installing without waiting for confirmation");
143+
if env::var("GITHUB_RUN_ID").is_ok() {
144+
eprintln!("[cargo-zerocopy] detected GitHub Actions environment; auto-installing without waiting for confirmation");
145+
} else if env::var("CARGO_ZEROCOPY_AUTO_INSTALL_TOOLCHAIN").is_ok() {
146+
eprintln!("[cargo-zerocopy] detected CARGO_ZEROCOPY_AUTO_INSTALL_TOOLCHAIN environment variable; auto-installing without waiting for confirmation");
145147
} else {
148+
eprintln!("[cargo-zerocopy] set CARGO_ZEROCOPY_AUTO_INSTALL_TOOLCHAIN=1 to always install toolchains without prompting");
146149
loop {
147150
eprint!("[cargo-zerocopy] would you like to install toolchain '{name}' and component 'rust-src' via 'rustup' (y/n)? ");
148151
let mut input = [0];

0 commit comments

Comments
 (0)