Skip to content

Commit 1c6b4d5

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 10deeae commit 1c6b4d5

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/bootstrap/compile.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,6 +1130,7 @@ pub fn run_cargo(builder: &Builder<'_>,
11301130
// Skip files like executables
11311131
if !filename.ends_with(".rlib") &&
11321132
!filename.ends_with(".lib") &&
1133+
!filename.ends_with(".a") &&
11331134
!is_dylib(&filename) &&
11341135
!(is_check && filename.ends_with(".rmeta")) {
11351136
continue;

src/librustc_codegen_ssa/back/linker.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,26 @@ 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+
// The output filename already contains `dll_suffix` so
373+
// the resulting import library will have a name in the
374+
// form of libfoo.dll.a
375+
let implib_name = out_filename
376+
.file_name()
377+
.and_then(|file| file.to_str())
378+
.map(|file| format!("{}{}{}",
379+
self.sess.target.target.options.staticlib_prefix,
380+
file,
381+
self.sess.target.target.options.staticlib_suffix));
382+
if let Some(implib_name) = implib_name {
383+
let implib = out_filename
384+
.parent()
385+
.map(|dir| dir.join(&implib_name));
386+
if let Some(implib) = implib {
387+
self.linker_arg(&format!("--out-implib,{}", (*implib).to_str().unwrap()));
388+
}
389+
}
390+
}
371391
}
372392
}
373393

0 commit comments

Comments
 (0)