Skip to content

Commit 70d2e69

Browse files
committed
feat(install): flag to DistOptions and try_update_from_dist_
1 parent 7435d63 commit 70d2e69

File tree

3 files changed

+61
-5
lines changed

3 files changed

+61
-5
lines changed

src/cli/rustup_mode.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,7 @@ async fn default_(
780780
MaybeResolvableToolchainName::Some(ResolvableToolchainName::Official(toolchain)) => {
781781
let desc = toolchain.resolve(&cfg.get_default_host_triple()?)?;
782782
let status = cfg
783-
.ensure_installed(&desc, vec![], vec![], None, force_non_host, true)
783+
.ensure_installed(&desc, vec![], vec![], None, force_non_host, true, false)
784784
.await?
785785
.0;
786786

src/config.rs

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ struct ToolchainSection {
5656
components: Option<Vec<String>>,
5757
targets: Option<Vec<String>>,
5858
profile: Option<String>,
59+
skip_std: Option<bool>,
5960
}
6061

6162
impl ToolchainSection {
@@ -64,6 +65,7 @@ impl ToolchainSection {
6465
&& self.components.is_none()
6566
&& self.targets.is_none()
6667
&& self.path.is_none()
68+
&& self.skip_std.is_none()
6769
}
6870
}
6971

@@ -137,6 +139,7 @@ enum OverrideCfg {
137139
components: Vec<String>,
138140
targets: Vec<String>,
139141
profile: Option<Profile>,
142+
skip_std: bool,
140143
},
141144
}
142145

@@ -180,6 +183,7 @@ impl OverrideCfg {
180183
ToolchainName::Official(desc) => {
181184
let components = file.toolchain.components.unwrap_or_default();
182185
let targets = file.toolchain.targets.unwrap_or_default();
186+
183187
Self::Official {
184188
toolchain: desc,
185189
components,
@@ -190,6 +194,7 @@ impl OverrideCfg {
190194
.as_deref()
191195
.map(Profile::from_str)
192196
.transpose()?,
197+
skip_std: file.toolchain.skip_std.unwrap_or(false),
193198
}
194199
}
195200
ToolchainName::Custom(name) => Self::Custom(name),
@@ -213,6 +218,7 @@ impl From<ToolchainName> for OverrideCfg {
213218
components: vec![],
214219
targets: vec![],
215220
profile: None,
221+
skip_std: false,
216222
},
217223
ToolchainName::Custom(name) => Self::Custom(name),
218224
}
@@ -737,6 +743,7 @@ impl<'a> Cfg<'a> {
737743
components,
738744
targets,
739745
profile,
746+
skip_std,
740747
} = override_config
741748
{
742749
self.ensure_installed(
@@ -746,6 +753,7 @@ impl<'a> Cfg<'a> {
746753
profile,
747754
force_non_host,
748755
verbose,
756+
skip_std,
749757
)
750758
.await?;
751759
} else {
@@ -755,7 +763,7 @@ impl<'a> Cfg<'a> {
755763
} else if let Some(toolchain) = self.get_default()? {
756764
let source = ActiveSource::Default;
757765
if let ToolchainName::Official(desc) = &toolchain {
758-
self.ensure_installed(desc, vec![], vec![], None, force_non_host, verbose)
766+
self.ensure_installed(desc, vec![], vec![], None, force_non_host, verbose, false)
759767
.await?;
760768
} else {
761769
Toolchain::with_source(self, toolchain.clone().into(), &source)?;
@@ -768,6 +776,7 @@ impl<'a> Cfg<'a> {
768776

769777
// Returns a Toolchain matching the given ToolchainDesc, installing it and
770778
// the given components and targets if they aren't already installed.
779+
#[allow(clippy::too_many_arguments)]
771780
#[tracing::instrument(level = "trace", err(level = "trace"), skip_all)]
772781
pub(crate) async fn ensure_installed(
773782
&self,
@@ -777,6 +786,7 @@ impl<'a> Cfg<'a> {
777786
profile: Option<Profile>,
778787
force_non_host: bool,
779788
verbose: bool,
789+
skip_std: bool,
780790
) -> Result<(UpdateStatus, Toolchain<'_>)> {
781791
common::check_non_host_toolchain(
782792
toolchain.to_string(),
@@ -800,6 +810,7 @@ impl<'a> Cfg<'a> {
800810
false,
801811
self,
802812
)?;
813+
options.skip_std = skip_std;
803814

804815
let (status, toolchain) = match DistributableToolchain::new(self, toolchain.clone()) {
805816
Err(RustupError::ToolchainNotInstalled { .. }) => {
@@ -1030,6 +1041,7 @@ mod tests {
10301041
components: None,
10311042
targets: None,
10321043
profile: None,
1044+
skip_std: None,
10331045
}
10341046
}
10351047
);
@@ -1057,6 +1069,7 @@ profile = "default"
10571069
"thumbv2-none-eabi".into()
10581070
]),
10591071
profile: Some("default".into()),
1072+
skip_std: None,
10601073
}
10611074
}
10621075
);
@@ -1078,6 +1091,7 @@ channel = "nightly-2020-07-10"
10781091
components: None,
10791092
targets: None,
10801093
profile: None,
1094+
skip_std: None,
10811095
}
10821096
}
10831097
);
@@ -1099,6 +1113,7 @@ path = "foobar"
10991113
components: None,
11001114
targets: None,
11011115
profile: None,
1116+
skip_std: None,
11021117
}
11031118
}
11041119
);
@@ -1121,6 +1136,7 @@ components = []
11211136
components: Some(vec![]),
11221137
targets: None,
11231138
profile: None,
1139+
skip_std: None,
11241140
}
11251141
}
11261142
);
@@ -1143,6 +1159,7 @@ targets = []
11431159
components: None,
11441160
targets: Some(vec![]),
11451161
profile: None,
1162+
skip_std: None,
11461163
}
11471164
}
11481165
);
@@ -1164,6 +1181,7 @@ components = [ "rustfmt" ]
11641181
components: Some(vec!["rustfmt".into()]),
11651182
targets: None,
11661183
profile: None,
1184+
skip_std: None,
11671185
}
11681186
}
11691187
);
@@ -1216,4 +1234,27 @@ channel = nightly
12161234
Ok(OverrideFileConfigError::Parsing)
12171235
));
12181236
}
1237+
1238+
#[test]
1239+
fn parse_toml_toolchain_file_with_skip_std() {
1240+
let contents = r#"[toolchain]
1241+
channel = "nightly-2020-07-10"
1242+
skip_std = true
1243+
"#;
1244+
1245+
let result = Cfg::parse_override_file(contents, ParseMode::Both);
1246+
assert_eq!(
1247+
result.unwrap(),
1248+
OverrideFile {
1249+
toolchain: ToolchainSection {
1250+
channel: Some("nightly-2020-07-10".into()),
1251+
path: None,
1252+
components: None,
1253+
targets: None,
1254+
profile: None,
1255+
skip_std: Some(true),
1256+
}
1257+
}
1258+
);
1259+
}
12191260
}

