Skip to content

Commit 2d5fe7f

Browse files
committed
feat(install): flag to DistOptions and try_update_from_dist_
1 parent 323bf9f commit 2d5fe7f

File tree

3 files changed

+60
-5
lines changed

3 files changed

+60
-5
lines changed

src/cli/rustup_mode.rs

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

src/config.rs

Lines changed: 41 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)?;
@@ -777,6 +785,7 @@ impl<'a> Cfg<'a> {
777785
profile: Option<Profile>,
778786
force_non_host: bool,
779787
verbose: bool,
788+
skip_std: bool,
780789
) -> Result<(UpdateStatus, Toolchain<'_>)> {
781790
common::check_non_host_toolchain(
782791
toolchain.to_string(),
@@ -800,6 +809,7 @@ impl<'a> Cfg<'a> {
800809
false,
801810
self,
802811
)?;
812+
options.skip_std = skip_std;
803813

804814
let (status, toolchain) = match DistributableToolchain::new(self, toolchain.clone()) {
805815
Err(RustupError::ToolchainNotInstalled { .. }) => {
@@ -1030,6 +1040,7 @@ mod tests {
10301040
components: None,
10311041
targets: None,
10321042
profile: None,
1043+
skip_std: None,
10331044
}
10341045
}
10351046
);
@@ -1057,6 +1068,7 @@ profile = "default"
10571068
"thumbv2-none-eabi".into()
10581069
]),
10591070
profile: Some("default".into()),
1071+
skip_std: None,
10601072
}
10611073
}
10621074
);
@@ -1078,6 +1090,7 @@ channel = "nightly-2020-07-10"
10781090
components: None,
10791091
targets: None,
10801092
profile: None,
1093+
skip_std: None,
10811094
}
10821095
}
10831096
);
@@ -1099,6 +1112,7 @@ path = "foobar"
10991112
components: None,
11001113
targets: None,
11011114
profile: None,
1115+
skip_std: None,
11021116
}
11031117
}
11041118
);
@@ -1121,6 +1135,7 @@ components = []
11211135
components: Some(vec![]),
11221136
targets: None,
11231137
profile: None,
1138+
skip_std: None,
11241139
}
11251140
}
11261141
);
@@ -1143,6 +1158,7 @@ targets = []
11431158
components: None,
11441159
targets: Some(vec![]),
11451160
profile: None,
1161+
skip_std: None,
11461162
}
11471163
}
11481164
);
@@ -1164,6 +1180,7 @@ components = [ "rustfmt" ]
11641180
components: Some(vec!["rustfmt".into()]),
11651181
targets: None,
11661182
profile: None,
1183+
skip_std: None,
11671184
}
11681185
}
11691186
);
@@ -1216,4 +1233,27 @@ channel = nightly
12161233
Ok(OverrideFileConfigError::Parsing)
12171234
));
12181235
}
1236+
1237+
#[test]
1238+
fn parse_toml_toolchain_file_with_skip_std() {
1239+
let contents = r#"[toolchain]
1240+
channel = "nightly-2020-07-10"
1241+
skip_std = true
1242+
"#;
1243+
1244+
let result = Cfg::parse_override_file(contents, ParseMode::Both);
1245+
assert_eq!(
1246+
result.unwrap(),
1247+
OverrideFile {
1248+
toolchain: ToolchainSection {
1249+
channel: Some("nightly-2020-07-10".into()),
1250+
path: None,
1251+
components: None,
1252+
targets: None,
1253+
profile: None,
1254+
skip_std: Some(true),
1255+
}
1256+
}
1257+
);
1258+
}
12191259
}

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

@@ -1034,6 +1037,7 @@ pub(crate) async fn update_from_dist(
10341037
opts.targets,
10351038
&mut fetched,
10361039
opts.cfg,
1040+
opts.skip_std,
10371041
)
10381042
.await;
10391043

@@ -1131,6 +1135,7 @@ async fn try_update_from_dist_(
11311135
targets: &[&str],
11321136
fetched: &mut String,
11331137
cfg: &Cfg<'_>,
1138+
skip_std: bool,
11341139
) -> Result<Option<String>> {
11351140
let toolchain_str = toolchain.to_string();
11361141
let manifestation = Manifestation::open(prefix.clone(), toolchain.target.clone())?;
@@ -1165,6 +1170,10 @@ async fn try_update_from_dist_(
11651170

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

1173+
if skip_std {
1174+
all_components.retain(|c| !c.short_name_in_manifest().starts_with("rust-std"));
1175+
}
1176+
11681177
let rust_package = m.get_package("rust")?;
11691178
let rust_target_package = rust_package.get_target(Some(&toolchain.target.clone()))?;
11701179

@@ -1188,9 +1197,15 @@ async fn try_update_from_dist_(
11881197
all_components.insert(component);
11891198
}
11901199

1191-
for &target in targets {
1192-
let triple = TargetTriple::new(target);
1193-
all_components.insert(Component::new("rust-std".to_string(), Some(triple), false));
1200+
if !skip_std {
1201+
for &target in targets {
1202+
let triple = TargetTriple::new(target);
1203+
all_components.insert(Component::new(
1204+
"rust-std".to_string(),
1205+
Some(triple),
1206+
false,
1207+
));
1208+
}
11941209
}
11951210

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

0 commit comments

Comments
 (0)