diff options
| author | Simonas Kazlauskas <git@kazlauskas.me> | 2021-05-10 19:15:19 +0300 |
|---|---|---|
| committer | Simonas Kazlauskas <git@kazlauskas.me> | 2021-05-10 19:15:19 +0300 |
| commit | b7c5599d22018ab6be88442c4668bc1697f85b8e (patch) | |
| tree | d1073b3273c158b7c329bb8382aef2923969ebd0 /compiler/rustc_session/src | |
| parent | 2fb1dee14b3eff979f91e99ad034cfe262fc78c3 (diff) | |
Adjust target search algorithm for rustlib path
With this the concerns expressed in #83800 should be addressed.
Diffstat (limited to 'compiler/rustc_session/src')
| -rw-r--r-- | compiler/rustc_session/src/filesearch.rs | 68 |
1 files changed, 15 insertions, 53 deletions
diff --git a/compiler/rustc_session/src/filesearch.rs b/compiler/rustc_session/src/filesearch.rs index 2df326628e7..6fe6a555f1a 100644 --- a/compiler/rustc_session/src/filesearch.rs +++ b/compiler/rustc_session/src/filesearch.rs @@ -1,6 +1,5 @@ pub use self::FileMatch::*; -use std::borrow::Cow; use std::env; use std::fs; use std::path::{Path, PathBuf}; @@ -91,26 +90,21 @@ impl<'a> FileSearch<'a> { // 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 mut p = PathBuf::from(self.sysroot); - p.push(find_libdir(self.sysroot).as_ref()); - p.push(RUST_LIB_DIR); - p.push(&self.triple); - p.push("bin"); + let rustlib_path = rustc_target::target_rustlib_path(self.sysroot, &self.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 relative_target_lib_path(sysroot: &Path, target_triple: &str) -> PathBuf { - let mut p = PathBuf::from(find_libdir(sysroot).as_ref()); - assert!(p.is_relative()); - p.push(RUST_LIB_DIR); - p.push(target_triple); - p.push("lib"); - p -} - pub fn make_target_lib_path(sysroot: &Path, target_triple: &str) -> PathBuf { - sysroot.join(&relative_target_lib_path(sysroot, target_triple)) + let rustlib_path = rustc_target::target_rustlib_path(sysroot, target_triple); + std::array::IntoIter::new([sysroot, Path::new(&rustlib_path), Path::new("lib")]) + .collect::<PathBuf>() } // 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 { return None; } + // Pop off `bin/rustc`, obtaining the suspected sysroot. p.pop(); p.pop(); - let mut libdir = PathBuf::from(&p); - libdir.push(find_libdir(&p).as_ref()); - if libdir.exists() { Some(p) } else { None } + // Look for the target rustlib directory in the suspected sysroot. + let mut rustlib_path = rustc_target::target_rustlib_path(&p, "dummy"); + rustlib_path.pop(); // pop off the dummy target. + if rustlib_path.exists() { Some(p) } else { None } } None => None, } @@ -171,37 +167,3 @@ pub fn get_or_default_sysroot() -> PathBuf { // use env::current_exe() to imply sysroot. from_env_args_next().unwrap_or_else(from_current_exe) } - -// The name of the directory rustc expects libraries to be located. -fn find_libdir(sysroot: &Path) -> Cow<'static, str> { - // FIXME: This is a quick hack to make the rustc binary able to locate - // Rust libraries in Linux environments where libraries might be installed - // to lib64/lib32. This would be more foolproof by basing the sysroot off - // of the directory where `librustc_driver` is located, rather than - // where the rustc binary is. - // If --libdir is set during configuration to the value other than - // "lib" (i.e., non-default), this value is used (see issue #16552). - - #[cfg(target_pointer_width = "64")] - const PRIMARY_LIB_DIR: &str = "lib64"; - - #[cfg(target_pointer_width = "32")] - const PRIMARY_LIB_DIR: &str = "lib32"; - - const SECONDARY_LIB_DIR: &str = "lib"; - - match option_env!("CFG_LIBDIR_RELATIVE") { - None | Some("lib") => { - if sysroot.join(PRIMARY_LIB_DIR).join(RUST_LIB_DIR).exists() { - PRIMARY_LIB_DIR.into() - } else { - SECONDARY_LIB_DIR.into() - } - } - Some(libdir) => libdir.into(), - } -} - -// The name of rustc's own place to organize libraries. -// Used to be "rustc", now the default is "rustlib" -const RUST_LIB_DIR: &str = "rustlib"; |