src/dist/mod.rs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -900,6 +900,8 @@ pub(crate) struct DistOptions<'cfg, 'a> {
900900
components: &'a [&'a str],
901901
/// Extra targets to install from dist
902902
targets: &'a [&'a str],
903+
/// Flag to skip installation of rust-std
904+
pub(super) skip_std: bool,
903905
}
904906

905907
impl<'cfg, 'a> DistOptions<'cfg, 'a> {
@@ -923,6 +925,7 @@ impl<'cfg, 'a> DistOptions<'cfg, 'a> {
923925
old_date_version: None,
924926
components,
925927
targets,
928+
skip_std: false,
926929
})
927930
}
928931

@@ -1030,6 +1033,7 @@ impl<'cfg, 'a> DistOptions<'cfg, 'a> {
10301033
self.targets,
10311034
&mut fetched,
10321035
self.cfg,
1036+
self.skip_std,
10331037
)
10341038
.await;
10351039

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

11631168
let mut all_components: HashSet<Component> = profile_components.into_iter().collect();
11641169

1170+
if skip_std {
1171+
all_components.retain(|c| !c.short_name_in_manifest().starts_with("rust-std"));
1172+
}
1173+
11651174
let rust_package = m.get_package("rust")?;
11661175
let rust_target_package = rust_package.get_target(Some(&toolchain.target.clone()))?;
11671176

@@ -1185,9 +1194,15 @@ async fn try_update_from_dist_(
11851194
all_components.insert(component);
11861195
}
11871196

1188-
for &target in targets {
1189-
let triple = TargetTriple::new(target);
1190-
all_components.insert(Component::new("rust-std".to_string(), Some(triple), false));
1197+
if !skip_std {
1198+
for &target in targets {
1199+
let triple = TargetTriple::new(target);
1200+
all_components.insert(Component::new(
1201+
"rust-std".to_string(),
1202+
Some(triple),
1203+
false,
1204+
));
1205+
}
11911206
}
11921207

11931208
let mut explicit_add_components: Vec<_> = all_components.into_iter().collect();

0 commit comments

Comments
 (0)