about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2016-01-21 09:02:48 +0000
committerbors <bors@rust-lang.org>2016-01-21 09:02:48 +0000
commit34b4e66736a0fb65235feadbb5178d42bd09ed67 (patch)
tree487479d46139a4e47a566e02995bb485622147a1
parentd5ec3ab6851eefaf87ea2247c2ce373f1e905351 (diff)
parent1b0064ea60fcfd9c0a4f4aa88bb1943dc7c3850e (diff)
downloadrust-34b4e66736a0fb65235feadbb5178d42bd09ed67.tar.gz
rust-34b4e66736a0fb65235feadbb5178d42bd09ed67.zip
Auto merge of #29520 - retep998:staticlib-naming-fiasco, r=alexcrichton
I'm not sure if this was the best way to go about it, but it seems to work.

Fixes https://github.com/rust-lang/rust/issues/29508

r? @alexcrichton
-rw-r--r--src/librustc_metadata/loader.rs12
-rw-r--r--src/librustc_trans/back/link.rs5
-rw-r--r--src/librustc_trans/back/linker.rs11
-rw-r--r--src/test/run-make/c-link-to-rust-dylib/Makefile2
-rw-r--r--src/test/run-make/c-link-to-rust-staticlib/Makefile5
-rw-r--r--src/test/run-make/lto-smoke-c/Makefile2
-rw-r--r--src/test/run-make/output-type-permutations/Makefile8
-rw-r--r--src/test/run-make/static-dylib-by-default/Makefile2
8 files changed, 32 insertions, 15 deletions
diff --git a/src/librustc_metadata/loader.rs b/src/librustc_metadata/loader.rs
index 40665beaa5a..b0fb12b26b2 100644
--- a/src/librustc_metadata/loader.rs
+++ b/src/librustc_metadata/loader.rs
@@ -388,11 +388,12 @@ impl<'a> Context<'a> {
         }
 
         let dypair = self.dylibname();
+        let staticpair = self.staticlibname();
 
         // want: crate_name.dir_part() + prefix + crate_name.file_part + "-"
         let dylib_prefix = format!("{}{}", dypair.0, self.crate_name);
         let rlib_prefix = format!("lib{}", self.crate_name);
-        let staticlib_prefix = format!("lib{}", self.crate_name);
+        let staticlib_prefix = format!("{}{}", staticpair.0, self.crate_name);
 
         let mut candidates = HashMap::new();
         let mut staticlibs = vec!();
