@@ -2682,27 +2682,27 @@ fn add_upstream_native_libraries(
2682
2682
}
2683
2683
}
2684
2684
2685
- // Rehome sysroot lib paths to be relative to the sysroot, which may be a relative
2686
- // path specified by the user. If the sysroot is a relative path, and the sysroot rlibs
2687
- // are specified as an absolute path, the linker command line can be non-deterministic
2688
- // due to the paths including the current working directory. The linker command line
2689
- // needs to be deterministic since it appears inside the PDB file generated by the MSVC
2690
- // linker. See https://github.com/rust-lang/rust/issues/112586.
2691
- fn rehome_sysroot_rlib_path < ' a > ( sess : & ' a Session , rlib_path : PathBuf ) -> PathBuf {
2685
+ // Rehome lib paths (which exclude the library file name) that point into the sysroot lib directory
2686
+ // to be relative to the sysroot directory, which may be a relative path specified by the user.
2687
+ //
2688
+ // If the sysroot is a relative path, and the sysroot libs are specified as an absolute path, the
2689
+ // linker command line can be non-deterministic due to the paths including the current working
2690
+ // directory. The linker command line needs to be deterministic since it appears inside the PDB
2691
+ // file generated by the MSVC linker. See https://github.com/rust-lang/rust/issues/112586.
2692
+ //
2693
+ // The returned path will always have `fix_windows_verbatim_for_gcc()` applied to it.
2694
+ fn rehome_sysroot_lib_dir < ' a > ( sess : & ' a Session , lib_dir : & Path ) -> PathBuf {
2692
2695
let sysroot_lib_path = sess. target_filesearch ( PathKind :: All ) . get_lib_path ( ) ;
2693
2696
let canonical_sysroot_lib_path =
2694
2697
{ try_canonicalize ( & sysroot_lib_path) . unwrap_or_else ( |_| sysroot_lib_path. clone ( ) ) } ;
2695
2698
2696
- let mut canonical_rlib_dir = try_canonicalize ( & rlib_path) . unwrap_or_else ( |_| rlib_path. clone ( ) ) ;
2697
- canonical_rlib_dir. pop ( ) ;
2698
-
2699
- if canonical_rlib_dir == canonical_sysroot_lib_path {
2700
- // The `susroot_lib_path` returned by `target_filesearch().get_lib_path()` has
2699
+ let canonical_lib_dir = try_canonicalize ( lib_dir) . unwrap_or_else ( |_| lib_dir. to_path_buf ( ) ) ;
2700
+ if canonical_lib_dir == canonical_sysroot_lib_path {
2701
+ // This path, returned by `target_filesearch().get_lib_path()`, has
2701
2702
// already had `fix_windows_verbatim_for_gcc()` applied if needed.
2702
2703
sysroot_lib_path
2703
- . join ( rlib_path. file_name ( ) . expect ( "rlib path has no file name path component" ) )
2704
2704
} else {
2705
- rlib_path
2705
+ fix_windows_verbatim_for_gcc ( & lib_dir )
2706
2706
}
2707
2707
}
2708
2708
@@ -2737,7 +2737,13 @@ fn add_static_crate<'a>(
2737
2737
let cratepath = & src. rlib . as_ref ( ) . unwrap ( ) . 0 ;
2738
2738
2739
2739
let mut link_upstream = |path : & Path | {
2740
- cmd. link_rlib ( & rehome_sysroot_rlib_path ( sess, fix_windows_verbatim_for_gcc ( path) ) ) ;
2740
+ let rlib_path = if let Some ( dir) = path. parent ( ) {
2741
+ let file_name = path. file_name ( ) . expect ( "rlib path has no file name path component" ) ;
2742
+ rehome_sysroot_lib_dir ( sess, & dir) . join ( file_name)
2743
+ } else {
2744
+ fix_windows_verbatim_for_gcc ( path)
2745
+ } ;
2746
+ cmd. link_rlib ( & rlib_path) ;
2741
2747
} ;
2742
2748
2743
2749
if !are_upstream_rust_objects_already_included ( sess)
@@ -2806,7 +2812,7 @@ fn add_dynamic_crate(cmd: &mut dyn Linker, sess: &Session, cratepath: &Path) {
2806
2812
// what its name is
2807
2813
let parent = cratepath. parent ( ) ;
2808
2814
if let Some ( dir) = parent {
2809
- cmd. include_path ( & fix_windows_verbatim_for_gcc ( dir) ) ;
2815
+ cmd. include_path ( & rehome_sysroot_lib_dir ( sess , dir) ) ;
2810
2816
}
2811
2817
let stem = cratepath. file_stem ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) ;
2812
2818
// Convert library file-stem into a cc -l argument.
0 commit comments