@@ -124,16 +124,33 @@ fn is_target_dir<P: Into<PathBuf>>(path: P) -> bool {
124124 path. metadata ( ) . map ( |m| m. is_dir ( ) ) . unwrap_or ( false )
125125}
126126
127- fn for_all_targets < F : FnMut ( String ) > ( sysroot : & Path , mut f : F ) {
127+ fn target_has_std < P : Into < PathBuf > > ( path : P ) -> bool {
128+ let mut path = path. into ( ) ;
129+ path. push ( "lib" ) ;
130+ std:: fs:: read_dir ( path)
131+ . expect ( "invalid target" )
132+ . map ( |entry| entry. unwrap ( ) )
133+ . filter ( |entry| entry. file_type ( ) . unwrap ( ) . is_file ( ) )
134+ . filter_map ( |entry| entry. file_name ( ) . into_string ( ) . ok ( ) )
135+ . any ( |file_name| file_name. starts_with ( "libstd" ) && file_name. ends_with ( ".rlib" ) )
136+ }
137+
138+
139+ fn for_all_targets < F : FnMut ( String ) > ( sysroot : & Path , f : F ) {
128140 let target_dir = sysroot. join ( "lib" ) . join ( "rustlib" ) ;
129- for entry in std:: fs:: read_dir ( target_dir) . expect ( "invalid sysroot" ) {
130- let entry = entry. unwrap ( ) ;
131- if !is_target_dir ( entry. path ( ) ) {
132- continue ;
133- }
134- let target = entry. file_name ( ) . into_string ( ) . unwrap ( ) ;
135- f ( target) ;
141+ let mut targets = std:: fs:: read_dir ( target_dir)
142+ . expect ( "invalid sysroot" )
143+ . map ( |entry| entry. unwrap ( ) )
144+ . filter ( |entry| is_target_dir ( entry. path ( ) ) )
145+ . filter ( |entry| target_has_std ( entry. path ( ) ) )
146+ . map ( |entry| entry. file_name ( ) . into_string ( ) . unwrap ( ) )
147+ . peekable ( ) ;
148+
149+ if targets. peek ( ) . is_none ( ) {
150+ panic ! ( "No valid targets found" ) ;
136151 }
152+
153+ targets. for_each ( f) ;
137154}
138155
139156fn get_sysroot ( ) -> PathBuf {
0 commit comments