Skip to content

Commit 5af318b

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 eedf6ce commit 5af318b

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

src/bootstrap/compile.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1126,6 +1126,7 @@ pub fn run_cargo(builder: &Builder<'_>,
11261126
// Skip files like executables
11271127
if !filename.ends_with(".rlib") &&
11281128
!filename.ends_with(".lib") &&
1129+
!filename.ends_with(".a") &&
11291130
!is_dylib(&filename) &&
11301131
!(is_check && filename.ends_with(".rmeta")) {
11311132
continue;

src/librustc_codegen_ssa/back/linker.rs

+20
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

src/test/run-make-fulldeps/output-type-permutations/Makefile

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ all:
55
$(call REMOVE_RLIBS,bar)
66
$(call REMOVE_DYLIBS,bar)
77
rm $(call STATICLIB,bar)
8-
rm -f $(TMPDIR)/bar.{dll.exp,dll.lib,pdb}
8+
rm -f $(TMPDIR)/{lib,}bar.{dll.exp,dll.lib,pdb,dll.a}
99
# Check that $(TMPDIR) is empty.
1010
[ "$$(ls -1 $(TMPDIR) | wc -l)" -eq "0" ]
1111

@@ -78,8 +78,8 @@ all:
7878
rm $(TMPDIR)/$(call BIN,foo)
7979
$(RUSTC) foo.rs --crate-type=dylib --emit=link=$(TMPDIR)/$(call BIN,foo)
8080
rm $(TMPDIR)/$(call BIN,foo)
81-
rm -f $(TMPDIR)/foo.{dll.exp,dll.lib,pdb}
82-
[ "$$(ls -1 $(TMPDIR) | wc -l)" -eq "0" ]
81+
rm -f $(TMPDIR)/{lib,}foo.{dll.exp,dll.lib,pdb,dll.a,exe.lib}
82+
[ "$$(ls -1 $(TMPDIR) | wc -l)" -eq "0" ] || (ls -1 $(TMPDIR) && exit 1)
8383

8484
$(RUSTC) foo.rs --crate-type=staticlib -o $(TMPDIR)/foo
8585
rm $(TMPDIR)/foo

0 commit comments

Comments
 (0)