Skip to content

Commit 0eb6b73

Browse files
committed
fix(install): force-skip behavior for rust-std - #4442
1 parent 591ed27 commit 0eb6b73

File tree

7 files changed

+121
-63
lines changed

7 files changed

+121
-63
lines changed

src/cli/rustup_mode.rs

Lines changed: 13 additions & 5 deletions
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, false, force_non_host, true)
779779
.await?
780780
.0;
781781

@@ -977,6 +977,7 @@ async fn update(
977977
&targets,
978978
profile,
979979
force,
980+
false,
980981
)
981982
.await?
982983
.0
@@ -1519,10 +1520,17 @@ async fn override_add(
15191520
Err(e @ RustupError::ToolchainNotInstalled { .. }) => match &toolchain_name {
15201521
ToolchainName::Custom(_) => Err(e)?,
15211522
ToolchainName::Official(desc) => {
1522-
let status =
1523-
DistributableToolchain::install(cfg, desc, &[], &[], cfg.get_profile()?, false)
1524-
.await?
1525-
.0;
1523+
let status = DistributableToolchain::install(
1524+
cfg,
1525+
desc,
1526+
&[],
1527+
&[],
1528+
cfg.get_profile()?,
1529+
false,
1530+
false,
1531+
)
1532+
.await?
1533+
.0;
15261534
writeln!(cfg.process.stdout().lock())?;
15271535
common::show_channel_update(
15281536
cfg,

src/cli/self_update.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,6 +1015,7 @@ async fn maybe_install_rust(opts: InstallOpts<'_>, cfg: &mut Cfg<'_>) -> Result<
10151015
targets,
10161016
cfg.get_profile()?,
10171017
true,
1018+
false,
10181019
)
10191020
.await?
10201021
.0

src/config.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ struct ToolchainSection {
5555
components: Option<Vec<String>>,
5656
targets: Option<Vec<String>>,
5757
profile: Option<String>,
58+
skip_std: Option<bool>,
5859
}
5960

6061
impl ToolchainSection {
@@ -63,6 +64,8 @@ impl ToolchainSection {
6364
&& self.components.is_none()
6465
&& self.targets.is_none()
6566
&& self.path.is_none()
67+
&& self.profile.is_none()
68+
&& self.skip_std.is_none()
6669
}
6770
}
6871

@@ -136,6 +139,7 @@ enum OverrideCfg {
136139
components: Vec<String>,
137140
targets: Vec<String>,
138141
profile: Option<Profile>,
142+
skip_std: bool,
139143
},
140144
}
141145

@@ -189,6 +193,7 @@ impl OverrideCfg {
189193
.as_deref()
190194
.map(Profile::from_str)
191195
.transpose()?,
196+
skip_std: file.toolchain.skip_std.unwrap_or(false),
192197
}
193198
}
194199
ToolchainName::Custom(name) => Self::Custom(name),
@@ -212,6 +217,7 @@ impl From<ToolchainName> for OverrideCfg {
212217
components: vec![],
213218
targets: vec![],
214219
profile: None,
220+
skip_std: false,
215221
},
216222
ToolchainName::Custom(name) => Self::Custom(name),
217223
}
@@ -736,13 +742,15 @@ impl<'a> Cfg<'a> {
736742
components,
737743
targets,
738744
profile,
745+
skip_std,
739746
} = override_config
740747
{
741748
self.ensure_installed(
742749
&toolchain,
743750
components,
744751
targets,
745752
profile,
753+
skip_std,
746754
force_non_host,
747755
verbose,
748756
)
@@ -754,7 +762,7 @@ impl<'a> Cfg<'a> {
754762
} else if let Some(toolchain) = self.get_default()? {
755763
let source = ActiveSource::Default;
756764
if let ToolchainName::Official(desc) = &toolchain {
757-
self.ensure_installed(desc, vec![], vec![], None, force_non_host, verbose)
765+
self.ensure_installed(desc, vec![], vec![], None, false, force_non_host, verbose)
758766
.await?;
759767
} else {
760768
Toolchain::with_source(self, toolchain.clone().into(), &source)?;
@@ -774,6 +782,7 @@ impl<'a> Cfg<'a> {
774782
components: Vec<String>,
775783
targets: Vec<String>,
776784
profile: Option<Profile>,
785+
skip_std: bool,
777786
force_non_host: bool,
778787
verbose: bool,
779788
) -> Result<(UpdateStatus, Toolchain<'_>)> {
@@ -801,6 +810,7 @@ impl<'a> Cfg<'a> {
801810
&targets,
802811
profile,
803812
false,
813+
skip_std,
804814
)
805815
.await?
806816
}
@@ -1048,6 +1058,7 @@ mod tests {
10481058
components: None,
10491059
targets: None,
10501060
profile: None,
1061+
skip_std: None,
10511062
}
10521063
}
10531064
);
@@ -1075,6 +1086,7 @@ profile = "default"
10751086
"thumbv2-none-eabi".into()
10761087
]),
10771088
profile: Some("default".into()),
1089+
skip_std: None,
10781090
}
10791091
}
10801092
);
@@ -1096,6 +1108,7 @@ channel = "nightly-2020-07-10"
10961108
components: None,
10971109
targets: None,
10981110
profile: None,
1111+
skip_std: None,
10991112
}
11001113
}
11011114
);
@@ -1117,6 +1130,7 @@ path = "foobar"
11171130
components: None,
11181131
targets: None,
11191132
profile: None,
1133+
skip_std: None,
11201134
}
11211135
}
11221136
);
@@ -1139,6 +1153,7 @@ components = []
11391153
components: Some(vec![]),
11401154
targets: None,
11411155
profile: None,
1156+
skip_std: None,
11421157
}
11431158
}
11441159
);
@@ -1161,6 +1176,7 @@ targets = []
11611176
components: None,
11621177
targets: Some(vec![]),
11631178
profile: None,
1179+
skip_std: None,
11641180
}
11651181
}
11661182
);
@@ -1182,6 +1198,7 @@ components = [ "rustfmt" ]
11821198
components: Some(vec!["rustfmt".into()]),
11831199
targets: None,
11841200
profile: None,
1201+
skip_std: None,
11851202
}
11861203
}
11871204
);

