|
1 | 1 | extern crate cc;
|
2 | 2 |
|
3 | 3 | use std::env;
|
| 4 | +use std::ffi::OsStr; |
4 | 5 | use std::fs;
|
5 | 6 | use std::path::{Path, PathBuf};
|
6 | 7 | use std::process::Command;
|
@@ -323,17 +324,25 @@ impl Build {
|
323 | 324 | // prefix, we unset `CROSS_COMPILE` for `./Configure`.
|
324 | 325 | configure.env_remove("CROSS_COMPILE");
|
325 | 326 |
|
326 |
| - // Infer ar/ranlib tools from cross compilers if the it looks like |
327 |
| - // we're doing something like `foo-gcc` route that to `foo-ranlib` |
328 |
| - // as well. |
329 |
| - if path.ends_with("-gcc") && !target.contains("unknown-linux-musl") { |
330 |
| - let path = &path[..path.len() - 4]; |
331 |
| - if env::var_os("RANLIB").is_none() { |
332 |
| - configure.env("RANLIB", format!("{}-ranlib", path)); |
333 |
| - } |
334 |
| - if env::var_os("AR").is_none() { |
335 |
| - configure.env("AR", format!("{}-ar", path)); |
336 |
| - } |
| 327 | + let ar = cc.get_archiver(); |
| 328 | + configure.env("AR", ar.get_program()); |
| 329 | + if ar.get_args().count() == 0 { |
| 330 | + // On some platforms (like emscripten on windows), the ar to use may not be a |
| 331 | + // single binary, but instead a multi-argument command like `cmd /c emar.bar`. |
| 332 | + // We can't convey that through `AR` alone, and so also need to set ARFLAGS. |
| 333 | + configure.env( |
| 334 | + "ARFLAGS", |
| 335 | + ar.get_args().collect::<Vec<_>>().join(OsStr::new(" ")), |
| 336 | + ); |
| 337 | + } |
| 338 | + let ranlib = cc.get_ranlib(); |
| 339 | + configure.env("RANLIB", ranlib.get_program()); |
| 340 | + if ranlib.get_args().count() == 0 { |
| 341 | + // Same thing as for AR -- we may need to set RANLIBFLAGS |
| 342 | + configure.env( |
| 343 | + "RANLIBFLAGS", |
| 344 | + ranlib.get_args().collect::<Vec<_>>().join(OsStr::new(" ")), |
| 345 | + ); |
337 | 346 | }
|
338 | 347 |
|
339 | 348 | // Make sure we pass extra flags like `-ffunction-sections` and
|
|
0 commit comments