Skip to content

Commit

Permalink
Search for libfoo.a on windows as well as foo.lib
Browse files Browse the repository at this point in the history
Turns out LLVM only builds libfoo.a libraries, so we're going to need this logic
to statically link librustc
  • Loading branch information
alexcrichton committed Dec 3, 2013
1 parent 18084be commit cb823b0
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/librustc/back/archive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,18 +119,25 @@ impl Archive {
}

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

let mut rustpath = filesearch::rust_path();
rustpath.push(self.sess.filesearch.get_target_lib_path());
let path = self.sess.opts.addl_lib_search_paths.iter();
for path in path.chain(rustpath.iter()) {
debug!("looking for {} inside {}", name, path.display());
let test = path.join(libname.clone());
let test = path.join(oslibname.as_slice());
if test.exists() { return test }
if oslibname != unixlibname {
let test = path.join(unixlibname.as_slice());
if test.exists() { return test }
}
}
self.sess.fatal(format!("could not find native static library `{}`, \
perhaps an -L flag is missing?", name));
Expand Down

5 comments on commit cb823b0

@bors
Copy link
Contributor

@bors bors commented on cb823b0 Dec 4, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from pcwalton
at alexcrichton@cb823b0

@bors
Copy link
Contributor

@bors bors commented on cb823b0 Dec 4, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging alexcrichton/rust/omg-i-hate-windows = cb823b0 into auto

@bors
Copy link
Contributor

@bors bors commented on cb823b0 Dec 4, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alexcrichton/rust/omg-i-hate-windows = cb823b0 merged ok, testing candidate = c22f6d8

@bors
Copy link
Contributor

@bors bors commented on cb823b0 Dec 4, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on cb823b0 Dec 4, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = c22f6d8

Please sign in to comment.