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 6, 2024
1 parent ca7d34e commit a80463f
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/bootstrap/src/core/sanity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,41 @@ than building it.
continue;
}

// Check if there exists a built-in target in the list of supported targets.
let cur_dir = env::current_dir().unwrap().display().to_string();

let supported_target_file = format!("{cur_dir}/compiler/rustc_target/src/spec/mod.rs");
let contents = fs::read_to_string(supported_target_file)
.expect("Should have been able to read the file.");

let (mut macro_beg, mut macro_end) = (false, false);
let mut has_target = false;

let target_str = target.to_string();
for line in contents.lines() {
if macro_end {
break;
}
if !macro_beg && line.contains("supported_targets!") {
macro_beg = true;
} else if macro_beg {
if line.contains("}") {
macro_end = true;
} else if line.contains(&target_str) {
has_target = true;
}
}
}

// If not, check for a valid file location that may have been specified
// by the user for the custom target.
// todo!()

if !has_target {
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 a80463f

Please sign in to comment.