11pub  use  self :: FileMatch :: * ; 
22
3- use  std:: borrow:: Cow ; 
43use  std:: env; 
54use  std:: fs; 
65use  std:: path:: { Path ,  PathBuf } ; 
@@ -91,26 +90,21 @@ impl<'a> FileSearch<'a> {
9190
9291    // Returns a list of directories where target-specific tool binaries are located. 
9392    pub  fn  get_tools_search_paths ( & self ,  self_contained :  bool )  -> Vec < PathBuf >  { 
94-         let  mut  p = PathBuf :: from ( self . sysroot ) ; 
95-         p. push ( find_libdir ( self . sysroot ) . as_ref ( ) ) ; 
96-         p. push ( RUST_LIB_DIR ) ; 
97-         p. push ( & self . triple ) ; 
98-         p. push ( "bin" ) ; 
93+         let  rustlib_path = rustc_target:: target_rustlib_path ( self . sysroot ,  & self . triple ) ; 
94+         let  p = std:: array:: IntoIter :: new ( [ 
95+             Path :: new ( & self . sysroot ) , 
96+             Path :: new ( & rustlib_path) , 
97+             Path :: new ( "bin" ) , 
98+         ] ) 
99+         . collect :: < PathBuf > ( ) ; 
99100        if  self_contained {  vec ! [ p. clone( ) ,  p. join( "self-contained" ) ]  }  else  {  vec ! [ p]  } 
100101    } 
101102} 
102103
103- pub  fn  relative_target_lib_path ( sysroot :  & Path ,  target_triple :  & str )  -> PathBuf  { 
104-     let  mut  p = PathBuf :: from ( find_libdir ( sysroot) . as_ref ( ) ) ; 
105-     assert ! ( p. is_relative( ) ) ; 
106-     p. push ( RUST_LIB_DIR ) ; 
107-     p. push ( target_triple) ; 
108-     p. push ( "lib" ) ; 
109-     p
110- } 
111- 
112104pub  fn  make_target_lib_path ( sysroot :  & Path ,  target_triple :  & str )  -> PathBuf  { 
113-     sysroot. join ( & relative_target_lib_path ( sysroot,  target_triple) ) 
105+     let  rustlib_path = rustc_target:: target_rustlib_path ( sysroot,  target_triple) ; 
106+     std:: array:: IntoIter :: new ( [ sysroot,  Path :: new ( & rustlib_path) ,  Path :: new ( "lib" ) ] ) 
107+         . collect :: < PathBuf > ( ) 
114108} 
115109
116110// This function checks if sysroot is found using env::args().next(), and if it 
@@ -157,11 +151,13 @@ pub fn get_or_default_sysroot() -> PathBuf {
157151                    return  None ; 
158152                } 
159153
154+                 // Pop off `bin/rustc`, obtaining the suspected sysroot. 
160155                p. pop ( ) ; 
161156                p. pop ( ) ; 
162-                 let  mut  libdir = PathBuf :: from ( & p) ; 
163-                 libdir. push ( find_libdir ( & p) . as_ref ( ) ) ; 
164-                 if  libdir. exists ( )  {  Some ( p)  }  else  {  None  } 
157+                 // Look for the target rustlib directory in the suspected sysroot. 
158+                 let  mut  rustlib_path = rustc_target:: target_rustlib_path ( & p,  "dummy" ) ; 
159+                 rustlib_path. pop ( ) ;  // pop off the dummy target. 
160+                 if  rustlib_path. exists ( )  {  Some ( p)  }  else  {  None  } 
165161            } 
166162            None  => None , 
167163        } 
@@ -171,37 +167,3 @@ pub fn get_or_default_sysroot() -> PathBuf {
171167    // use env::current_exe() to imply sysroot. 
172168    from_env_args_next ( ) . unwrap_or_else ( from_current_exe) 
173169} 
174- 
175- // The name of the directory rustc expects libraries to be located. 
176- fn  find_libdir ( sysroot :  & Path )  -> Cow < ' static ,  str >  { 
177-     // FIXME: This is a quick hack to make the rustc binary able to locate 
178-     // Rust libraries in Linux environments where libraries might be installed 
179-     // to lib64/lib32. This would be more foolproof by basing the sysroot off 
180-     // of the directory where `librustc_driver` is located, rather than 
181-     // where the rustc binary is. 
182-     // If --libdir is set during configuration to the value other than 
183-     // "lib" (i.e., non-default), this value is used (see issue #16552). 
184- 
185-     #[ cfg( target_pointer_width = "64" ) ]  
186-     const  PRIMARY_LIB_DIR :  & str  = "lib64" ; 
187- 
188-     #[ cfg( target_pointer_width = "32" ) ]  
189-     const  PRIMARY_LIB_DIR :  & str  = "lib32" ; 
190- 
191-     const  SECONDARY_LIB_DIR :  & str  = "lib" ; 
192- 
193-     match  option_env ! ( "CFG_LIBDIR_RELATIVE" )  { 
194-         None  | Some ( "lib" )  => { 
195-             if  sysroot. join ( PRIMARY_LIB_DIR ) . join ( RUST_LIB_DIR ) . exists ( )  { 
196-                 PRIMARY_LIB_DIR . into ( ) 
197-             }  else  { 
198-                 SECONDARY_LIB_DIR . into ( ) 
199-             } 
200-         } 
201-         Some ( libdir)  => libdir. into ( ) , 
202-     } 
203- } 
204- 
205- // The name of rustc's own place to organize libraries. 
206- // Used to be "rustc", now the default is "rustlib" 
207- const  RUST_LIB_DIR :  & str  = "rustlib" ; 
0 commit comments