2020-03-11 11:49:08 +00:00
|
|
|
use rustc_session::Session;
|
2020-01-01 18:30:57 +00:00
|
|
|
use rustc_span::symbol::Symbol;
|
2018-10-23 15:01:35 +00:00
|
|
|
|
2019-03-30 11:59:40 +00:00
|
|
|
use std::io;
|
|
|
|
use std::path::{Path, PathBuf};
|
2018-10-23 15:01:35 +00:00
|
|
|
|
2019-12-22 22:42:04 +00:00
|
|
|
pub fn find_library(name: Symbol, search_paths: &[PathBuf], sess: &Session) -> PathBuf {
|
2018-10-23 15:01:35 +00:00
|
|
|
// On Windows, static libraries sometimes show up as libfoo.a and other
|
|
|
|
// times show up as foo.lib
|
2020-11-08 11:27:51 +00:00
|
|
|
let oslibname =
|
|
|
|
format!("{}{}{}", sess.target.staticlib_prefix, name, sess.target.staticlib_suffix);
|
2018-10-23 15:01:35 +00:00
|
|
|
let unixlibname = format!("lib{}.a", name);
|
|
|
|
|
|
|
|
for path in search_paths {
|
|
|
|
debug!("looking for {} inside {:?}", name, path);
|
|
|
|
let test = path.join(&oslibname);
|
2019-12-22 22:42:04 +00:00
|
|
|
if test.exists() {
|
|
|
|
return test;
|
|
|
|
}
|
2018-10-23 15:01:35 +00:00
|
|
|
if oslibname != unixlibname {
|
|
|
|
let test = path.join(&unixlibname);
|
2019-12-22 22:42:04 +00:00
|
|
|
if test.exists() {
|
|
|
|
return test;
|
|
|
|
}
|
2018-10-23 15:01:35 +00:00
|
|
|
}
|
|
|
|
}
|
2019-12-22 22:42:04 +00:00
|
|
|
sess.fatal(&format!(
|
|
|
|
"could not find native static library `{}`, \
|
|
|
|
perhaps an -L flag is missing?",
|
|
|
|
name
|
|
|
|
));
|
2018-10-23 15:01:35 +00:00
|
|
|
}
|
2019-03-30 11:59:40 +00:00
|
|
|
|
|
|
|
pub trait ArchiveBuilder<'a> {
|
|
|
|
fn new(sess: &'a Session, output: &Path, input: Option<&Path>) -> Self;
|
|
|
|
|
|
|
|
fn add_file(&mut self, path: &Path);
|
|
|
|
fn remove_file(&mut self, name: &str);
|
|
|
|
fn src_files(&mut self) -> Vec<String>;
|
|
|
|
|
2019-03-30 15:16:25 +00:00
|
|
|
fn add_rlib(
|
|
|
|
&mut self,
|
|
|
|
path: &Path,
|
|
|
|
name: &str,
|
|
|
|
lto: bool,
|
|
|
|
skip_objects: bool,
|
|
|
|
) -> io::Result<()>;
|
2019-09-05 01:23:45 +00:00
|
|
|
fn add_native_library(&mut self, name: Symbol);
|
2019-03-30 11:59:40 +00:00
|
|
|
fn update_symbols(&mut self);
|
|
|
|
|
|
|
|
fn build(self);
|
|
|
|
}
|