Skip to content

Commit 03f23c1

Browse files
committed
linker: Fix Rust dylib crate extension on windows-msvc
1 parent 1b8e871 commit 03f23c1

File tree

1 file changed

+5
-1
lines changed
  • compiler/rustc_codegen_ssa/src/back

1 file changed

+5
-1
lines changed

compiler/rustc_codegen_ssa/src/back/link.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -2866,7 +2866,11 @@ fn add_dynamic_crate(cmd: &mut dyn Linker, sess: &Session, cratepath: &Path) {
28662866
if let Some(dir) = parent {
28672867
cmd.include_path(&rehome_sysroot_lib_dir(sess, dir));
28682868
}
2869-
let stem = cratepath.file_stem().unwrap().to_str().unwrap();
2869+
// "<dir>/name.dll -> name.dll" on windows-msvc
2870+
// "<dir>/name.dll -> name" on windows-gnu
2871+
// "<dir>/libname.<ext> -> name" elsewhere
2872+
let stem = if sess.target.is_like_msvc { cratepath.file_name() } else { cratepath.file_stem() };
2873+
let stem = stem.unwrap().to_str().unwrap();
28702874
// Convert library file-stem into a cc -l argument.
28712875
let prefix = if stem.starts_with("lib") && !sess.target.is_like_windows { 3 } else { 0 };
28722876
cmd.link_dylib_by_name(&stem[prefix..], false, true);

0 commit comments

Comments
 (0)