Skip to content

Commit cca5874

Browse files
committed
Set --target flag for Apple's clang when cross-compiling
1 parent cef0acf commit cca5874

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

build.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,14 @@ fn build(target_os: &str) -> io::Result<()> {
209209
// The cc crate has the messy logic of guessing a working prefix,
210210
// and this is a messy way of reusing that logic.
211211
let cc = cc::Build::new();
212+
213+
// Apple-clang needs this, -arch is not enough.
214+
let target_flag = format!("--target={}", target);
215+
if cc.is_flag_supported(&target_flag).unwrap_or(false) {
216+
configure.arg(format!("--extra-cflags={}", target_flag));
217+
configure.arg(format!("--extra-ldflags={}", target_flag));
218+
}
219+
212220
let compiler = cc.get_compiler();
213221
let compiler = compiler.path().file_stem().unwrap().to_str().unwrap();
214222
if let Some(suffix_pos) = compiler.rfind('-') {
@@ -340,6 +348,8 @@ fn build(target_os: &str) -> io::Result<()> {
340348
// configure misc build options
341349
enable!(configure, "BUILD_PIC", "pic");
342350

351+
println!("configure cmd: {:?}", configure);
352+
343353
// run ./configure
344354
let output = configure
345355
.output()

0 commit comments

Comments
 (0)