From 411e243dcd480592ea1417548ccf20a4bf3beb3d Mon Sep 17 00:00:00 2001 From: alexmoon Date: Mon, 19 Jun 2023 13:40:07 -0400 Subject: [PATCH] Fix cross compilation on a macos host In a build script `cfg(target_os=...)` refers to the host, not the target. Using the `CARGO_CFG_TARGET_OS` environment variable sets the link parameters properly. --- nokhwa-bindings-macos/build.rs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/nokhwa-bindings-macos/build.rs b/nokhwa-bindings-macos/build.rs index d01268b..00fe7aa 100644 --- a/nokhwa-bindings-macos/build.rs +++ b/nokhwa-bindings-macos/build.rs @@ -14,12 +14,11 @@ * limitations under the License. */ -#[cfg(any(target_os = "macos", target_os = "ios"))] fn main() { - println!("cargo:rustc-link-lib=framework=CoreMedia"); - println!("cargo:rustc-link-lib=framework=AVFoundation"); - println!("cargo:rustc-link-lib=framework=CoreVideo"); + let target_os = std::env::var("CARGO_CFG_TARGET_OS").unwrap(); + if target_os == "macos" || target_os == "ios" { + println!("cargo:rustc-link-lib=framework=CoreMedia"); + println!("cargo:rustc-link-lib=framework=AVFoundation"); + println!("cargo:rustc-link-lib=framework=CoreVideo"); + } } - -#[cfg(not(any(target_os = "macos", target_os = "ios")))] -fn main() {}