diff --git a/src/cli/rustup_mode.rs b/src/cli/rustup_mode.rs index 48e865eb78..14f1f31573 100644 --- a/src/cli/rustup_mode.rs +++ b/src/cli/rustup_mode.rs @@ -775,7 +775,7 @@ async fn default_( MaybeResolvableToolchainName::Some(ResolvableToolchainName::Official(toolchain)) => { let desc = toolchain.resolve(&cfg.get_default_host_triple()?)?; let status = cfg - .ensure_installed(&desc, vec![], vec![], None, force_non_host, true) + .ensure_installed(&desc, vec![], vec![], None, force_non_host, true, false) .await? .0; diff --git a/src/config.rs b/src/config.rs index bbba13a075..8f685bd25c 100644 --- a/src/config.rs +++ b/src/config.rs @@ -56,6 +56,7 @@ struct ToolchainSection { components: Option>, targets: Option>, profile: Option, + skip_std: Option, } impl ToolchainSection { @@ -64,6 +65,7 @@ impl ToolchainSection { && self.components.is_none() && self.targets.is_none() && self.path.is_none() + && self.skip_std.is_none() } } @@ -137,6 +139,7 @@ enum OverrideCfg { components: Vec, targets: Vec, profile: Option, + skip_std: bool, }, } @@ -180,6 +183,7 @@ impl OverrideCfg { ToolchainName::Official(desc) => { let components = file.toolchain.components.unwrap_or_default(); let targets = file.toolchain.targets.unwrap_or_default(); + Self::Official { toolchain: desc, components, @@ -190,6 +194,7 @@ impl OverrideCfg { .as_deref() .map(Profile::from_str) .transpose()?, + skip_std: file.toolchain.skip_std.unwrap_or(false), } } ToolchainName::Custom(name) => Self::Custom(name), @@ -213,6 +218,7 @@ impl From for OverrideCfg { components: vec![], targets: vec![], profile: None, + skip_std: false, }, ToolchainName::Custom(name) => Self::Custom(name), } @@ -737,6 +743,7 @@ impl<'a> Cfg<'a> { components, targets, profile, + skip_std, } = override_config { self.ensure_installed( @@ -746,6 +753,7 @@ impl<'a> Cfg<'a> { profile, force_non_host, verbose, + skip_std, ) .await?; } else { @@ -755,7 +763,7 @@ impl<'a> Cfg<'a> { } else if let Some(toolchain) = self.get_default()? { let source = ActiveSource::Default; if let ToolchainName::Official(desc) = &toolchain { - self.ensure_installed(desc, vec![], vec![], None, force_non_host, verbose) + self.ensure_installed(desc, vec![], vec![], None, force_non_host, verbose, false) .await?; } else { Toolchain::with_source(self, toolchain.clone().into(), &source)?; @@ -777,6 +785,7 @@ impl<'a> Cfg<'a> { profile: Option, force_non_host: bool, verbose: bool, + skip_std: bool, ) -> Result<(UpdateStatus, Toolchain<'_>)> { common::check_non_host_toolchain( toolchain.to_string(), @@ -800,6 +809,7 @@ impl<'a> Cfg<'a> { false, self, )?; + options.skip_std = skip_std; let (status, toolchain) = match DistributableToolchain::new(self, toolchain.clone()) { Err(RustupError::ToolchainNotInstalled { .. }) => { @@ -1030,6 +1040,7 @@ mod tests { components: None, targets: None, profile: None, + skip_std: None, } } ); @@ -1057,6 +1068,7 @@ profile = "default" "thumbv2-none-eabi".into() ]), profile: Some("default".into()), + skip_std: None, } } ); @@ -1078,6 +1090,7 @@ channel = "nightly-2020-07-10" components: None, targets: None, profile: None, + skip_std: None, } } ); @@ -1099,6 +1112,7 @@ path = "foobar" components: None, targets: None, profile: None, + skip_std: None, } } ); @@ -1121,6 +1135,7 @@ components = [] components: Some(vec![]), targets: None, profile: None, + skip_std: None, } } ); @@ -1143,6 +1158,7 @@ targets = [] components: None, targets: Some(vec![]), profile: None, + skip_std: None, } } ); @@ -1164,6 +1180,7 @@ components = [ "rustfmt" ] components: Some(vec!["rustfmt".into()]), targets: None, profile: None, + skip_std: None, } } ); @@ -1216,4 +1233,27 @@ channel = nightly Ok(OverrideFileConfigError::Parsing) )); } + + #[test] + fn parse_toml_toolchain_file_with_skip_std() { + let contents = r#"[toolchain] +channel = "nightly-2020-07-10" +skip_std = true +"#; + + let result = Cfg::parse_override_file(contents, ParseMode::Both); + assert_eq!( + result.unwrap(), + OverrideFile { + toolchain: ToolchainSection { + channel: Some("nightly-2020-07-10".into()), + path: None, + components: None, + targets: None, + profile: None, + skip_std: Some(true), + } + } + ); + } } diff --git a/src/dist/mod.rs b/src/dist/mod.rs index 7691447f62..0612367251 100644 --- a/src/dist/mod.rs +++ b/src/dist/mod.rs @@ -900,6 +900,8 @@ pub(crate) struct DistOptions<'cfg, 'a> { components: &'a [&'a str], /// Extra targets to install from dist targets: &'a [&'a str], + /// Flag to skip installation of rust-std + pub(super) skip_std: bool, } impl<'cfg, 'a> DistOptions<'cfg, 'a> { @@ -923,6 +925,7 @@ impl<'cfg, 'a> DistOptions<'cfg, 'a> { old_date_version: None, components, targets, + skip_std: false, }) } @@ -1034,6 +1037,7 @@ pub(crate) async fn update_from_dist( opts.targets, &mut fetched, opts.cfg, + opts.skip_std, ) .await; @@ -1131,6 +1135,7 @@ async fn try_update_from_dist_( targets: &[&str], fetched: &mut String, cfg: &Cfg<'_>, + skip_std: bool, ) -> Result> { let toolchain_str = toolchain.to_string(); let manifestation = Manifestation::open(prefix.clone(), toolchain.target.clone())?; @@ -1165,6 +1170,10 @@ async fn try_update_from_dist_( let mut all_components: HashSet = profile_components.into_iter().collect(); + if skip_std { + all_components.retain(|c| !c.short_name_in_manifest().starts_with("rust-std")); + } + let rust_package = m.get_package("rust")?; let rust_target_package = rust_package.get_target(Some(&toolchain.target.clone()))?; @@ -1188,9 +1197,15 @@ async fn try_update_from_dist_( all_components.insert(component); } - for &target in targets { - let triple = TargetTriple::new(target); - all_components.insert(Component::new("rust-std".to_string(), Some(triple), false)); + if !skip_std { + for &target in targets { + let triple = TargetTriple::new(target); + all_components.insert(Component::new( + "rust-std".to_string(), + Some(triple), + false, + )); + } } let mut explicit_add_components: Vec<_> = all_components.into_iter().collect();