Skip to content

Commit 2ded197

Browse files
committed
rustc: codegen: Build import library for all windows targets
So far it is assumed that using a DLL as a -l parameter argument is ok, but the assumption doesn't hold when compiling the native code with llvm. In which case, an import library is required, so let's build one This also requires the cargo counterpart to add the import library in the stamp files, at least when compiling libstd. Otherwise, the files don't get uplifted
1 parent 8bea2ba commit 2ded197

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/bootstrap/compile.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,6 +1108,7 @@ pub fn run_cargo(builder: &Builder<'_>,
11081108
// Skip files like executables
11091109
if !filename.ends_with(".rlib") &&
11101110
!filename.ends_with(".lib") &&
1111+
!filename.ends_with(".a") &&
11111112
!is_dylib(&filename) &&
11121113
!(is_check && filename.ends_with(".rmeta")) {
11131114
continue;

src/librustc_codegen_ssa/back/linker.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,23 @@ impl<'a> Linker for GccLinker<'a> {
368368
}
369369
} else {
370370
self.cmd.arg("-shared");
371+
if self.sess.target.target.options.is_like_windows {
372+
let implib_name = out_filename
373+
.file_name()
374+
.and_then(|file| file.to_str())
375+
.map(|file| format!("{}{}{}",
376+
self.sess.target.target.options.staticlib_prefix,
377+
file,
378+
self.sess.target.target.options.staticlib_suffix));
379+
if let Some(implib_name) = implib_name {
380+
let implib = out_filename
381+
.parent()
382+
.map(|dir| dir.join(&implib_name));
383+
if let Some(implib) = implib {
384+
self.linker_arg(&format!("--out-implib,{}", (*implib).to_str().unwrap()));
385+
}
386+
}
387+
}
371388
}
372389
}
373390

0 commit comments

Comments
 (0)