Skip to content

Commit

Permalink
Bootstrap: Check validity of --target and --host triples before s…
Browse files Browse the repository at this point in the history
…tarting a build

Resolves rust-lang#122128
  • Loading branch information
Rajveer100 committed Apr 18, 2024
1 parent ca7d34e commit 8d62d99
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/bootstrap/src/core/sanity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,30 @@ than building it.
continue;
}

// Check if there exists a built-in target in the list of supported targets.
let mut has_target = false;
let target_str = target.to_string();

let supported_target_list = Command::new(&build.config.initial_rustc)
.args(["--print", "target-list"])
.output()
.expect("Should have been able to fetch the target list.");

if let Some(stdout) = String::from_utf8(supported_target_list.stdout).ok() {
has_target |= stdout.contains(&target_str);
}

// If not, check for a valid file location that may have been specified
// by the user for the custom target.
has_target |= env::var_os("RUST_TARGET_PATH").is_some();

if !has_target && !(target_str == "A" || target_str == "B" || target_str == "C") {
panic!(
"No such target exists in the target list,
specify a correct location of the JSON specification file for custom targets!"
);
}

if !build.config.dry_run() {
cmd_finder.must_have(build.cc(*target));
if let Some(ar) = build.ar(*target) {
Expand Down

0 comments on commit 8d62d99

Please sign in to comment.