From cca5874cde44041918644ad685d80375b36e3d92 Mon Sep 17 00:00:00 2001 From: Kornel Date: Mon, 22 Nov 2021 01:44:30 +0000 Subject: [PATCH] Set --target flag for Apple's clang when cross-compiling --- build.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/build.rs b/build.rs index 3ac94eb..9eccb59 100644 --- a/build.rs +++ b/build.rs @@ -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('-') { @@ -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()