Skip to content

Commit 24dfba3

Browse files
committed
enable using AR to modify archiving behavior on windows
Fixes #384.
1 parent 1f0cd6f commit 24dfba3

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

src/lib.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1487,12 +1487,7 @@ impl Build {
14871487
let objects: Vec<_> = objs.iter().map(|obj| obj.dst.clone()).collect();
14881488
let target = self.get_target()?;
14891489
if target.contains("msvc") {
1490-
let mut cmd = match self.archiver {
1491-
Some(ref s) => self.cmd(s),
1492-
None => windows_registry::find(&target, "lib.exe")
1493-
.unwrap_or_else(|| self.cmd("lib.exe")),
1494-
};
1495-
1490+
let (mut cmd, program) = self.get_ar()?;
14961491
let mut out = OsString::from("/OUT:");
14971492
out.push(dst);
14981493
cmd.arg(out).arg("/nologo");
@@ -1537,7 +1532,7 @@ impl Build {
15371532
} else {
15381533
cmd.args(&objects).args(&self.objects);
15391534
}
1540-
run(&mut cmd, "lib.exe")?;
1535+
run(&mut cmd, &program)?;
15411536

15421537
// The Rust compiler will look for libfoo.a and foo.lib, but the
15431538
// MSVC linker will also be passed foo.lib, so be sure that both
@@ -1979,9 +1974,10 @@ impl Build {
19791974
if let Ok(p) = self.get_var("AR") {
19801975
return Ok((self.cmd(&p), p));
19811976
}
1982-
let program = if self.get_target()?.contains("android") {
1983-
format!("{}-ar", self.get_target()?.replace("armv7", "arm"))
1984-
} else if self.get_target()?.contains("emscripten") {
1977+
let target = self.get_target()?;
1978+
let program = if target.contains("android") {
1979+
format!("{}-ar", target.replace("armv7", "arm"))
1980+
} else if target.contains("emscripten") {
19851981
// Windows use bat files so we have to be a bit more specific
19861982
if cfg!(windows) {
19871983
let mut cmd = self.cmd("cmd");
@@ -1990,6 +1986,14 @@ impl Build {
19901986
}
19911987

19921988
"emar".to_string()
1989+
} else if target.contains("msvc") {
1990+
match windows_registry::find_tool(&target, "lib.exe") {
1991+
Some(t) => match t.path().to_str() {
1992+
Some(ref p) => p.to_string(),
1993+
None => "lib.exe".to_string(),
1994+
},
1995+
None => "lib.exe".to_string(),
1996+
}
19931997
} else {
19941998
"ar".to_string()
19951999
};

0 commit comments

Comments
 (0)