2021-03-08 12:42:54 -08:00
|
|
|
use rustc_data_structures::temp_dir::MaybeTempDir;
|
2020-11-14 03:02:03 +01:00
|
|
|
use rustc_session::cstore::DllImport;
|
2020-03-11 12:49:08 +01:00
|
|
|
use rustc_session::Session;
|
2018-10-23 17:01:35 +02:00
|
|
|
|
2019-03-30 12:59:40 +01:00
|
|
|
use std::io;
|
|
|
|
|
use std::path::{Path, PathBuf};
|
2018-10-23 17:01:35 +02:00
|
|
|
|
2021-09-01 14:38:37 +02:00
|
|
|
pub(super) fn find_library(
|
2022-06-28 17:47:33 +00:00
|
|
|
name: &str,
|
2021-03-24 21:45:09 -07:00
|
|
|
verbatim: bool,
|
|
|
|
|
search_paths: &[PathBuf],
|
|
|
|
|
sess: &Session,
|
|
|
|
|
) -> PathBuf {
|
2018-10-23 17:01:35 +02:00
|
|
|
// On Windows, static libraries sometimes show up as libfoo.a and other
|
|
|
|
|
// times show up as foo.lib
|
2021-03-24 21:45:09 -07:00
|
|
|
let oslibname = if verbatim {
|
|
|
|
|
name.to_string()
|
|
|
|
|
} else {
|
|
|
|
|
format!("{}{}{}", sess.target.staticlib_prefix, name, sess.target.staticlib_suffix)
|
|
|
|
|
};
|
2018-10-23 17:01:35 +02: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 17:42:04 -05:00
|
|
|
if test.exists() {
|
|
|
|
|
return test;
|
|
|
|
|
}
|
2018-10-23 17:01:35 +02:00
|
|
|
if oslibname != unixlibname {
|
|
|
|
|
let test = path.join(&unixlibname);
|
2019-12-22 17:42:04 -05:00
|
|
|
if test.exists() {
|
|
|
|
|
return test;
|
|
|
|
|
}
|
2018-10-23 17:01:35 +02:00
|
|
|
}
|
|
|
|
|
}
|
2019-12-22 17:42:04 -05:00
|
|
|
sess.fatal(&format!(
|
|
|
|
|
"could not find native static library `{}`, \
|
|
|
|
|
perhaps an -L flag is missing?",
|
|
|
|
|
name
|
|
|
|
|
));
|
2018-10-23 17:01:35 +02:00
|
|
|
}
|
2019-03-30 12:59:40 +01:00
|
|
|
|
|
|
|
|
pub trait ArchiveBuilder<'a> {
|
2022-06-14 15:16:51 +00:00
|
|
|
fn new(sess: &'a Session, output: &Path) -> Self;
|
2019-03-30 12:59:40 +01:00
|
|
|
|
|
|
|
|
fn add_file(&mut self, path: &Path);
|
|
|
|
|
|
2021-09-01 14:38:37 +02:00
|
|
|
fn add_archive<F>(&mut self, archive: &Path, skip: F) -> io::Result<()>
|
|
|
|
|
where
|
|
|
|
|
F: FnMut(&str) -> bool + 'static;
|
2019-03-30 12:59:40 +01:00
|
|
|
|
2022-06-18 17:55:24 +00:00
|
|
|
fn build(self) -> bool;
|
2021-03-08 12:42:54 -08:00
|
|
|
|
|
|
|
|
fn inject_dll_import_lib(
|
|
|
|
|
&mut self,
|
|
|
|
|
lib_name: &str,
|
|
|
|
|
dll_imports: &[DllImport],
|
|
|
|
|
tmpdir: &MaybeTempDir,
|
|
|
|
|
);
|
2019-03-30 12:59:40 +01:00
|
|
|
}
|