Skip to content

Commit 7f920bc

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

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

build.rs

Lines changed: 14 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()
@@ -386,6 +396,7 @@ fn os_from_triple(triple: &str) -> &str {
386396
.trim_start_matches("unknown-")
387397
.trim_start_matches("pc-")
388398
.trim_start_matches("wrs-")
399+
.trim_start_matches("apple-")
389400
.trim_start_matches("uwp-")
390401
.split('-')
391402
.next()
@@ -654,11 +665,11 @@ fn main() {
654665
"cargo:rustc-link-search=native={}",
655666
search().join("lib").to_string_lossy()
656667
);
657-
link_to_libraries(statik, &target_os);
668+
link_to_libraries(statik, target_os);
658669
if fs::metadata(&search().join("lib").join("libavutil.a")).is_err() {
659670
fs::create_dir_all(&output()).expect("failed to create build directory");
660671
fetch().unwrap();
661-
build(&target_os).unwrap();
672+
build(target_os).unwrap();
662673
}
663674

664675
// Check additional required libraries.
@@ -691,7 +702,7 @@ fn main() {
691702
"cargo:rustc-link-search=native={}",
692703
ffmpeg_dir.join("lib").to_string_lossy()
693704
);
694-
link_to_libraries(statik, &target_os);
705+
link_to_libraries(statik, target_os);
695706
vec![ffmpeg_dir.join("include")]
696707
} else if let Some(paths) = try_vcpkg(statik) {
697708
// vcpkg doesn't detect the "system" dependencies

0 commit comments

Comments
 (0)