Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/cli/rustup_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,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;

Expand Down
43 changes: 42 additions & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ struct ToolchainSection {
components: Option<Vec<String>>,
targets: Option<Vec<String>>,
profile: Option<String>,
skip_std: Option<bool>,
}

impl ToolchainSection {
Expand All @@ -64,6 +65,7 @@ impl ToolchainSection {
&& self.components.is_none()
&& self.targets.is_none()
&& self.path.is_none()
&& self.skip_std.is_none()
}
}

Expand Down Expand Up @@ -137,6 +139,7 @@ enum OverrideCfg {
components: Vec<String>,
targets: Vec<String>,
profile: Option<Profile>,
skip_std: bool,
},
}

Expand Down Expand Up @@ -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,
Expand All @@ -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),
Expand All @@ -213,6 +218,7 @@ impl From<ToolchainName> for OverrideCfg {
components: vec![],
targets: vec![],
profile: None,
skip_std: false,
},
ToolchainName::Custom(name) => Self::Custom(name),
}
Expand Down Expand Up @@ -737,6 +743,7 @@ impl<'a> Cfg<'a> {
components,
targets,
profile,
skip_std,
} = override_config
{
self.ensure_installed(
Expand All @@ -746,6 +753,7 @@ impl<'a> Cfg<'a> {
profile,
force_non_host,
verbose,
skip_std,
)
.await?;
} else {
Expand All @@ -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)?;
Expand All @@ -768,6 +776,7 @@ impl<'a> Cfg<'a> {

// Returns a Toolchain matching the given ToolchainDesc, installing it and
// the given components and targets if they aren't already installed.
#[allow(clippy::too_many_arguments)]
#[tracing::instrument(level = "trace", err(level = "trace"), skip_all)]
pub(crate) async fn ensure_installed(
&self,
Expand All @@ -777,6 +786,7 @@ impl<'a> Cfg<'a> {
profile: Option<Profile>,
force_non_host: bool,
verbose: bool,
skip_std: bool,
) -> Result<(UpdateStatus, Toolchain<'_>)> {
common::check_non_host_toolchain(
toolchain.to_string(),
Expand All @@ -800,6 +810,7 @@ impl<'a> Cfg<'a> {
false,
self,
)?;
options.skip_std = skip_std;

let (status, toolchain) = match DistributableToolchain::new(self, toolchain.clone()) {
Err(RustupError::ToolchainNotInstalled { .. }) => {
Expand Down Expand Up @@ -1030,6 +1041,7 @@ mod tests {
components: None,
targets: None,
profile: None,
skip_std: None,
}
}
);
Expand Down Expand Up @@ -1057,6 +1069,7 @@ profile = "default"
"thumbv2-none-eabi".into()
]),
profile: Some("default".into()),
skip_std: None,
}
}
);
Expand All @@ -1078,6 +1091,7 @@ channel = "nightly-2020-07-10"
components: None,
targets: None,
profile: None,
skip_std: None,
}
}
);
Expand All @@ -1099,6 +1113,7 @@ path = "foobar"
components: None,
targets: None,
profile: None,
skip_std: None,
}
}
);
Expand All @@ -1121,6 +1136,7 @@ components = []
components: Some(vec![]),
targets: None,
profile: None,
skip_std: None,
}
}
);
Expand All @@ -1143,6 +1159,7 @@ targets = []
components: None,
targets: Some(vec![]),
profile: None,
skip_std: None,
}
}
);
Expand All @@ -1164,6 +1181,7 @@ components = [ "rustfmt" ]
components: Some(vec!["rustfmt".into()]),
targets: None,
profile: None,
skip_std: None,
}
}
);
Expand Down Expand Up @@ -1216,4 +1234,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),
}
}
);
}
}
21 changes: 18 additions & 3 deletions src/dist/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand All @@ -923,6 +925,7 @@ impl<'cfg, 'a> DistOptions<'cfg, 'a> {
old_date_version: None,
components,
targets,
skip_std: false,
})
}

Expand Down Expand Up @@ -1030,6 +1033,7 @@ impl<'cfg, 'a> DistOptions<'cfg, 'a> {
self.targets,
&mut fetched,
self.cfg,
self.skip_std,
)
.await;

Expand Down Expand Up @@ -1128,6 +1132,7 @@ async fn try_update_from_dist_(
targets: &[&str],
fetched: &mut String,
cfg: &Cfg<'_>,
skip_std: bool,
) -> Result<Option<String>> {
let toolchain_str = toolchain.to_string();
let manifestation = Manifestation::open(prefix.clone(), toolchain.target.clone())?;
Expand Down Expand Up @@ -1162,6 +1167,10 @@ async fn try_update_from_dist_(

let mut all_components: HashSet<Component> = 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()))?;

Expand All @@ -1185,9 +1194,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();
Expand Down
Loading