diff options
Diffstat (limited to 'compiler/rustc_session/src/session.rs')
| -rw-r--r-- | compiler/rustc_session/src/session.rs | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs index 4471e1e0ae8..d6f4a3ae4f1 100644 --- a/compiler/rustc_session/src/session.rs +++ b/compiler/rustc_session/src/session.rs @@ -36,7 +36,7 @@ use std::fmt; use std::io::Write; use std::num::NonZeroU32; use std::ops::{Div, Mul}; -use std::path::PathBuf; +use std::path::{Path, PathBuf}; use std::str::FromStr; use std::sync::Arc; use std::time::Duration; @@ -131,9 +131,8 @@ pub struct Session { pub target: Target, pub host: Target, pub opts: config::Options, - pub host_tlib_path: SearchPath, - /// `None` if the host and target are the same. - pub target_tlib_path: Option<SearchPath>, + pub host_tlib_path: Lrc<SearchPath>, + pub target_tlib_path: Lrc<SearchPath>, pub parse_sess: ParseSess, pub sysroot: PathBuf, /// The name of the root source file of the crate, in the local file system. @@ -787,8 +786,7 @@ impl Session { &self.sysroot, self.opts.target_triple.triple(), &self.opts.search_paths, - // `target_tlib_path == None` means it's the same as `host_tlib_path`. - self.target_tlib_path.as_ref().unwrap_or(&self.host_tlib_path), + &self.target_tlib_path, kind, ) } @@ -802,6 +800,18 @@ impl Session { ) } + /// Returns a list of directories where target-specific tool binaries are located. + pub fn get_tools_search_paths(&self, self_contained: bool) -> Vec<PathBuf> { + let rustlib_path = rustc_target::target_rustlib_path(&self.sysroot, &config::host_triple()); + let p = std::array::IntoIter::new([ + Path::new(&self.sysroot), + Path::new(&rustlib_path), + Path::new("bin"), + ]) + .collect::<PathBuf>(); + if self_contained { vec![p.clone(), p.join("self-contained")] } else { vec![p] } + } + pub fn init_incr_comp_session( &self, session_dir: PathBuf, @@ -1245,11 +1255,13 @@ pub fn build_session( let host_triple = config::host_triple(); let target_triple = sopts.target_triple.triple(); - let host_tlib_path = SearchPath::from_sysroot_and_triple(&sysroot, host_triple); + let host_tlib_path = Lrc::new(SearchPath::from_sysroot_and_triple(&sysroot, host_triple)); let target_tlib_path = if host_triple == target_triple { - None + // Use the same `SearchPath` if host and target triple are identical to avoid unnecessary + // rescanning of the target lib path and an unnecessary allocation. + host_tlib_path.clone() } else { - Some(SearchPath::from_sysroot_and_triple(&sysroot, target_triple)) + Lrc::new(SearchPath::from_sysroot_and_triple(&sysroot, target_triple)) }; let file_path_mapping = sopts.file_path_mapping(); |
