@@ -36,7 +36,7 @@ use std::fmt;
3636use std:: io:: Write ;
3737use std:: num:: NonZeroU32 ;
3838use std:: ops:: { Div , Mul } ;
39- use std:: path:: PathBuf ;
39+ use std:: path:: { Path , PathBuf } ;
4040use std:: str:: FromStr ;
4141use std:: sync:: Arc ;
4242use std:: time:: Duration ;
@@ -131,9 +131,8 @@ pub struct Session {
131131 pub target : Target ,
132132 pub host : Target ,
133133 pub opts : config:: Options ,
134- pub host_tlib_path : SearchPath ,
135- /// `None` if the host and target are the same.
136- pub target_tlib_path : Option < SearchPath > ,
134+ pub host_tlib_path : Lrc < SearchPath > ,
135+ pub target_tlib_path : Lrc < SearchPath > ,
137136 pub parse_sess : ParseSess ,
138137 pub sysroot : PathBuf ,
139138 /// The name of the root source file of the crate, in the local file system.
@@ -787,8 +786,7 @@ impl Session {
787786 & self . sysroot ,
788787 self . opts . target_triple . triple ( ) ,
789788 & self . opts . search_paths ,
790- // `target_tlib_path == None` means it's the same as `host_tlib_path`.
791- self . target_tlib_path . as_ref ( ) . unwrap_or ( & self . host_tlib_path ) ,
789+ & self . target_tlib_path ,
792790 kind,
793791 )
794792 }
@@ -802,6 +800,18 @@ impl Session {
802800 )
803801 }
804802
803+ /// Returns a list of directories where target-specific tool binaries are located.
804+ pub fn get_tools_search_paths ( & self , self_contained : bool ) -> Vec < PathBuf > {
805+ let rustlib_path = rustc_target:: target_rustlib_path ( & self . sysroot , & config:: host_triple ( ) ) ;
806+ let p = std:: array:: IntoIter :: new ( [
807+ Path :: new ( & self . sysroot ) ,
808+ Path :: new ( & rustlib_path) ,
809+ Path :: new ( "bin" ) ,
810+ ] )
811+ . collect :: < PathBuf > ( ) ;
812+ if self_contained { vec ! [ p. clone( ) , p. join( "self-contained" ) ] } else { vec ! [ p] }
813+ }
814+
805815 pub fn init_incr_comp_session (
806816 & self ,
807817 session_dir : PathBuf ,
@@ -1245,11 +1255,13 @@ pub fn build_session(
12451255
12461256 let host_triple = config:: host_triple ( ) ;
12471257 let target_triple = sopts. target_triple . triple ( ) ;
1248- let host_tlib_path = SearchPath :: from_sysroot_and_triple ( & sysroot, host_triple) ;
1258+ let host_tlib_path = Lrc :: new ( SearchPath :: from_sysroot_and_triple ( & sysroot, host_triple) ) ;
12491259 let target_tlib_path = if host_triple == target_triple {
1250- None
1260+ // Use the same `SearchPath` if host and target triple are identical to avoid unnecessary
1261+ // rescanning of the target lib path and an unnecessary allocation.
1262+ host_tlib_path. clone ( )
12511263 } else {
1252- Some ( SearchPath :: from_sysroot_and_triple ( & sysroot, target_triple) )
1264+ Lrc :: new ( SearchPath :: from_sysroot_and_triple ( & sysroot, target_triple) )
12531265 } ;
12541266
12551267 let file_path_mapping = sopts. file_path_mapping ( ) ;
0 commit comments