Skip to content

Commit 819a5f0

Browse files
authored
Rollup merge of rust-lang#124461 - onur-ozkan:followup-123546, r=pietroalbini
handle the targets that are missing in stage0 During sanity checks, we search for target names to determine if they exist in the compiler's built-in target list (`rustc --print target-list`). While a target name may be present in the stage2 compiler, it might not yet be included in stage0. This PR handles that difference. Follow-up of rust-lang#123546
2 parents 561b5de + 57a5f34 commit 819a5f0

File tree

1 file changed

+38
-19
lines changed

1 file changed

+38
-19
lines changed

src/bootstrap/src/core/sanity.rs

+38-19
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,17 @@ pub struct Finder {
2626
path: OsString,
2727
}
2828

29+
// During sanity checks, we search for target names to determine if they exist in the compiler's built-in
30+
// target list (`rustc --print target-list`). While a target name may be present in the stage2 compiler,
31+
// it might not yet be included in stage0. In such cases, we handle the targets missing from stage0 in this list.
32+
//
33+
// Targets can be removed from this list once they are present in the stage0 compiler (usually by updating the beta compiler of the bootstrap).
34+
const STAGE0_MISSING_TARGETS: &[&str] = &[
35+
// just a dummy comment so the list doesn't get onelined
36+
"aarch64-apple-visionos",
37+
"aarch64-apple-visionos-sim",
38+
];
39+
2940
impl Finder {
3041
pub fn new() -> Self {
3142
Self { cache: HashMap::new(), path: env::var_os("PATH").unwrap_or_default() }
@@ -178,32 +189,40 @@ than building it.
178189
continue;
179190
}
180191

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

185-
let supported_target_list =
186-
output(Command::new(&build.config.initial_rustc).args(["--print", "target-list"]));
194+
// Ignore fake targets that are only used for unit tests in bootstrap.
195+
if !["A", "B", "C"].contains(&target_str.as_str()) {
196+
let mut has_target = false;
197+
198+
let supported_target_list =
199+
output(Command::new(&build.config.initial_rustc).args(["--print", "target-list"]));
200+
201+
// Check if it's a built-in target.
202+
has_target |= supported_target_list.contains(&target_str);
203+
has_target |= STAGE0_MISSING_TARGETS.contains(&target_str.as_str());
187204

188-
has_target |= supported_target_list.contains(&target_str);
205+
if !has_target {
206+
// This might also be a custom target, so check the target file that could have been specified by the user.
207+
if let Some(custom_target_path) = env::var_os("RUST_TARGET_PATH") {
208+
let mut target_filename = OsString::from(&target_str);
209+
// Target filename ends with `.json`.
210+
target_filename.push(".json");
189211

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 mut target_os_str = OsString::from(&target_str);
194-
target_os_str.push(".json");
195-
// Recursively traverse through nested directories.
196-
let walker = WalkDir::new(custom_target_path).into_iter();
197-
for entry in walker.filter_map(|e| e.ok()) {
198-
has_target |= entry.file_name() == target_os_str;
212+
// Recursively traverse through nested directories.
213+
let walker = WalkDir::new(custom_target_path).into_iter();
214+
for entry in walker.filter_map(|e| e.ok()) {
215+
has_target |= entry.file_name() == target_filename;
216+
}
217+
}
199218
}
200-
}
201219

202-
if !has_target && !["A", "B", "C"].contains(&target_str.as_str()) {
203-
panic!(
204-
"No such target exists in the target list,
220+
if !has_target {
221+
panic!(
222+
"No such target exists in the target list,
205223
specify a correct location of the JSON specification file for custom targets!"
206-
);
224+
);
225+
}
207226
}
208227

209228
if !build.config.dry_run() {

0 commit comments

Comments
 (0)