-
Notifications
You must be signed in to change notification settings - Fork 504
Fix archiver detection for musl cross compilation #1404
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
1005cd7
a64bb2f
98eb42b
8e226da
32665bc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -232,7 +232,7 @@ use std::io::{self, Write}; | |
use std::path::{Component, Path, PathBuf}; | ||
#[cfg(feature = "parallel")] | ||
use std::process::Child; | ||
use std::process::Command; | ||
use std::process::{Command, Stdio}; | ||
use std::sync::{ | ||
atomic::{AtomicU8, Ordering::Relaxed}, | ||
Arc, RwLock, | ||
|
@@ -3226,7 +3226,6 @@ impl Build { | |
} | ||
}); | ||
|
||
let default = tool.to_string(); | ||
let tool = match tool_opt { | ||
Some(t) => t, | ||
None => { | ||
|
@@ -3287,32 +3286,39 @@ impl Build { | |
self.cmd(&name) | ||
} else if self.get_is_cross_compile()? { | ||
match self.prefix_for_target(&self.get_raw_target()?) { | ||
Some(p) => { | ||
Some(prefix) => { | ||
// GCC uses $target-gcc-ar, whereas binutils uses $target-ar -- try both. | ||
// Prefer -ar if it exists, as builds of `-gcc-ar` have been observed to be | ||
// outright broken (such as when targeting freebsd with `--disable-lto` | ||
// toolchain where the archiver attempts to load the LTO plugin anyway but | ||
// fails to find one). | ||
// | ||
// The same applies to ranlib. | ||
let mut chosen = default; | ||
for &infix in &["", "-gcc"] { | ||
let target_p = format!("{}{}-{}", p, infix, tool); | ||
if Command::new(&target_p).output().is_ok() { | ||
chosen = target_p; | ||
break; | ||
} | ||
} | ||
let chosen = ["", "-gcc"] | ||
.iter() | ||
.filter_map(|infix| { | ||
let target_p = format!("{prefix}{infix}-{tool}"); | ||
let status = Command::new(&target_p) | ||
.arg("--version") | ||
NobodyXu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
.stdin(Stdio::null()) | ||
.stdout(Stdio::null()) | ||
.stderr(Stdio::null()) | ||
.status() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a reason why we don't invoke There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, because https://docs.rs/which/latest/which/ There's a crate that we could use for it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Which also has quite a few deps unfortunately. The core logic would be re-implementable in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Just slightly worried about having more code to be maintained. |
||
.ok()?; | ||
status.success().then_some(target_p) | ||
}) | ||
.next() | ||
.unwrap_or_else(|| tool.to_string()); | ||
name = chosen.into(); | ||
self.cmd(&name) | ||
} | ||
None => { | ||
name = default.into(); | ||
name = tool.into(); | ||
self.cmd(&name) | ||
} | ||
} | ||
} else { | ||
name = default.into(); | ||
name = tool.into(); | ||
self.cmd(&name) | ||
} | ||
} | ||
|
Uh oh!
There was an error while loading. Please reload this page.