From e54dfa244259f00ce6597ffb9b7f339a5b92e172 Mon Sep 17 00:00:00 2001 From: rami3l Date: Tue, 28 Apr 2026 21:52:45 +0200 Subject: [PATCH 1/2] feat(config): add `Cfg` field to force-disable auto-installation --- src/config.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/config.rs b/src/config.rs index a4682ff6fd..7b0086e0fe 100644 --- a/src/config.rs +++ b/src/config.rs @@ -246,6 +246,12 @@ pub(crate) struct Cfg<'a> { pub quiet: bool, pub current_dir: PathBuf, pub process: &'a Process, + + /// If this flag is set to `true`, it can stop `rustup` from automatically installing the active + /// toolchain in certain undesired cases, such as under `rustup component` and `rustup target` + /// subcommands. This effect has higher precedence than the `RUSTUP_AUTO_INSTALL` environment + /// variable and the `rustup set auto-install` setting. + pub skip_auto_install: bool, } impl<'a> Cfg<'a> { @@ -317,6 +323,7 @@ impl<'a> Cfg<'a> { quiet, current_dir, process, + skip_auto_install: false, }; // Run some basic checks against the constructed configuration @@ -373,6 +380,10 @@ impl<'a> Cfg<'a> { } pub(crate) fn should_auto_install(&self) -> Result { + if self.skip_auto_install { + return Ok(false); + } + if let Ok(mode) = self.process.var("RUSTUP_AUTO_INSTALL") { Ok(mode != "0") } else { @@ -959,6 +970,7 @@ impl Debug for Cfg<'_> { dist_root_url, quiet, current_dir, + skip_auto_install, process: _, } = self; @@ -976,6 +988,7 @@ impl Debug for Cfg<'_> { .field("dist_root_url", dist_root_url) .field("quiet", quiet) .field("current_dir", current_dir) + .field("skip_auto_install", skip_auto_install) .finish() } } From 8ab1b84a304cf5a311a83440bb6293a1e93c4dd9 Mon Sep 17 00:00:00 2001 From: rami3l Date: Tue, 28 Apr 2026 22:01:08 +0200 Subject: [PATCH 2/2] fix(cli/rustup_mode)!: (wip) skip auto-installation in some `rustup` commands --- src/cli/rustup_mode.rs | 60 +++++++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 27 deletions(-) diff --git a/src/cli/rustup_mode.rs b/src/cli/rustup_mode.rs index 45e793cfd7..86d8d9d5ad 100644 --- a/src/cli/rustup_mode.rs +++ b/src/cli/rustup_mode.rs @@ -689,34 +689,40 @@ pub async fn main( toolchain, force_non_host, } => default_(cfg, toolchain, force_non_host).await, - RustupSubcmd::Target { subcmd } => match subcmd { - TargetSubcmd::List { - toolchain, - installed, - quiet, - } => handle_epipe(target_list(cfg, toolchain, installed, quiet).await), - TargetSubcmd::Add { target, toolchain } => target_add(cfg, target, toolchain).await, - TargetSubcmd::Remove { target, toolchain } => { - target_remove(cfg, target, toolchain).await + RustupSubcmd::Target { subcmd } => { + cfg.skip_auto_install = true; + match subcmd { + TargetSubcmd::List { + toolchain, + installed, + quiet, + } => handle_epipe(target_list(cfg, toolchain, installed, quiet).await), + TargetSubcmd::Add { target, toolchain } => target_add(cfg, target, toolchain).await, + TargetSubcmd::Remove { target, toolchain } => { + target_remove(cfg, target, toolchain).await + } } - }, - RustupSubcmd::Component { subcmd } => match subcmd { - ComponentSubcmd::List { - toolchain, - installed, - quiet, - } => handle_epipe(component_list(cfg, toolchain, installed, quiet).await), - ComponentSubcmd::Add { - component, - toolchain, - target, - } => component_add(cfg, component, toolchain, target).await, - ComponentSubcmd::Remove { - component, - toolchain, - target, - } => component_remove(cfg, component, toolchain, target).await, - }, + } + RustupSubcmd::Component { subcmd } => { + cfg.skip_auto_install = true; + match subcmd { + ComponentSubcmd::List { + toolchain, + installed, + quiet, + } => handle_epipe(component_list(cfg, toolchain, installed, quiet).await), + ComponentSubcmd::Add { + component, + toolchain, + target, + } => component_add(cfg, component, toolchain, target).await, + ComponentSubcmd::Remove { + component, + toolchain, + target, + } => component_remove(cfg, component, toolchain, target).await, + } + } RustupSubcmd::Override { subcmd } => match subcmd { OverrideSubcmd::List => handle_epipe(common::list_overrides(cfg)), OverrideSubcmd::Set { toolchain, path } => {