Skip to content

Commit d6ff46c

Browse files
authored
Rollup merge of #75548 - dancrossnyc:master, r=tmandry
librustc_metadata::locator: Properly detect file type. Make sure to test file types against the non-canonicalized name to avoid detecting the wrong type. Some systems save build artifacts into associate file stores that do not preserve extensions, and then link to those using conventionally-named symbolic links, that are the arguments to `rustc` et al. If we canonicalize before testing the type, we resolve the symlink, the extension is lost and we might treat rlibs and rmetas as dylibs. The fix is to tntroduce a temporary to hold the canonicalized name, compare against the non-canonical name, and add a comment explaining what's going on for the would-be mainter who sees a potential cleanup. Signed-off-by: Dan Cross <[email protected]>
2 parents d7dcae0 + 6ad6d8c commit d6ff46c

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/librustc_metadata/locator.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -685,13 +685,19 @@ impl<'a> CrateLocator<'a> {
685685
&& file.ends_with(&self.target.options.dll_suffix)
686686
{
687687
// Make sure there's at most one rlib and at most one dylib.
688-
let loc = fs::canonicalize(&loc).unwrap_or_else(|_| loc.clone());
688+
// Note to take care and match against the non-canonicalized name:
689+
// some systems save build artifacts into content-addressed stores
690+
// that do not preserve extensions, and then link to them using
691+
// e.g. symbolic links. If we canonicalize too early, we resolve
692+
// the symlink, the file type is lost and we might treat rlibs and
693+
// rmetas as dylibs.
694+
let loc_canon = fs::canonicalize(&loc).unwrap_or_else(|_| loc.clone());
689695
if loc.file_name().unwrap().to_str().unwrap().ends_with(".rlib") {
690-
rlibs.insert(loc, PathKind::ExternFlag);
696+
rlibs.insert(loc_canon, PathKind::ExternFlag);
691697
} else if loc.file_name().unwrap().to_str().unwrap().ends_with(".rmeta") {
692-
rmetas.insert(loc, PathKind::ExternFlag);
698+
rmetas.insert(loc_canon, PathKind::ExternFlag);
693699
} else {
694-
dylibs.insert(loc, PathKind::ExternFlag);
700+
dylibs.insert(loc_canon, PathKind::ExternFlag);
695701
}
696702
} else {
697703
self.rejected_via_filename

0 commit comments

Comments
 (0)