@@ -36,7 +36,7 @@ use std::fmt;
36
36
use std:: io:: Write ;
37
37
use std:: num:: NonZeroU32 ;
38
38
use std:: ops:: { Div , Mul } ;
39
- use std:: path:: PathBuf ;
39
+ use std:: path:: { Path , PathBuf } ;
40
40
use std:: str:: FromStr ;
41
41
use std:: sync:: Arc ;
42
42
use std:: time:: Duration ;
@@ -131,9 +131,8 @@ pub struct Session {
131
131
pub target : Target ,
132
132
pub host : Target ,
133
133
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 > ,
137
136
pub parse_sess : ParseSess ,
138
137
pub sysroot : PathBuf ,
139
138
/// The name of the root source file of the crate, in the local file system.
@@ -787,8 +786,7 @@ impl Session {
787
786
& self . sysroot ,
788
787
self . opts . target_triple . triple ( ) ,
789
788
& 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 ,
792
790
kind,
793
791
)
794
792
}
@@ -802,6 +800,18 @@ impl Session {
802
800
)
803
801
}
804
802
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
+
805
815
pub fn init_incr_comp_session (
806
816
& self ,
807
817
session_dir : PathBuf ,
@@ -1245,11 +1255,13 @@ pub fn build_session(
1245
1255
1246
1256
let host_triple = config:: host_triple ( ) ;
1247
1257
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) ) ;
1249
1259
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 ( )
1251
1263
} else {
1252
- Some ( SearchPath :: from_sysroot_and_triple ( & sysroot, target_triple) )
1264
+ Lrc :: new ( SearchPath :: from_sysroot_and_triple ( & sysroot, target_triple) )
1253
1265
} ;
1254
1266
1255
1267
let file_path_mapping = sopts. file_path_mapping ( ) ;
0 commit comments