about summary refs log tree commit diff
path: root/compiler/rustc_codegen_ssa/src/back/archive.rs
blob: c477ac6462acb21420303dcf06eedccb3b3c9ec9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
use rustc_session::Session;
use rustc_span::symbol::Symbol;

use std::io;
use std::path::{Path, PathBuf};

pub fn find_library(name: Symbol, search_paths: &[PathBuf], sess: &Session) -> PathBuf {
    // On Windows, static libraries sometimes show up as libfoo.a and other
    // times show up as foo.lib
    let oslibname =
        format!("{}{}{}", sess.target.staticlib_prefix, name, sess.target.staticlib_suffix);
    let unixlibname = format!("lib{}.a", name);

    for path in search_paths {
        debug!("looking for {} inside {:?}", name, path);
        let test = path.join(&oslibname);
        if test.exists() {
            return test;
        }
        if oslibname != unixlibname {
            let test = path.join(&unixlibname);
            if test.exists() {
                return test;
            }
        }
    }
    sess.fatal(&format!(
        "could not find native static library `{}`, \
                         perhaps an -L flag is missing?",
        name
    ));
}

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>;

    fn add_rlib(
        &mut self,
        path: &Path,
        name: &str,
        lto: bool,
        skip_objects: bool,
    ) -> io::Result<()>;
    fn add_native_library(&mut self, name: Symbol);
    fn update_symbols(&mut self);

    fn build(self);
}