From e5d1755aa019d2b5bc1a1af9dda5311a6fe7e5e6 Mon Sep 17 00:00:00 2001 From: Jaki Chen Date: Tue, 21 Jul 2026 09:19:10 +0800 Subject: [PATCH] build: conditionally compile media capture permission for macOS deployment target --- build.rs | 29 +++++++++++++++++++ .../class/wry_web_view_ui_delegate.rs | 1 + 2 files changed, 30 insertions(+) diff --git a/build.rs b/build.rs index 13ff4cff4..d634493dc 100644 --- a/build.rs +++ b/build.rs @@ -109,6 +109,35 @@ fn main() { || target.contains("openbsd")); alias("linux", linux); alias("gtk", cfg!(feature = "os-webview") && linux); + + // Detect the macOS deployment target from the environment (set by Tauri or the user). + // This allows conditional compilation based on the minimum supported macOS version. + // We define two custom cfg flags: + // - macos_12_or_later: true if deployment target is macOS 12.0+ + // - macos_11_or_earlier: true if deployment target is macOS 11.x or older + // + // These flags are used in the WebView implementation to conditionally compile APIs + // that were introduced in macOS 12 (e.g., requestMediaCapturePermissionForOrigin). + // On older deployment targets, the unsupported code is simply excluded, + // preventing compilation errors and removing the need for downstream patches. + + println!("cargo::rustc-check-cfg=cfg(macos_12_or_later)"); + println!("cargo::rustc-check-cfg=cfg(macos_11_or_earlier)"); + + let deployment_target = + std::env::var("MACOSX_DEPLOYMENT_TARGET").unwrap_or_else(|_| "10.15".to_string()); + let major: u32 = deployment_target + .split('.') + .next() + .unwrap_or("10") + .parse() + .unwrap_or(10); + + if major >= 12 { + println!("cargo:rustc-cfg=macos_12_or_later"); + } else { + println!("cargo:rustc-cfg=macos_11_or_earlier"); + } } fn alias(alias: &str, condition: bool) { diff --git a/src/wkwebview/class/wry_web_view_ui_delegate.rs b/src/wkwebview/class/wry_web_view_ui_delegate.rs index 7d2b0e640..2e0439379 100644 --- a/src/wkwebview/class/wry_web_view_ui_delegate.rs +++ b/src/wkwebview/class/wry_web_view_ui_delegate.rs @@ -124,6 +124,7 @@ define_class!( } } + #[cfg(macos_12_or_later)] #[unsafe(method(webView:requestMediaCapturePermissionForOrigin:initiatedByFrame:type:decisionHandler:))] fn request_media_capture_permission( &self,