Skip to content

Commit d92af4f

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

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

build.rs

Lines changed: 13 additions & 3 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()
@@ -654,11 +664,11 @@ fn main() {
654664
"cargo:rustc-link-search=native={}",
655665
search().join("lib").to_string_lossy()
656666
);
657-
link_to_libraries(statik, &target_os);
667+
link_to_libraries(statik, target_os);
658668
if fs::metadata(&search().join("lib").join("libavutil.a")).is_err() {
659669
fs::create_dir_all(&output()).expect("failed to create build directory");
660670
fetch().unwrap();
661-
build(&target_os).unwrap();
671+
build(target_os).unwrap();
662672
}
663673

664674
// Check additional required libraries.
@@ -691,7 +701,7 @@ fn main() {
691701
"cargo:rustc-link-search=native={}",
692702
ffmpeg_dir.join("lib").to_string_lossy()
693703
);
694-
link_to_libraries(statik, &target_os);
704+
link_to_libraries(statik, target_os);
695705
vec![ffmpeg_dir.join("include")]
696706
} else if let Some(paths) = try_vcpkg(statik) {
697707
// vcpkg doesn't detect the "system" dependencies

0 commit comments

Comments
 (0)