Browse Source

Add the ability to configure an archiver as well

add-rc-path
Alex Crichton 9 years ago
parent
commit
172cf7fea0
  1. 36
      src/lib.rs
  2. 18
      tests/test.rs

36
src/lib.rs

@ -74,6 +74,7 @@ pub struct Config {
debug: Option<bool>, debug: Option<bool>,
env: Vec<(OsString, OsString)>, env: Vec<(OsString, OsString)>,
compiler: Option<PathBuf>, compiler: Option<PathBuf>,
archiver: Option<PathBuf>,
} }
fn getenv(v: &str) -> Option<String> { fn getenv(v: &str) -> Option<String> {
@ -131,6 +132,7 @@ impl Config {
debug: None, debug: None,
env: Vec::new(), env: Vec::new(),
compiler: None, compiler: None,
archiver: None,
} }
} }
@ -275,6 +277,16 @@ impl Config {
self self
} }
/// Configures the tool used to assemble archives.
///
/// This option is automatically determined from the target platform or a
/// number of environment variables, so it's not required to call this
/// function.
pub fn archiver<P: AsRef<Path>>(&mut self, archiver: P) -> &mut Config {
self.archiver = Some(archiver.as_ref().to_owned());
self
}
#[doc(hidden)] #[doc(hidden)]
pub fn __set_env<A, B>(&mut self, a: A, b: B) -> &mut Config pub fn __set_env<A, B>(&mut self, a: A, b: B) -> &mut Config
where A: AsRef<OsStr>, B: AsRef<OsStr> where A: AsRef<OsStr>, B: AsRef<OsStr>
@ -428,8 +440,11 @@ impl Config {
fn assemble(&self, lib_name: &str, dst: &Path, objects: &[PathBuf]) { fn assemble(&self, lib_name: &str, dst: &Path, objects: &[PathBuf]) {
let target = self.get_target(); let target = self.get_target();
if target.contains("msvc") { if target.contains("msvc") {
let cmd = windows_registry::find(&target, "lib.exe"); let mut cmd = match self.archiver {
let mut cmd = cmd.unwrap_or(self.cmd("lib.exe")); Some(ref s) => self.cmd(s),
None => windows_registry::find(&target, "lib.exe")
.unwrap_or(self.cmd("lib.exe")),
};
let mut out = OsString::from("/OUT:"); let mut out = OsString::from("/OUT:");
out.push(dst); out.push(dst);
run(cmd.arg(out).arg("/nologo") run(cmd.arg(out).arg("/nologo")
@ -444,10 +459,11 @@ impl Config {
fs::hard_link(dst, lib_dst).unwrap(); fs::hard_link(dst, lib_dst).unwrap();
} else { } else {
let ar = self.get_ar(); let ar = self.get_ar();
let cmd = ar.file_name().unwrap().to_string_lossy();
run(self.cmd(&ar).arg("crus") run(self.cmd(&ar).arg("crus")
.arg(dst) .arg(dst)
.args(objects) .args(objects)
.args(&self.objects), &ar); .args(&self.objects), &cmd);
} }
} }
@ -576,11 +592,15 @@ impl Config {
}) })
} }
fn get_ar(&self) -> String { fn get_ar(&self) -> PathBuf {
self.get_var("AR").unwrap_or(if self.get_target().contains("android") { self.archiver.clone().or_else(|| {
format!("{}-ar", self.get_target()) self.get_var("AR").map(PathBuf::from).ok()
} else { }).unwrap_or_else(|| {
"ar".to_string() if self.get_target().contains("android") {
PathBuf::from(format!("{}-ar", self.get_target()))
} else {
PathBuf::from("ar")
}
}) })
} }

18
tests/test.rs

@ -69,6 +69,7 @@ impl Test {
.__set_env("GCCTEST_OUT_DIR", self.td.path()); .__set_env("GCCTEST_OUT_DIR", self.td.path());
if self.msvc { if self.msvc {
cfg.compiler(self.td.path().join("cl")); cfg.compiler(self.td.path().join("cl"));
cfg.archiver(self.td.path().join("lib.exe"));
} }
return cfg return cfg
} }
@ -263,20 +264,3 @@ fn msvc_define() {
test.cmd(0).must_have("/DFOO=bar").must_have("/DBAR"); test.cmd(0).must_have("/DFOO=bar").must_have("/DBAR");
} }
#[test]
fn msvc_compile_assembly() {
let test = Test::msvc();
test.shim("ml64.exe").gcc()
.file("foo.asm").compile("libfoo.a");
test.cmd(0).must_have("foo.asm");
}
#[test]
fn msvc_compile_assembly_32() {
let test = Test::msvc();
test.shim("ml.exe").gcc()
.target("i686-pc-windows-msvc")
.file("foo.asm").compile("libfoo.a");
test.cmd(0).must_have("foo.asm");
}

Loading…
Cancel
Save