Skip to content

Commit cb823b0

Browse files
committed
Search for libfoo.a on windows as well as foo.lib
Turns out LLVM only builds libfoo.a libraries, so we're going to need this logic to statically link librustc
1 parent 18084be commit cb823b0

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

Diff for: src/librustc/back/archive.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -119,18 +119,25 @@ impl Archive {
119119
}
120120

121121
fn find_library(&self, name: &str) -> Path {
122-
let (prefix, ext) = match self.sess.targ_cfg.os {
122+
let (osprefix, osext) = match self.sess.targ_cfg.os {
123123
abi::OsWin32 => ("", "lib"), _ => ("lib", "a"),
124124
};
125-
let libname = format!("{}{}.{}", prefix, name, ext);
125+
// On windows, static libraries sometimes show up as libfoo.a and other
126+
// times show up as foo.lib
127+
let oslibname = format!("{}{}.{}", osprefix, name, osext);
128+
let unixlibname = format!("lib{}.a", name);
126129

127130
let mut rustpath = filesearch::rust_path();
128131
rustpath.push(self.sess.filesearch.get_target_lib_path());
129132
let path = self.sess.opts.addl_lib_search_paths.iter();
130133
for path in path.chain(rustpath.iter()) {
131134
debug!("looking for {} inside {}", name, path.display());
132-
let test = path.join(libname.clone());
135+
let test = path.join(oslibname.as_slice());
133136
if test.exists() { return test }
137+
if oslibname != unixlibname {
138+
let test = path.join(unixlibname.as_slice());
139+
if test.exists() { return test }
140+
}
134141
}
135142
self.sess.fatal(format!("could not find native static library `{}`, \
136143
perhaps an -L flag is missing?", name));

0 commit comments

Comments
 (0)