Skip to content

Commit ffdb04a

Browse files
committed
Bootstrap: Check validity of --target and --host triples before starting a build
Resolves #122128
1 parent ca7d34e commit ffdb04a

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/bootstrap/src/core/sanity.rs

+27
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use std::ffi::{OsStr, OsString};
1414
use std::fs;
1515
use std::path::PathBuf;
1616
use std::process::Command;
17+
use walkdir::WalkDir;
1718

1819
use crate::builder::Kind;
1920
use crate::core::config::Target;
@@ -177,6 +178,32 @@ than building it.
177178
continue;
178179
}
179180

181+
// Check if there exists a built-in target in the list of supported targets.
182+
let mut has_target = false;
183+
let target_str = target.to_string();
184+
185+
let supported_target_list =
186+
output(Command::new(&build.config.initial_rustc).args(["--print", "target-list"]));
187+
188+
has_target |= supported_target_list.contains(&target_str);
189+
190+
// If not, check for a valid file location that may have been specified
191+
// by the user for the custom target.
192+
if let Some(custom_target_path) = env::var_os("RUST_TARGET_PATH") {
193+
let target_os_str = OsStr::new(&target_str);
194+
let walker = WalkDir::new(custom_target_path).into_iter();
195+
for entry in walker.filter_map(|e| e.ok()) {
196+
has_target |= entry.file_name() == target_os_str;
197+
}
198+
}
199+
200+
if !has_target && !["A", "B", "C"].contains(&target_str.as_str()) {
201+
panic!(
202+
"No such target exists in the target list,
203+
specify a correct location of the JSON specification file for custom targets!"
204+
);
205+
}
206+
180207
if !build.config.dry_run() {
181208
cmd_finder.must_have(build.cc(*target));
182209
if let Some(ar) = build.ar(*target) {

0 commit comments

Comments
 (0)