Remap dylib paths into the sysroot to be relative to the sysroot
Like for rlibs, the paths on the linker command line need to be relative paths if the sysroot was specified by the user to be a relative path. Dylibs put the path in /LIBPATH instead of into the file path of the library itself, so we rehome the libpath and adjust the rehoming function to be able to support both use cases, rlibs and dylibs.
This commit is contained in:
parent
4b83156a5c
commit
c340325ebf
@ -2682,27 +2682,27 @@ fn add_upstream_native_libraries(
|
||||
}
|
||||
}
|
||||
|
||||
// Rehome sysroot lib paths to be relative to the sysroot, which may be a relative
|
||||
// path specified by the user. If the sysroot is a relative path, and the sysroot rlibs
|
||||
// are specified as an absolute path, the linker command line can be non-deterministic
|
||||
// due to the paths including the current working directory. The linker command line
|
||||
// needs to be deterministic since it appears inside the PDB file generated by the MSVC
|
||||
// linker. See https://github.com/rust-lang/rust/issues/112586.
|
||||
fn rehome_sysroot_rlib_path<'a>(sess: &'a Session, rlib_path: PathBuf) -> PathBuf {
|
||||
// Rehome lib paths (which exclude the library file name) that point into the sysroot lib directory
|
||||
// to be relative to the sysroot directory, which may be a relative path specified by the user.
|
||||
//
|
||||
// If the sysroot is a relative path, and the sysroot libs are specified as an absolute path, the
|
||||
// linker command line can be non-deterministic due to the paths including the current working
|
||||
// directory. The linker command line needs to be deterministic since it appears inside the PDB
|
||||
// file generated by the MSVC linker. See https://github.com/rust-lang/rust/issues/112586.
|
||||
//
|
||||
// The returned path will always have `fix_windows_verbatim_for_gcc()` applied to it.
|
||||
fn rehome_sysroot_lib_dir<'a>(sess: &'a Session, lib_dir: &Path) -> PathBuf {
|
||||
let sysroot_lib_path = sess.target_filesearch(PathKind::All).get_lib_path();
|
||||
let canonical_sysroot_lib_path =
|
||||
{ try_canonicalize(&sysroot_lib_path).unwrap_or_else(|_| sysroot_lib_path.clone()) };
|
||||
|
||||
let mut canonical_rlib_dir = try_canonicalize(&rlib_path).unwrap_or_else(|_| rlib_path.clone());
|
||||
canonical_rlib_dir.pop();
|
||||
|
||||
if canonical_rlib_dir == canonical_sysroot_lib_path {
|
||||
// The `susroot_lib_path` returned by `target_filesearch().get_lib_path()` has
|
||||
let canonical_lib_dir = try_canonicalize(lib_dir).unwrap_or_else(|_| lib_dir.to_path_buf());
|
||||
if canonical_lib_dir == canonical_sysroot_lib_path {
|
||||
// This path, returned by `target_filesearch().get_lib_path()`, has
|
||||
// already had `fix_windows_verbatim_for_gcc()` applied if needed.
|
||||
sysroot_lib_path
|
||||
.join(rlib_path.file_name().expect("rlib path has no file name path component"))
|
||||
} else {
|
||||
rlib_path
|
||||
fix_windows_verbatim_for_gcc(&lib_dir)
|
||||
}
|
||||
}
|
||||
|
||||
@ -2737,7 +2737,13 @@ fn add_static_crate<'a>(
|
||||
let cratepath = &src.rlib.as_ref().unwrap().0;
|
||||
|
||||
let mut link_upstream = |path: &Path| {
|
||||
cmd.link_rlib(&rehome_sysroot_rlib_path(sess, fix_windows_verbatim_for_gcc(path)));
|
||||
let rlib_path = if let Some(dir) = path.parent() {
|
||||
let file_name = path.file_name().expect("rlib path has no file name path component");
|
||||
rehome_sysroot_lib_dir(sess, &dir).join(file_name)
|
||||
} else {
|
||||
fix_windows_verbatim_for_gcc(path)
|
||||
};
|
||||
cmd.link_rlib(&rlib_path);
|
||||
};
|
||||
|
||||
if !are_upstream_rust_objects_already_included(sess)
|
||||
@ -2806,7 +2812,7 @@ fn add_dynamic_crate(cmd: &mut dyn Linker, sess: &Session, cratepath: &Path) {
|
||||
// what its name is
|
||||
let parent = cratepath.parent();
|
||||
if let Some(dir) = parent {
|
||||
cmd.include_path(&fix_windows_verbatim_for_gcc(dir));
|
||||
cmd.include_path(&rehome_sysroot_lib_dir(sess, dir));
|
||||
}
|
||||
let stem = cratepath.file_stem().unwrap().to_str().unwrap();
|
||||
// Convert library file-stem into a cc -l argument.
|
||||
|
Loading…
x
Reference in New Issue
Block a user