@@ -425,7 +426,7 @@ impl<'a> Context<'a> {
                  false)
             } else {
                 if file.starts_with(&staticlib_prefix[..]) &&
-                   file.ends_with(".a") {
+                   file.ends_with(&staticpair.1) {
                     staticlibs.push(CrateMismatch {
                         path: path.to_path_buf(),
                         got: "static".to_string()
@@ -644,6 +645,13 @@ impl<'a> Context<'a> {
         (t.options.dll_prefix.clone(), t.options.dll_suffix.clone())
     }
 
+    // Returns the corresponding (prefix, suffix) that files need to have for
+    // static libraries
+    fn staticlibname(&self) -> (String, String) {
+        let t = &self.target;
+        (t.options.staticlib_prefix.clone(), t.options.staticlib_suffix.clone())
+    }
+
     fn find_commandline_library(&mut self, locs: &[String]) -> Option<Library> {
         // First, filter out all libraries that look suspicious. We only accept
         // files which actually exist that have the correct naming scheme for
diff --git a/src/librustc_trans/back/link.rs b/src/librustc_trans/back/link.rs
index ec1383f1f7b..6aabf51a9ed 100644
--- a/src/librustc_trans/back/link.rs
+++ b/src/librustc_trans/back/link.rs
@@ -490,7 +490,10 @@ pub fn filename_for_input(sess: &Session,
                                                 suffix))
         }
         config::CrateTypeStaticlib => {
-            outputs.out_directory.join(&format!("lib{}.a", libname))
+            let (prefix, suffix) = (&sess.target.target.options.staticlib_prefix,
+                                    &sess.target.target.options.staticlib_suffix);
+            outputs.out_directory.join(&format!("{}{}{}", prefix, libname,
+                                                suffix))
         }
         config::CrateTypeExecutable => {
             let suffix = &sess.target.target.options.exe_suffix;
diff --git a/src/librustc_trans/back/linker.rs b/src/librustc_trans/back/linker.rs
index f585c65228a..9c445737b10 100644
--- a/src/librustc_trans/back/linker.rs
+++ b/src/librustc_trans/back/linker.rs
@@ -210,7 +210,14 @@ impl<'a> Linker for MsvcLinker<'a> {
     fn link_rlib(&mut self, lib: &Path) { self.cmd.arg(lib); }
     fn add_object(&mut self, path: &Path) { self.cmd.arg(path); }
     fn args(&mut self, args: &[String]) { self.cmd.args(args); }
-    fn build_dylib(&mut self, _out_filename: &Path) { self.cmd.arg("/DLL"); }
+
+    fn build_dylib(&mut self, out_filename: &Path) {
+        self.cmd.arg("/DLL");
+        let mut arg: OsString = "/IMPLIB:".into();
+        arg.push(out_filename.with_extension("dll.lib"));
+        self.cmd.arg(arg);
+    }
+
     fn gc_sections(&mut self, _is_dylib: bool) { self.cmd.arg("/OPT:REF,ICF"); }
 
     fn link_dylib(&mut self, lib: &str) {
@@ -222,7 +229,7 @@ impl<'a> Linker for MsvcLinker<'a> {
         // `foo.lib` file if the dll doesn't actually export any symbols, so we
         // check to see if the file is there and just omit linking to it if it's
         // not present.
-        let name = format!("{}.lib", lib);
+        let name = format!("{}.dll.lib", lib);
         if fs::metadata(&path.join(&name)).is_ok() {
             self.cmd.arg(name);
         }
diff --git a/src/test/run-make/c-link-to-rust-dylib/Makefile b/src/test/run-make/c-link-to-rust-dylib/Makefile
index 7b2130cd4ed..98e112a3744 100644
--- a/src/test/run-make/c-link-to-rust-dylib/Makefile
+++ b/src/test/run-make/c-link-to-rust-dylib/Makefile
@@ -7,7 +7,7 @@ all: $(TMPDIR)/$(call BIN,bar)
 
 ifdef IS_MSVC
 $(TMPDIR)/$(call BIN,bar): $(call DYLIB,foo)
-	$(CC) bar.c $(TMPDIR)/foo.lib $(call OUT_EXE,bar)
+	$(CC) bar.c $(TMPDIR)/foo.dll.lib $(call OUT_EXE,bar)
 else
 $(TMPDIR)/$(call BIN,bar): $(call DYLIB,foo)
 	$(CC) bar.c -lfoo -o $(call RUN_BINFILE,bar) -L $(TMPDIR)
diff --git a/src/test/run-make/c-link-to-rust-staticlib/Makefile b/src/test/run-make/c-link-to-rust-staticlib/Makefile
index 3d44b3c256e..47264e82165 100644
--- a/src/test/run-make/c-link-to-rust-staticlib/Makefile
+++ b/src/test/run-make/c-link-to-rust-staticlib/Makefile
@@ -4,11 +4,10 @@
 ifneq ($(shell uname),FreeBSD)
 all:
 	$(RUSTC) foo.rs
-	cp $(TMPDIR)/libfoo.a $(call NATIVE_STATICLIB,foo2)
-	$(CC) bar.c $(call NATIVE_STATICLIB,foo2) $(call OUT_EXE,bar) \
+	$(CC) bar.c $(call STATICLIB,foo) $(call OUT_EXE,bar) \
 		$(EXTRACFLAGS) $(EXTRACXXFLAGS)
 	$(call RUN,bar)
-	rm $(call STATICLIB,foo*)
+	rm $(call STATICLIB,foo)
 	$(call RUN,bar)
 
 else
diff --git a/src/test/run-make/lto-smoke-c/Makefile b/src/test/run-make/lto-smoke-c/Makefile
index 72c161abe91..0f61f5de938 100644
--- a/src/test/run-make/lto-smoke-c/Makefile
+++ b/src/test/run-make/lto-smoke-c/Makefile
@@ -5,7 +5,7 @@ CC := $(CC:-g=)
 
 all:
 	$(RUSTC) foo.rs -C lto
-	$(CC) bar.c $(TMPDIR)/libfoo.a \
+	$(CC) bar.c $(call STATICLIB,foo) \
 		$(call OUT_EXE,bar) \
 		$(EXTRACFLAGS) $(EXTRACXXFLAGS)
 	$(call RUN,bar)
diff --git a/src/test/run-make/output-type-permutations/Makefile b/src/test/run-make/output-type-permutations/Makefile
index 6cfa7043a2e..c2715027bc1 100644
--- a/src/test/run-make/output-type-permutations/Makefile
+++ b/src/test/run-make/output-type-permutations/Makefile
@@ -4,8 +4,8 @@ all:
 	$(RUSTC) foo.rs --crate-type=rlib,dylib,staticlib
 	$(call REMOVE_RLIBS,bar)
 	$(call REMOVE_DYLIBS,bar)
-	rm $(TMPDIR)/libbar.a
-	rm -f $(TMPDIR)/bar.{exp,lib,pdb}
+	rm $(call STATICLIB,bar)
+	rm -f $(TMPDIR)/bar.{dll.exp,dll.lib,pdb}
 	# Check that $(TMPDIR) is empty.
 	[ "$$(ls -1 $(TMPDIR) | wc -l)" -eq "0" ]
 
@@ -78,7 +78,7 @@ all:
 	rm $(TMPDIR)/$(call BIN,foo)
 	$(RUSTC) foo.rs --crate-type=dylib --emit=link=$(TMPDIR)/$(call BIN,foo)
 	rm $(TMPDIR)/$(call BIN,foo)
-	rm -f $(TMPDIR)/foo.{exp,lib,pdb}
+	rm -f $(TMPDIR)/foo.{dll.exp,dll.lib,pdb}
 	[ "$$(ls -1 $(TMPDIR) | wc -l)" -eq "0" ]
 
 	$(RUSTC) foo.rs --crate-type=staticlib -o $(TMPDIR)/foo
@@ -133,7 +133,7 @@ all:
 	rm $(TMPDIR)/bar.ll
 	rm $(TMPDIR)/bar.s
 	rm $(TMPDIR)/bar.o
-	rm $(TMPDIR)/libbar.a
+	rm $(call STATICLIB,bar)
 	mv $(TMPDIR)/bar.bc $(TMPDIR)/foo.bc
 	# Don't check that the $(TMPDIR) is empty - we left `foo.bc` for later
 	# comparison.
diff --git a/src/test/run-make/static-dylib-by-default/Makefile b/src/test/run-make/static-dylib-by-default/Makefile
index 8bd05dc201f..6409aa66ae0 100644
--- a/src/test/run-make/static-dylib-by-default/Makefile
+++ b/src/test/run-make/static-dylib-by-default/Makefile
@@ -2,7 +2,7 @@
 
 TO_LINK := $(call DYLIB,bar)
 ifdef IS_MSVC
-LINK_ARG = $(TO_LINK:dll=lib)
+LINK_ARG = $(TO_LINK:dll=dll.lib)
 else
 LINK_ARG = $(TO_LINK)
 endif