Skip to content

Commit 34b4e66

Browse files
committed
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 #29508 r? @alexcrichton
2 parents d5ec3ab + 1b0064e commit 34b4e66

File tree

8 files changed

+32
-15
lines changed

8 files changed

+32
-15
lines changed

src/librustc_metadata/loader.rs

+10-2
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

+4-1
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

+9-2
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
}

src/test/run-make/c-link-to-rust-dylib/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ all: $(TMPDIR)/$(call BIN,bar)
77

88
ifdef IS_MSVC
99
$(TMPDIR)/$(call BIN,bar): $(call DYLIB,foo)
10-
$(CC) bar.c $(TMPDIR)/foo.lib $(call OUT_EXE,bar)
10+
$(CC) bar.c $(TMPDIR)/foo.dll.lib $(call OUT_EXE,bar)
1111
else
1212
$(TMPDIR)/$(call BIN,bar): $(call DYLIB,foo)
1313
$(CC) bar.c -lfoo -o $(call RUN_BINFILE,bar) -L $(TMPDIR)

src/test/run-make/c-link-to-rust-staticlib/Makefile

+2-3
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@
44
ifneq ($(shell uname),FreeBSD)
55
all:
66
$(RUSTC) foo.rs
7-
cp $(TMPDIR)/libfoo.a $(call NATIVE_STATICLIB,foo2)
8-
$(CC) bar.c $(call NATIVE_STATICLIB,foo2) $(call OUT_EXE,bar) \
7+
$(CC) bar.c $(call STATICLIB,foo) $(call OUT_EXE,bar) \
98
$(EXTRACFLAGS) $(EXTRACXXFLAGS)
109
$(call RUN,bar)
11-
rm $(call STATICLIB,foo*)
10+
rm $(call STATICLIB,foo)
1211
$(call RUN,bar)
1312

1413
else

src/test/run-make/lto-smoke-c/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ CC := $(CC:-g=)
55

66
all:
77
$(RUSTC) foo.rs -C lto
8-
$(CC) bar.c $(TMPDIR)/libfoo.a \
8+
$(CC) bar.c $(call STATICLIB,foo) \
99
$(call OUT_EXE,bar) \
1010
$(EXTRACFLAGS) $(EXTRACXXFLAGS)
1111
$(call RUN,bar)

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ all:
44
$(RUSTC) foo.rs --crate-type=rlib,dylib,staticlib
55
$(call REMOVE_RLIBS,bar)
66
$(call REMOVE_DYLIBS,bar)
7-
rm $(TMPDIR)/libbar.a
8-
rm -f $(TMPDIR)/bar.{exp,lib,pdb}
7+
rm $(call STATICLIB,bar)
8+
rm -f $(TMPDIR)/bar.{dll.exp,dll.lib,pdb}
99
# Check that $(TMPDIR) is empty.
1010
[ "$$(ls -1 $(TMPDIR) | wc -l)" -eq "0" ]
1111

@@ -78,7 +78,7 @@ 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.{exp,lib,pdb}
81+
rm -f $(TMPDIR)/foo.{dll.exp,dll.lib,pdb}
8282
[ "$$(ls -1 $(TMPDIR) | wc -l)" -eq "0" ]
8383

8484
$(RUSTC) foo.rs --crate-type=staticlib -o $(TMPDIR)/foo
@@ -133,7 +133,7 @@ all:
133133
rm $(TMPDIR)/bar.ll
134134
rm $(TMPDIR)/bar.s
135135
rm $(TMPDIR)/bar.o
136-
rm $(TMPDIR)/libbar.a
136+
rm $(call STATICLIB,bar)
137137
mv $(TMPDIR)/bar.bc $(TMPDIR)/foo.bc
138138
# Don't check that the $(TMPDIR) is empty - we left `foo.bc` for later
139139
# comparison.

src/test/run-make/static-dylib-by-default/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
TO_LINK := $(call DYLIB,bar)
44
ifdef IS_MSVC
5-
LINK_ARG = $(TO_LINK:dll=lib)
5+
LINK_ARG = $(TO_LINK:dll=dll.lib)
66
else
77
LINK_ARG = $(TO_LINK)
88
endif

0 commit comments

Comments
 (0)