]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_codegen_ssa/src/back/archive.rs
Move `{core,std}::stream::Stream` to `{core,std}::async_iter::AsyncIterator`.
[rust.git] / compiler / rustc_codegen_ssa / src / back / archive.rs
1 use rustc_data_structures::temp_dir::MaybeTempDir;
2 use rustc_session::cstore::DllImport;
3 use rustc_session::Session;
4 use rustc_span::symbol::Symbol;
5
6 use std::io;
7 use std::path::{Path, PathBuf};
8
9 pub(super) fn find_library(
10     name: Symbol,
11     verbatim: bool,
12     search_paths: &[PathBuf],
13     sess: &Session,
14 ) -> PathBuf {
15     // On Windows, static libraries sometimes show up as libfoo.a and other
16     // times show up as foo.lib
17     let oslibname = if verbatim {
18         name.to_string()
19     } else {
20         format!("{}{}{}", sess.target.staticlib_prefix, name, sess.target.staticlib_suffix)
21     };
22     let unixlibname = format!("lib{}.a", name);
23
24     for path in search_paths {
25         debug!("looking for {} inside {:?}", name, path);
26         let test = path.join(&oslibname);
27         if test.exists() {
28             return test;
29         }
30         if oslibname != unixlibname {
31             let test = path.join(&unixlibname);
32             if test.exists() {
33                 return test;
34             }
35         }
36     }
37     sess.fatal(&format!(
38         "could not find native static library `{}`, \
39                          perhaps an -L flag is missing?",
40         name
41     ));
42 }
43
44 pub trait ArchiveBuilder<'a> {
45     fn new(sess: &'a Session, output: &Path, input: Option<&Path>) -> Self;
46
47     fn add_file(&mut self, path: &Path);
48     fn remove_file(&mut self, name: &str);
49     fn src_files(&mut self) -> Vec<String>;
50
51     fn add_archive<F>(&mut self, archive: &Path, skip: F) -> io::Result<()>
52     where
53         F: FnMut(&str) -> bool + 'static;
54     fn update_symbols(&mut self);
55
56     fn build(self);
57
58     fn inject_dll_import_lib(
59         &mut self,
60         lib_name: &str,
61         dll_imports: &[DllImport],
62         tmpdir: &MaybeTempDir,
63     );
64 }