src/dist/mod.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -905,6 +905,7 @@ pub(crate) struct DistOptions<'a> {
905905
pub(crate) async fn update_from_dist(
906906
prefix: &InstallPrefix,
907907
opts: &DistOptions<'_>,
908+
skip_std: bool,
908909
) -> Result<Option<String>> {
909910
let fresh_install = !prefix.path().exists();
910911
if let Some(hash) = opts.update_hash {
@@ -980,6 +981,7 @@ pub(crate) async fn update_from_dist(
980981
opts.targets,
981982
&mut fetched,
982983
&opts.cfg.dist_root_url,
984+
skip_std,
983985
)
984986
.await;
985987

@@ -1077,6 +1079,7 @@ async fn try_update_from_dist_(
10771079
targets: &[&str],
10781080
fetched: &mut String,
10791081
dist_root: &str,
1082+
skip_std: bool,
10801083
) -> Result<Option<String>> {
10811084
let toolchain_str = toolchain.to_string();
10821085
let manifestation = Manifestation::open(prefix.clone(), toolchain.target.clone())?;
@@ -1134,9 +1137,15 @@ async fn try_update_from_dist_(
11341137
all_components.insert(component);
11351138
}
11361139

1137-
for &target in targets {
1138-
let triple = TargetTriple::new(target);
1139-
all_components.insert(Component::new("rust-std".to_string(), Some(triple), false));
1140+
if !skip_std {
1141+
for &target in targets {
1142+
let triple = TargetTriple::new(target);
1143+
all_components.insert(Component::new(
1144+
"rust-std".to_string(),
1145+
Some(triple),
1146+
false,
1147+
));
1148+
}
11401149
}
11411150

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

src/install.rs

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub(crate) enum InstallMethod<'a> {
3131
dest: &'a CustomToolchainName,
3232
cfg: &'a Cfg<'a>,
3333
},
34-
Dist(DistOptions<'a>),
34+
Dist(DistOptions<'a>, bool),
3535
}
3636

3737
impl InstallMethod<'_> {
@@ -46,10 +46,13 @@ impl InstallMethod<'_> {
4646
match self {
4747
InstallMethod::Copy { .. }
4848
| InstallMethod::Link { .. }
49-
| InstallMethod::Dist(DistOptions {
50-
old_date_version: None,
51-
..
52-
}) => debug!("installing toolchain {}", self.dest_basename()),
49+
| InstallMethod::Dist(
50+
DistOptions {
51+
old_date_version: None,
52+
..
53+
},
54+
_,
55+
) => debug!("installing toolchain {}", self.dest_basename()),
5356
_ => debug!("updating existing install for '{}'", self.dest_basename()),
5457
}
5558

@@ -64,10 +67,13 @@ impl InstallMethod<'_> {
6467
true => {
6568
debug!("toolchain {} installed", self.dest_basename());
6669
match self {
67-
InstallMethod::Dist(DistOptions {
68-
old_date_version: Some((_, v)),
69-
..
70-
}) => UpdateStatus::Updated(v.clone()),
70+
InstallMethod::Dist(
71+
DistOptions {
72+
old_date_version: Some((_, v)),
73+
..
74+
},
75+
_,
76+
) => UpdateStatus::Updated(v.clone()),
7177
InstallMethod::Copy { .. }
7278
| InstallMethod::Link { .. }
7379
| InstallMethod::Dist { .. } => UpdateStatus::Installed,
@@ -102,9 +108,9 @@ impl InstallMethod<'_> {
102108
utils::symlink_dir(src, path)?;
103109
Ok(true)
104110
}
105-
InstallMethod::Dist(opts) => {
111+
InstallMethod::Dist(opts, skip_std) => {
106112
let prefix = &InstallPrefix::from(path.to_owned());
107-
let maybe_new_hash = dist::update_from_dist(prefix, opts).await?;
113+
let maybe_new_hash = dist::update_from_dist(prefix, opts, *skip_std).await?;
108114

109115
if let Some(hash) = maybe_new_hash {
110116
if let Some(hash_file) = opts.update_hash {
@@ -123,17 +129,20 @@ impl InstallMethod<'_> {
123129
match self {
124130
InstallMethod::Copy { cfg, .. } => cfg,
125131
InstallMethod::Link { cfg, .. } => cfg,
126-
InstallMethod::Dist(DistOptions { cfg, .. }) => cfg,
132+
InstallMethod::Dist(DistOptions { cfg, .. }, _) => cfg,
127133
}
128134
}
129135

130136
fn local_name(&self) -> LocalToolchainName {
131137
match self {
132138
InstallMethod::Copy { dest, .. } => (*dest).into(),
133139
InstallMethod::Link { dest, .. } => (*dest).into(),
134-
InstallMethod::Dist(DistOptions {
135-
toolchain: desc, ..
136-
}) => (*desc).into(),
140+
InstallMethod::Dist(
141+
DistOptions {
142+
toolchain: desc, ..
143+
},
144+
_,
145+
) => (*desc).into(),
137146
}
138147
}
139148

@@ -145,11 +154,14 @@ impl InstallMethod<'_> {
145154
match self {
146155
InstallMethod::Copy { cfg, dest, .. } => cfg.toolchain_path(&(*dest).into()),
147156
InstallMethod::Link { cfg, dest, .. } => cfg.toolchain_path(&(*dest).into()),
148-
InstallMethod::Dist(DistOptions {
149-
cfg,
150-
toolchain: desc,
151-
..
152-
}) => cfg.toolchain_path(&(*desc).into()),
157+
InstallMethod::Dist(
158+
DistOptions {
159+
cfg,
160+
toolchain: desc,
161+
..
162+
},
163+
_,
164+
) => cfg.toolchain_path(&(*desc).into()),
153165
}
154166
}
155167
}

src/toolchain.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,18 @@ impl<'a> Toolchain<'a> {
6060
Err(RustupError::ToolchainNotInstalled {
6161
name: ToolchainName::Official(desc),
6262
..
63-
}) if install_if_missing => {
64-
Ok(
65-
DistributableToolchain::install(cfg, &desc, &[], &[], cfg.get_profile()?, true)
66-
.await?
67-
.1
68-
.toolchain,
69-
)
70-
}
63+
}) if install_if_missing => Ok(DistributableToolchain::install(
64+
cfg,
65+
&desc,
66+
&[],
67+
&[],
68+
cfg.get_profile()?,
69+
true,
70+
false,
71+
)
72+
.await?
73+
.1
74+
.toolchain),
7175
Err(e) => Err(e.into()),
7276
}
7377
}

0 commit comments

Comments
 (0)