88//! In theory if we get past this phase it's a bug if a build fails, but in 
99//! practice that's likely not true! 
1010
11- use  std:: collections:: HashMap ; 
11+ use  std:: collections:: { HashMap ,   HashSet } ; 
1212use  std:: env; 
1313use  std:: ffi:: { OsStr ,  OsString } ; 
1414use  std:: fs; 
@@ -33,8 +33,6 @@ pub struct Finder {
3333// Targets can be removed from this list once they are present in the stage0 compiler (usually by updating the beta compiler of the bootstrap). 
3434const  STAGE0_MISSING_TARGETS :  & [ & str ]  = & [ 
3535    // just a dummy comment so the list doesn't get onelined 
36-     "aarch64-apple-visionos" , 
37-     "aarch64-apple-visionos-sim" , 
3836] ; 
3937
4038impl  Finder  { 
@@ -169,6 +167,12 @@ than building it.
169167        . map ( |p| cmd_finder. must_have ( p) ) 
170168        . or_else ( || cmd_finder. maybe_have ( "reuse" ) ) ; 
171169
170+     let  stage0_supported_target_list:  HashSet < String >  =
171+         output ( Command :: new ( & build. config . initial_rustc ) . args ( [ "--print" ,  "target-list" ] ) ) 
172+             . lines ( ) 
173+             . map ( |s| s. to_string ( ) ) 
174+             . collect ( ) ; 
175+ 
172176    // We're gonna build some custom C code here and there, host triples 
173177    // also build some C++ shims for LLVM so we need a C++ compiler. 
174178    for  target in  & build. targets  { 
@@ -195,11 +199,19 @@ than building it.
195199        if  ![ "A" ,  "B" ,  "C" ] . contains ( & target_str. as_str ( ) )  { 
196200            let  mut  has_target = false ; 
197201
198-             let  supported_target_list =
199-                 output ( Command :: new ( & build. config . initial_rustc ) . args ( [ "--print" ,  "target-list" ] ) ) ; 
202+             let  missing_targets_hashset:  HashSet < _ >  = STAGE0_MISSING_TARGETS . iter ( ) . map ( |t| t. to_string ( ) ) . collect ( ) ; 
203+             let  duplicated_targets:  Vec < _ >  = stage0_supported_target_list. intersection ( & missing_targets_hashset) . collect ( ) ; 
204+ 
205+             if  !duplicated_targets. is_empty ( )  { 
206+                 println ! ( "Following targets supported from the stage0 compiler, please remove them from STAGE0_MISSING_TARGETS list." ) ; 
207+                 for  duplicated_target in  duplicated_targets { 
208+                     println ! ( "  {duplicated_target}" ) ; 
209+                 } 
210+                 std:: process:: exit ( 1 ) ; 
211+             } 
200212
201213            // Check if it's a built-in target. 
202-             has_target |= supported_target_list . contains ( & target_str) ; 
214+             has_target |= stage0_supported_target_list . contains ( & target_str) ; 
203215            has_target |= STAGE0_MISSING_TARGETS . contains ( & target_str. as_str ( ) ) ; 
204216
205217            if  !has_target { 
0 commit comments