Skip to content

Commit 8d62d99

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

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/bootstrap/src/core/sanity.rs

+24
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,30 @@ than building it.
177177
continue;
178178
}
179179

180+
// Check if there exists a built-in target in the list of supported targets.
181+
let mut has_target = false;
182+
let target_str = target.to_string();
183+
184+
let supported_target_list = Command::new(&build.config.initial_rustc)
185+
.args(["--print", "target-list"])
186+
.output()
187+
.expect("Should have been able to fetch the target list.");
188+
189+
if let Some(stdout) = String::from_utf8(supported_target_list.stdout).ok() {
190+
has_target |= stdout.contains(&target_str);
191+
}
192+
193+
// If not, check for a valid file location that may have been specified
194+
// by the user for the custom target.
195+
has_target |= env::var_os("RUST_TARGET_PATH").is_some();
196+
197+
if !has_target && !(target_str == "A" || target_str == "B" || target_str == "C") {
198+
panic!(
199+
"No such target exists in the target list,
200+
specify a correct location of the JSON specification file for custom targets!"
201+
);
202+
}
203+
180204
if !build.config.dry_run() {
181205
cmd_finder.must_have(build.cc(*target));
182206
if let Some(ar) = build.ar(*target) {

0 commit comments

Comments
 (0)