Skip to content

Commit

Permalink
feat(cli): warn when removing the last/host target for a toolchain
Browse files Browse the repository at this point in the history
  • Loading branch information
rami3l committed Jan 15, 2024
1 parent f2ecc75 commit dbdbceb
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
12 changes: 11 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ wait-timeout = "0.2"
walkdir = { workspace = true, optional = true }
xz2 = "0.1.3"
zstd = "0.13"
itertools = "0.12.0"

[target."cfg(windows)".dependencies]
cc = "1"
Expand Down
22 changes: 17 additions & 5 deletions src/cli/rustup_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use clap::{
Arg, ArgAction, ArgGroup, ArgMatches, Command, ValueEnum,
};
use clap_complete::Shell;
use itertools::Itertools;

use crate::{
cli::{
Expand Down Expand Up @@ -1334,11 +1335,22 @@ fn target_remove(cfg: &Cfg, m: &ArgMatches) -> Result<utils::ExitCode> {
let distributable = DistributableToolchain::try_from(&toolchain)?;

for target in m.get_many::<String>("target").unwrap() {
let new_component = Component::new(
"rust-std".to_string(),
Some(TargetTriple::new(target)),
false,
);
let target = TargetTriple::new(target);
let default_target = cfg.get_default_host_triple().ok();
if default_target.as_ref() == Some(&target) {
warn!("after removing this default host target, proc-macros and build scripts might no longer build");
}
let at_most_one_target = distributable.components().ok().and_then(|cs| {
// Every component target that is not `None` (wildcard).
let targets = cs
.iter()
.filter_map(|c| c.installed.then(|| c.component.target.clone()).flatten());
targets.unique().at_most_one().ok()
});
if at_most_one_target.is_some() {
warn!("after removing the last target, no build targets will be available");
}
let new_component = Component::new("rust-std".to_string(), Some(target), false);
distributable.remove_component(new_component)?;
}

Expand Down

0 comments on commit dbdbceb

Please sign in to comment.