diff options
| author | Yuki Okushi <jtitor@2k36.org> | 2021-09-17 14:09:47 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-09-17 14:09:47 +0900 |
| commit | a84d39c7d4e8b1cdbfc44f368181f2fe05a6ac1c (patch) | |
| tree | 0eb0a0a375f5fcebdd5b45bca1dd2fa8c6bccbb3 /compiler/rustc_session/src/session.rs | |
| parent | 758c7bcc58387178ee0d7c454e6cf748a44a8618 (diff) | |
| parent | d7ef0b30e89960aede88bf450e4a2172332432e0 (diff) | |
| download | rust-a84d39c7d4e8b1cdbfc44f368181f2fe05a6ac1c.tar.gz rust-a84d39c7d4e8b1cdbfc44f368181f2fe05a6ac1c.zip | |
Rollup merge of #88751 - bjorn3:move_filesearch, r=oli-obk
Couple of changes to FileSearch and SearchPath * Turn a couple of regular comments into doc comments * Move `get_tools_search_paths` from `FileSearch` to `Session` * Use Lrc instead of Option to avoid duplication of a `SearchPath`
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(); |
