@@ -26,6 +26,17 @@ pub struct Finder {
26
26
path : OsString ,
27
27
}
28
28
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
+
29
40
impl Finder {
30
41
pub fn new ( ) -> Self {
31
42
Self { cache : HashMap :: new ( ) , path : env:: var_os ( "PATH" ) . unwrap_or_default ( ) }
@@ -178,32 +189,40 @@ than building it.
178
189
continue ;
179
190
}
180
191
181
- // Check if there exists a built-in target in the list of supported targets.
182
- let mut has_target = false ;
183
192
let target_str = target. to_string ( ) ;
184
193
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 ( ) ) ;
187
204
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" ) ;
189
211
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
+ }
199
218
}
200
- }
201
219
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,
205
223
specify a correct location of the JSON specification file for custom targets!"
206
- ) ;
224
+ ) ;
225
+ }
207
226
}
208
227
209
228
if !build. config . dry_run ( ) {
0 commit comments