diff options
Diffstat (limited to 'compiler/rustc_metadata')
| -rw-r--r-- | compiler/rustc_metadata/src/creader.rs | 3 | ||||
| -rw-r--r-- | compiler/rustc_metadata/src/locator.rs | 84 | ||||
| -rw-r--r-- | compiler/rustc_metadata/src/native_libs.rs | 4 |
3 files changed, 48 insertions, 43 deletions
diff --git a/compiler/rustc_metadata/src/creader.rs b/compiler/rustc_metadata/src/creader.rs index e525d94a0c1..ca16a66763a 100644 --- a/compiler/rustc_metadata/src/creader.rs +++ b/compiler/rustc_metadata/src/creader.rs @@ -507,7 +507,8 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> { locator.is_proc_macro = true; locator.target = &self.sess.host; locator.tuple = TargetTuple::from_tuple(config::host_tuple()); - locator.filesearch = self.sess.host_filesearch(path_kind); + locator.filesearch = self.sess.host_filesearch(); + locator.path_kind = path_kind; let Some(host_result) = self.load(locator)? else { return Ok(None); diff --git a/compiler/rustc_metadata/src/locator.rs b/compiler/rustc_metadata/src/locator.rs index ddd97fc66f6..0b53e5eeaa8 100644 --- a/compiler/rustc_metadata/src/locator.rs +++ b/compiler/rustc_metadata/src/locator.rs @@ -253,9 +253,10 @@ pub(crate) struct CrateLocator<'a> { extra_filename: Option<&'a str>, pub target: &'a Target, pub tuple: TargetTuple, - pub filesearch: FileSearch<'a>, + pub filesearch: &'a FileSearch, pub is_proc_macro: bool, + pub path_kind: PathKind, // Mutable in-progress state or output. crate_rejections: CrateRejections, } @@ -339,7 +340,8 @@ impl<'a> CrateLocator<'a> { extra_filename, target: &sess.target, tuple: sess.opts.target_triple.clone(), - filesearch: sess.target_filesearch(path_kind), + filesearch: sess.target_filesearch(), + path_kind, is_proc_macro: false, crate_rejections: CrateRejections::default(), } @@ -407,47 +409,49 @@ impl<'a> CrateLocator<'a> { // given that `extra_filename` comes from the `-C extra-filename` // option and thus can be anything, and the incorrect match will be // handled safely in `extract_one`. - for search_path in self.filesearch.search_paths() { + for search_path in self.filesearch.search_paths(self.path_kind) { debug!("searching {}", search_path.dir.display()); - for spf in search_path.files.iter() { - debug!("testing {}", spf.path.display()); + let spf = &search_path.files; - let f = &spf.file_name_str; - let (hash, kind) = if let Some(f) = f.strip_prefix(rlib_prefix) - && let Some(f) = f.strip_suffix(rlib_suffix) - { - (f, CrateFlavor::Rlib) - } else if let Some(f) = f.strip_prefix(rmeta_prefix) - && let Some(f) = f.strip_suffix(rmeta_suffix) - { - (f, CrateFlavor::Rmeta) - } else if let Some(f) = f.strip_prefix(dylib_prefix) - && let Some(f) = f.strip_suffix(dylib_suffix.as_ref()) - { - (f, CrateFlavor::Dylib) - } else { - if f.starts_with(staticlib_prefix) && f.ends_with(staticlib_suffix.as_ref()) { - self.crate_rejections.via_kind.push(CrateMismatch { - path: spf.path.clone(), - got: "static".to_string(), - }); - } - continue; - }; - - info!("lib candidate: {}", spf.path.display()); + let mut should_check_staticlibs = true; + for (prefix, suffix, kind) in [ + (rlib_prefix.as_str(), rlib_suffix, CrateFlavor::Rlib), + (rmeta_prefix.as_str(), rmeta_suffix, CrateFlavor::Rmeta), + (dylib_prefix, dylib_suffix, CrateFlavor::Dylib), + ] { + if prefix == staticlib_prefix && suffix == staticlib_suffix { + should_check_staticlibs = false; + } + if let Some(matches) = spf.query(prefix, suffix) { + for (hash, spf) in matches { + info!("lib candidate: {}", spf.path.display()); - let (rlibs, rmetas, dylibs) = candidates.entry(hash.to_string()).or_default(); - let path = try_canonicalize(&spf.path).unwrap_or_else(|_| spf.path.clone()); - if seen_paths.contains(&path) { - continue; - }; - seen_paths.insert(path.clone()); - match kind { - CrateFlavor::Rlib => rlibs.insert(path, search_path.kind), - CrateFlavor::Rmeta => rmetas.insert(path, search_path.kind), - CrateFlavor::Dylib => dylibs.insert(path, search_path.kind), - }; + let (rlibs, rmetas, dylibs) = + candidates.entry(hash.to_string()).or_default(); + let path = + try_canonicalize(&spf.path).unwrap_or_else(|_| spf.path.to_path_buf()); + if seen_paths.contains(&path) { + continue; + }; + seen_paths.insert(path.clone()); + match kind { + CrateFlavor::Rlib => rlibs.insert(path, search_path.kind), + CrateFlavor::Rmeta => rmetas.insert(path, search_path.kind), + CrateFlavor::Dylib => dylibs.insert(path, search_path.kind), + }; + } + } + } + if let Some(static_matches) = should_check_staticlibs + .then(|| spf.query(staticlib_prefix, staticlib_suffix)) + .flatten() + { + for (_, spf) in static_matches { + self.crate_rejections.via_kind.push(CrateMismatch { + path: spf.path.to_path_buf(), + got: "static".to_string(), + }); + } } } diff --git a/compiler/rustc_metadata/src/native_libs.rs b/compiler/rustc_metadata/src/native_libs.rs index b7695216f3c..493db498b7c 100644 --- a/compiler/rustc_metadata/src/native_libs.rs +++ b/compiler/rustc_metadata/src/native_libs.rs @@ -28,10 +28,10 @@ pub fn walk_native_lib_search_dirs<R>( mut f: impl FnMut(&Path, bool /*is_framework*/) -> ControlFlow<R>, ) -> ControlFlow<R> { // Library search paths explicitly supplied by user (`-L` on the command line). - for search_path in sess.target_filesearch(PathKind::Native).cli_search_paths() { + for search_path in sess.target_filesearch().cli_search_paths(PathKind::Native) { f(&search_path.dir, false)?; } - for search_path in sess.target_filesearch(PathKind::Framework).cli_search_paths() { + for search_path in sess.target_filesearch().cli_search_paths(PathKind::Framework) { // Frameworks are looked up strictly in framework-specific paths. if search_path.kind != PathKind::All { f(&search_path.dir, true)?; |
