]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_codegen_ssa/src/back/archive.rs
Auto merge of #83738 - jyn514:only-load-some-crates, r=petrochenkov
[rust.git] / compiler / rustc_codegen_ssa / src / back / archive.rs
1 use rustc_session::Session;
2 use rustc_span::symbol::Symbol;
3
4 use std::io;
5 use std::path::{Path, PathBuf};
6
7 pub fn find_library(name: Symbol, search_paths: &[PathBuf], sess: &Session) -> PathBuf {
8     // On Windows, static libraries sometimes show up as libfoo.a and other
9     // times show up as foo.lib
10     let oslibname =
11         format!("{}{}{}", sess.target.staticlib_prefix, name, sess.target.staticlib_suffix);
12     let unixlibname = format!("lib{}.a", name);
13
14     for path in search_paths {
15         debug!("looking for {} inside {:?}", name, path);
16         let test = path.join(&oslibname);
17         if test.exists() {
18             return test;
19         }
20         if oslibname != unixlibname {
21             let test = path.join(&unixlibname);
22             if test.exists() {
23                 return test;
24             }
25         }
26     }
27     sess.fatal(&format!(
28         "could not find native static library `{}`, \
29                          perhaps an -L flag is missing?",
30         name
31     ));
32 }
33
34 pub trait ArchiveBuilder<'a> {
35     fn new(sess: &'a Session, output: &Path, input: Option<&Path>) -> Self;
36
37     fn add_file(&mut self, path: &Path);
38     fn remove_file(&mut self, name: &str);
39     fn src_files(&mut self) -> Vec<String>;
40
41     fn add_rlib(
42         &mut self,
43         path: &Path,
44         name: &str,
45         lto: bool,
46         skip_objects: bool,
47     ) -> io::Result<()>;
48     fn add_native_library(&mut self, name: Symbol);
49     fn update_symbols(&mut self);
50
51     fn build(self);
52 }