Skip to content

Commit 06c66d6

Browse files
committed
Change name when outputting staticlibs on Windows
libfoo.a -> foo.lib In order to not cause conflicts, changes the DLL import library name foo.lib -> foo.dll.lib Fixes rust-lang#29508 Because this changes output filenames this is a [breaking-change] Signed-off-by: Peter Atashian <[email protected]>
1 parent dda25f2 commit 06c66d6

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

src/librustc_metadata/loader.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,11 +388,12 @@ impl<'a> Context<'a> {
388388
}
389389

390390
let dypair = self.dylibname();
391+
let staticpair = self.staticlibname();
391392

392393
// want: crate_name.dir_part() + prefix + crate_name.file_part + "-"
393394
let dylib_prefix = format!("{}{}", dypair.0, self.crate_name);
394395
let rlib_prefix = format!("lib{}", self.crate_name);
395-
let staticlib_prefix = format!("lib{}", self.crate_name);
396+
let staticlib_prefix = format!("{}{}", staticpair.0, self.crate_name);
396397

397398
let mut candidates = HashMap::new();
398399
let mut staticlibs = vec!();
@@ -425,7 +426,7 @@ impl<'a> Context<'a> {
425426
false)
426427
} else {
427428
if file.starts_with(&staticlib_prefix[..]) &&
428-
file.ends_with(".a") {
429+
file.ends_with(&staticpair.1) {
429430
staticlibs.push(CrateMismatch {
430431
path: path.to_path_buf(),
431432
got: "static".to_string()
@@ -644,6 +645,13 @@ impl<'a> Context<'a> {
644645
(t.options.dll_prefix.clone(), t.options.dll_suffix.clone())
645646
}
646647

648+
// Returns the corresponding (prefix, suffix) that files need to have for
649+
// static libraries
650+
fn staticlibname(&self) -> (String, String) {
651+
let t = &self.target;
652+
(t.options.staticlib_prefix.clone(), t.options.staticlib_suffix.clone())
653+
}
654+
647655
fn find_commandline_library(&mut self, locs: &[String]) -> Option<Library> {
648656
// First, filter out all libraries that look suspicious. We only accept
649657
// files which actually exist that have the correct naming scheme for

src/librustc_trans/back/link.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,10 @@ pub fn filename_for_input(sess: &Session,
490490
suffix))
491491
}
492492
config::CrateTypeStaticlib => {
493-
outputs.out_directory.join(&format!("lib{}.a", libname))
493+
let (prefix, suffix) = (&sess.target.target.options.staticlib_prefix,
494+
&sess.target.target.options.staticlib_suffix);
495+
outputs.out_directory.join(&format!("{}{}{}", prefix, libname,
496+
suffix))
494497
}
495498
config::CrateTypeExecutable => {
496499
let suffix = &sess.target.target.options.exe_suffix;

src/librustc_trans/back/linker.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,14 @@ impl<'a> Linker for MsvcLinker<'a> {
210210
fn link_rlib(&mut self, lib: &Path) { self.cmd.arg(lib); }
211211
fn add_object(&mut self, path: &Path) { self.cmd.arg(path); }
212212
fn args(&mut self, args: &[String]) { self.cmd.args(args); }
213-
fn build_dylib(&mut self, _out_filename: &Path) { self.cmd.arg("/DLL"); }
213+
214+
fn build_dylib(&mut self, out_filename: &Path) {
215+
self.cmd.arg("/DLL");
216+
let mut arg: OsString = "/IMPLIB:".into();
217+
arg.push(out_filename.with_extension("dll.lib"));
218+
self.cmd.arg(arg);
219+
}
220+
214221
fn gc_sections(&mut self, _is_dylib: bool) { self.cmd.arg("/OPT:REF,ICF"); }
215222

216223
fn link_dylib(&mut self, lib: &str) {
@@ -222,7 +229,7 @@ impl<'a> Linker for MsvcLinker<'a> {
222229
// `foo.lib` file if the dll doesn't actually export any symbols, so we
223230
// check to see if the file is there and just omit linking to it if it's
224231
// not present.
225-
let name = format!("{}.lib", lib);
232+
let name = format!("{}.dll.lib", lib);
226233
if fs::metadata(&path.join(&name)).is_ok() {
227234
self.cmd.arg(name);
228235
}

0 commit comments

Comments
 (0)