Skip to content
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

Correctly infer ranlib/ar for cross-gcc toolchains #164

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 18 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,15 +346,25 @@ impl Build {
configure.env_remove("CROSS_COMPILE");

// Infer ar/ranlib tools from cross compilers if the it looks like
// we're doing something like `foo-gcc` route that to `foo-ranlib`
// as well.
// we're doing something like `foo-gcc` route that to `foo-gcc-ranlib`
// or `foo-ranlib` (for `binutils`) as well.
if path.ends_with("-gcc") && !target.contains("unknown-linux-musl") {
let path = &path[..path.len() - 4];
if env::var_os("RANLIB").is_none() {
configure.env("RANLIB", format!("{}-ranlib", path));
}
if env::var_os("AR").is_none() {
configure.env("AR", format!("{}-ar", path));
let suffix = &path[path.len() - 4..];
let path = &path[..path.len() - suffix.len()];
for &tool in &["RANLIB", "AR"] {
if env::var_os(tool).is_some() {
// Respect what came before.
break;
}

for &infix in &["", suffix] {
let candidate = format!("{}{}-{}", path, infix, tool.to_lowercase());
// Only choose a tool if it's actually executable
if Command::new(&candidate).output().is_ok() {
configure.env(tool, candidate);
break;
}
}
}
}

Expand Down