From ad1f00de0f799c3a140a6ced13c08820606763c9 Mon Sep 17 00:00:00 2001 From: Simonas Kazlauskas Date: Mon, 31 Oct 2022 01:11:21 +0200 Subject: [PATCH] Prefer `-ar` to `-gcc-ar` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As observed in https://github.com/cross-rs/cross/issues/1100, in some situations `*-gcc-ar` might actually be just broken. I believe this is most likely just a plain bug in gcc (failing to consider `--disable-lto` configuration option somewhere in their build setup,) but for the time being `*-ar` tends to avoid this problem altogether. Code added in https://github.com/rust-lang/cc-rs/pull/736 appears to be preferring `*-gcc-ar`, but no strong rationale is given to prefer one over the other. `*-gcc-ar` being outright broken sometimes seems like a rationale strong enough to continue preferring binutils’ `ar`. --- src/lib.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 130389205..21185a7fe 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2623,9 +2623,12 @@ impl Build { match self.prefix_for_target(&target) { Some(p) => { // GCC uses $target-gcc-ar, whereas binutils uses $target-ar -- try both. - // Prefer -gcc-ar if it exists, since that matches what we'll use for $CC. + // Prefer -ar if it exists, as builds of `-gcc-ar` have been observed to be + // outright broken (such as when targetting freebsd with `--disable-lto` + // toolchain where the archiver attempts to load the LTO plugin anyway but + // fails to find one). let mut ar = default_ar; - for &infix in &["-gcc", ""] { + for &infix in &["", "-gcc"] { let target_ar = format!("{}{}-ar", p, infix); if Command::new(&target_ar).output().is_ok() { ar = target_ar;