1+ use crossbeam_channel:: unbounded;
12use rayon:: prelude:: { IntoParallelIterator , ParallelIterator } ;
23use std:: env;
34use std:: env:: consts:: EXE_SUFFIX ;
@@ -9,8 +10,9 @@ use std::path::{Path, PathBuf};
910use std:: process:: { Command , Stdio } ;
1011use std:: sync:: OnceLock ;
1112
13+ use ignore:: WalkBuilder ;
14+ use ignore:: WalkState :: Continue ;
1215use log:: warn;
13- use walkdir:: WalkDir ;
1416
1517pub static LLVM_PATH : OnceLock < PathBuf > = OnceLock :: new ( ) ;
1618
@@ -74,28 +76,38 @@ pub fn find_binaries(binary_path: &Path) -> Vec<PathBuf> {
7476 vec ! [ binary_path. to_owned( ) ]
7577 } else {
7678 let mut paths = vec ! [ ] ;
77- let mut bytes = vec ! [ 0u8 ; 128 ] ;
7879
79- for entry in WalkDir :: new ( binary_path) . follow_links ( true ) {
80- let entry = entry
81- . unwrap_or_else ( |e| panic ! ( "Failed to open directory '{:?}': {}" , binary_path, e) ) ;
80+ let ( sender, receiver) = unbounded ( ) ;
81+ let walker = WalkBuilder :: new ( binary_path)
82+ . threads ( num_cpus:: get ( ) - 1 )
83+ . build_parallel ( ) ;
84+ walker. run ( || {
85+ let sender = sender. clone ( ) ;
86+ let mut bytes = vec ! [ 0u8 ; 128 ] ;
8287
83- if !entry. file_type ( ) . is_file ( ) {
84- continue ;
85- }
88+ Box :: new ( move |result| {
89+ let entry = result. unwrap ( ) ;
8690
87- let size = entry. metadata ( ) . unwrap ( ) . len ( ) ;
88- if size == 0 {
89- continue ;
90- }
91+ if !entry. file_type ( ) . unwrap ( ) . is_file ( ) {
92+ return Continue ;
93+ }
9194
92- let file = fs:: File :: open ( entry. path ( ) ) . unwrap ( ) ;
95+ let file = fs:: File :: open ( entry. path ( ) ) . unwrap ( ) ;
96+ let read = file. take ( 128 ) . read ( & mut bytes) . unwrap ( ) ;
97+ if read == 0 {
98+ return Continue ;
99+ }
93100
94- file. take ( 128 ) . read_exact ( & mut bytes) . unwrap ( ) ;
101+ if infer:: is_app ( & bytes) {
102+ sender. send ( entry. into_path ( ) ) . unwrap ( ) ;
103+ }
95104
96- if infer:: is_app ( & bytes) {
97- paths. push ( entry. into_path ( ) ) ;
98- }
105+ Continue
106+ } )
107+ } ) ;
108+
109+ while let Ok ( path) = receiver. try_recv ( ) {
110+ paths. push ( path) ;
99111 }
100112
101113 paths
0 commit comments