Skip to content

Commit

Permalink
Set --target flag for Apple's clang when cross-compiling
Browse files Browse the repository at this point in the history
  • Loading branch information
kornelski committed Nov 22, 2021
1 parent cef0acf commit cca5874
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,14 @@ fn build(target_os: &str) -> io::Result<()> {
// The cc crate has the messy logic of guessing a working prefix,
// and this is a messy way of reusing that logic.
let cc = cc::Build::new();

// Apple-clang needs this, -arch is not enough.
let target_flag = format!("--target={}", target);
if cc.is_flag_supported(&target_flag).unwrap_or(false) {
configure.arg(format!("--extra-cflags={}", target_flag));
configure.arg(format!("--extra-ldflags={}", target_flag));
}

let compiler = cc.get_compiler();
let compiler = compiler.path().file_stem().unwrap().to_str().unwrap();
if let Some(suffix_pos) = compiler.rfind('-') {
Expand Down Expand Up @@ -340,6 +348,8 @@ fn build(target_os: &str) -> io::Result<()> {
// configure misc build options
enable!(configure, "BUILD_PIC", "pic");

println!("configure cmd: {:?}", configure);

// run ./configure
let output = configure
.output()
Expand Down

0 comments on commit cca5874

Please sign in to comment.