|
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;
|
@@ -345,17 +346,25 @@ impl Build {
|
345 | 346 | // prefix, we unset `CROSS_COMPILE` for `./Configure`.
|
346 | 347 | configure.env_remove("CROSS_COMPILE");
|
347 | 348 |
|
348 |
| - // Infer ar/ranlib tools from cross compilers if the it looks like |
349 |
| - // we're doing something like `foo-gcc` route that to `foo-ranlib` |
350 |
| - // as well. |
351 |
| - if path.ends_with("-gcc") && !target.contains("unknown-linux-musl") { |
352 |
| - let path = &path[..path.len() - 4]; |
353 |
| - if env::var_os("RANLIB").is_none() { |
354 |
| - configure.env("RANLIB", format!("{}-ranlib", path)); |
355 |
| - } |
356 |
| - if env::var_os("AR").is_none() { |
357 |
| - configure.env("AR", format!("{}-ar", path)); |
358 |
| - } |
| 349 | + let ar = cc.get_archiver(); |
| 350 | + configure.env("AR", ar.get_program()); |
| 351 | + if ar.get_args().count() == 0 { |
| 352 | + // On some platforms (like emscripten on windows), the ar to use may not be a |
| 353 | + // single binary, but instead a multi-argument command like `cmd /c emar.bar`. |
| 354 | + // We can't convey that through `AR` alone, and so also need to set ARFLAGS. |
| 355 | + configure.env( |
| 356 | + "ARFLAGS", |
| 357 | + ar.get_args().collect::<Vec<_>>().join(OsStr::new(" ")), |
| 358 | + ); |
| 359 | + } |
| 360 | + let ranlib = cc.get_ranlib(); |
| 361 | + configure.env("RANLIB", ranlib.get_program()); |
| 362 | + if ranlib.get_args().count() == 0 { |
| 363 | + // Same thing as for AR -- we may need to set RANLIBFLAGS |
| 364 | + configure.env( |
| 365 | + "RANLIBFLAGS", |
| 366 | + ranlib.get_args().collect::<Vec<_>>().join(OsStr::new(" ")), |
| 367 | + ); |
359 | 368 | }
|
360 | 369 |
|
361 | 370 | // Make sure we pass extra flags like `-ffunction-sections` and
|
|
0 commit comments