@@ -2816,6 +2816,15 @@ fn rehome_sysroot_lib_dir(sess: &Session, lib_dir: &Path) -> PathBuf {
2816
2816
}
2817
2817
}
2818
2818
2819
+ fn rehome_lib_path ( sess : & Session , path : & Path ) -> PathBuf {
2820
+ if let Some ( dir) = path. parent ( ) {
2821
+ let file_name = path. file_name ( ) . expect ( "library path has no file name component" ) ;
2822
+ rehome_sysroot_lib_dir ( sess, dir) . join ( file_name)
2823
+ } else {
2824
+ fix_windows_verbatim_for_gcc ( path)
2825
+ }
2826
+ }
2827
+
2819
2828
// Adds the static "rlib" versions of all crates to the command line.
2820
2829
// There's a bit of magic which happens here specifically related to LTO,
2821
2830
// namely that we remove upstream object files.
@@ -2847,12 +2856,7 @@ fn add_static_crate(
2847
2856
let cratepath = & src. rlib . as_ref ( ) . unwrap ( ) . 0 ;
2848
2857
2849
2858
let mut link_upstream = |path : & Path | {
2850
- let rlib_path = if let Some ( dir) = path. parent ( ) {
2851
- let file_name = path. file_name ( ) . expect ( "rlib path has no file name path component" ) ;
2852
- rehome_sysroot_lib_dir ( sess, dir) . join ( file_name)
2853
- } else {
2854
- fix_windows_verbatim_for_gcc ( path)
2855
- } ;
2859
+ let rlib_path = rehome_lib_path ( sess, path) ;
2856
2860
cmd. link_staticlib_by_path ( & rlib_path, false ) ;
2857
2861
} ;
2858
2862
@@ -2918,27 +2922,16 @@ fn add_static_crate(
2918
2922
2919
2923
// Same thing as above, but for dynamic crates instead of static crates.
2920
2924
fn add_dynamic_crate ( cmd : & mut dyn Linker , sess : & Session , cratepath : & Path ) {
2921
- // Just need to tell the linker about where the library lives and
2922
- // what its name is
2923
- let parent = cratepath. parent ( ) ;
2924
2925
// When producing a dll, the MSVC linker may not actually emit a
2925
2926
// `foo.lib` file if the dll doesn't actually export any symbols, so we
2926
2927
// check to see if the file is there and just omit linking to it if it's
2927
2928
// not present.
2928
2929
if sess. target . is_like_msvc && !cratepath. with_extension ( "dll.lib" ) . exists ( ) {
2929
2930
return ;
2930
2931
}
2931
- if let Some ( dir) = parent {
2932
- cmd. include_path ( & rehome_sysroot_lib_dir ( sess, dir) ) ;
2933
- }
2934
- // "<dir>/name.dll -> name.dll" on windows-msvc
2935
- // "<dir>/name.dll -> name" on windows-gnu
2936
- // "<dir>/libname.<ext> -> name" elsewhere
2937
- let stem = if sess. target . is_like_msvc { cratepath. file_name ( ) } else { cratepath. file_stem ( ) } ;
2938
- let stem = stem. unwrap ( ) . to_str ( ) . unwrap ( ) ;
2939
- // Convert library file-stem into a cc -l argument.
2940
- let prefix = if stem. starts_with ( "lib" ) && !sess. target . is_like_windows { 3 } else { 0 } ;
2941
- cmd. link_dylib_by_name ( & stem[ prefix..] , false , true ) ;
2932
+
2933
+ let dylib_path = rehome_lib_path ( sess, cratepath) ;
2934
+ cmd. link_dylib_by_path ( & dylib_path, true ) ;
2942
2935
}
2943
2936
2944
2937
fn relevant_lib ( sess : & Session , lib : & NativeLib ) -> bool {
0 commit comments