Skip to content

Commit a80463f

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

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

src/bootstrap/src/core/sanity.rs

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

180+
// Check if there exists a built-in target in the list of supported targets.
181+
let cur_dir = env::current_dir().unwrap().display().to_string();
182+
183+
let supported_target_file = format!("{cur_dir}/compiler/rustc_target/src/spec/mod.rs");
184+
let contents = fs::read_to_string(supported_target_file)
185+
.expect("Should have been able to read the file.");
186+
187+
let (mut macro_beg, mut macro_end) = (false, false);
188+
let mut has_target = false;
189+
190+
let target_str = target.to_string();
191+
for line in contents.lines() {
192+
if macro_end {
193+
break;
194+
}
195+
if !macro_beg && line.contains("supported_targets!") {
196+
macro_beg = true;
197+
} else if macro_beg {
198+
if line.contains("}") {
199+
macro_end = true;
200+
} else if line.contains(&target_str) {
201+
has_target = true;
202+
}
203+
}
204+
}
205+
206+
// If not, check for a valid file location that may have been specified
207+
// by the user for the custom target.
208+
// todo!()
209+
210+
if !has_target {
211+
panic!("No such target exists in the target list,
212+
specify a correct location of the JSON specification file for custom targets!")
213+
}
214+
180215
if !build.config.dry_run() {
181216
cmd_finder.must_have(build.cc(*target));
182217
if let Some(ar) = build.ar(*target) {

0 commit comments

Comments
 (0)