1- use std:: io;
21use std:: path:: PathBuf ;
32use std:: sync:: LazyLock ;
43
5- pub fn binutil ( name : & str ) -> Option < PathBuf > {
6- static LLVM_TOOLS : LazyLock < LlvmTools > = LazyLock :: new ( || LlvmTools :: new ( ) . unwrap ( ) ) ;
4+ pub fn binutil ( name : & str ) -> PathBuf {
5+ static LLVM_TOOLS : LazyLock < Option < LlvmTools > > = LazyLock :: new ( LlvmTools :: new) ;
76
8- LLVM_TOOLS . tool ( name)
7+ LLVM_TOOLS
8+ . as_ref ( )
9+ . and_then ( |llvm_tools| llvm_tools. tool ( name) )
10+ . unwrap_or ( PathBuf :: from ( name) )
911}
1012
1113struct LlvmTools {
1214 bin : PathBuf ,
1315}
1416
1517impl LlvmTools {
16- pub fn new ( ) -> io :: Result < Self > {
18+ pub fn new ( ) -> Option < Self > {
1719 let mut rustc = crate :: rustc ( ) ;
1820 rustc. args ( [ "--print" , "sysroot" ] ) ;
1921
2022 eprintln ! ( "$ {rustc:?}" ) ;
21- let output = rustc. output ( ) ? ;
23+ let output = rustc. output ( ) . unwrap ( ) ;
2224 assert ! ( output. status. success( ) ) ;
2325
2426 let sysroot = String :: from_utf8 ( output. stdout ) . unwrap ( ) ;
2527 let rustlib = [ sysroot. trim_end ( ) , "lib" , "rustlib" ]
2628 . iter ( )
2729 . collect :: < PathBuf > ( ) ;
2830
29- let example_exe = exe ( "objdump" ) ;
30- for entry in rustlib. read_dir ( ) ? {
31- let bin = entry? . path ( ) . join ( "bin" ) ;
31+ let example_exe = exe ( "llvm- objdump" ) ;
32+ for entry in rustlib. read_dir ( ) . unwrap ( ) {
33+ let bin = entry. unwrap ( ) . path ( ) . join ( "bin" ) ;
3234 if bin. join ( & example_exe) . exists ( ) {
33- return Ok ( Self { bin } ) ;
35+ return Some ( Self { bin } ) ;
3436 }
3537 }
36- Err ( io:: Error :: new (
37- io:: ErrorKind :: NotFound ,
38- "Could not find llvm-tools component\n \
39- \n \
40- Maybe the rustup component `llvm-tools` is missing? Install it through: `rustup component add llvm-tools`",
41- ) )
38+
39+ None
4240 }
4341
4442 pub fn tool ( & self , name : & str ) -> Option < PathBuf > {
@@ -49,5 +47,5 @@ impl LlvmTools {
4947
5048fn exe ( name : & str ) -> String {
5149 let exe_suffix = std:: env:: consts:: EXE_SUFFIX ;
52- format ! ( "llvm- {name}{exe_suffix}" )
50+ format ! ( "{name}{exe_suffix}" )
5351}
0 commit comments