Skip to content

Commit f47345e

Browse files
committed
Alter lookup of crates
1 parent 0fef891 commit f47345e

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

compiler/rustc_metadata/src/locator.rs

+20-1
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ pub(crate) struct CrateLocator<'a> {
247247

248248
// Immutable per-search configuration.
249249
crate_name: Symbol,
250+
// Dependency paths passed through --extern
250251
exact_paths: Vec<CanonicalizedPath>,
251252
pub hash: Option<Svh>,
252253
extra_filename: Option<&'a str>,
@@ -511,6 +512,8 @@ impl<'a> CrateLocator<'a> {
511512
rlib: self.extract_one(rlibs, CrateFlavor::Rlib, &mut slot)?,
512513
dylib: self.extract_one(dylibs, CrateFlavor::Dylib, &mut slot)?,
513514
};
515+
// Question: check if we have no rmeta, but rlib/dylib with is_stub, and in that case
516+
// invoke `find_library`?
514517
Ok(slot.map(|(svh, metadata, _)| (svh, Library { source, metadata })))
515518
}
516519

@@ -730,6 +733,14 @@ impl<'a> CrateLocator<'a> {
730733
};
731734
if file.starts_with("lib") {
732735
if file.ends_with(".rlib") {
736+
// In case the .rlib contains only stub metadata, we will most likely
737+
// need to load a corresponding .rmeta file. Since it will often be
738+
// located right next to the .rlib path, directly add it to the candidate
739+
// paths as a "fast-path".
740+
let possible_rmeta_path = loc_orig.with_extension("rmeta");
741+
if let Ok(rmeta_path) = try_canonicalize(possible_rmeta_path) {
742+
rmetas.insert(rmeta_path, PathKind::ExternFlag);
743+
}
733744
rlibs.insert(loc_canon.clone(), PathKind::ExternFlag);
734745
continue;
735746
}
@@ -740,7 +751,15 @@ impl<'a> CrateLocator<'a> {
740751
}
741752
let dll_prefix = self.target.dll_prefix.as_ref();
742753
let dll_suffix = self.target.dll_suffix.as_ref();
743-
if file.starts_with(dll_prefix) && file.ends_with(dll_suffix) {
754+
if let Some(stem) =
755+
file.strip_prefix(dll_prefix).and_then(|name| name.strip_suffix(dll_suffix))
756+
{
757+
// See comment above about stub metadata, it applies also here for dylibs
758+
let possible_rmeta_path =
759+
loc_orig.parent().unwrap().join(format!("lib{stem}.rmeta"));
760+
if let Ok(rmeta_path) = try_canonicalize(possible_rmeta_path) {
761+
rmetas.insert(rmeta_path, PathKind::ExternFlag);
762+
}
744763
dylibs.insert(loc_canon.clone(), PathKind::ExternFlag);
745764
continue;
746765
}

0 commit comments

Comments
 (0)