diff --git a/README.md b/README.md index 8983caa..6556b4a 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,8 @@ fn main() { The linker may warn that a couple of these were ignored because nothing imports from them. That's expected: those are bridges for backends that only exist on other platforms. +On macOS and iOS, cargo links the system frameworks a static build needs. If you build a Rust `staticlib` and link it from Xcode, cargo isn't doing the final link, so add them to your Xcode target yourself: Foundation, AVFoundation, AppKit, IOKit, and CoreFoundation on macOS, or Foundation, AVFoundation, and UIKit on iOS. + ## Custom backends You can write a backend in Rust and register it alongside prism's own. Implement `CustomBackend`, declare the operations you implemented, and freeze a registry: diff --git a/crates/prism-sys/build.rs b/crates/prism-sys/build.rs index d00930d..6c5c294 100644 --- a/crates/prism-sys/build.rs +++ b/crates/prism-sys/build.rs @@ -11,6 +11,15 @@ use cmake::Config; /// otherwise it failed with unresolved UI Automation, RPC and Windows Runtime symbols. const WINDOWS_SYSTEM_LIBS: &[&str] = &["ole32", "onecore", "runtimeobject", "uiautomationcore", "rpcrt4", "powrprof"]; +/// The frameworks prism links itself on macOS, in `PrismPlatformApple.cmake`. +/// +/// `IOKit` and `CoreFoundation` are for the power notifier, which is always linked, so a static +/// binary fails to link without them even before any backend is used. +const MACOS_FRAMEWORKS: &[&str] = &["Foundation", "AVFoundation", "AppKit", "IOKit", "CoreFoundation"]; + +/// The frameworks prism links itself on iOS, in `PrismPlatformApple.cmake`. +const IOS_FRAMEWORKS: &[&str] = &["Foundation", "AVFoundation", "UIKit"]; + fn main() { println!("cargo:rerun-if-env-changed=PRISM_LIB_DIR"); let static_link = env::var("CARGO_FEATURE_STATIC").is_ok(); @@ -24,6 +33,21 @@ fn main() { if static_link { link_cpp_runtime(); link_windows_import_libs(); + link_apple_frameworks(); + } +} + +/// Links the frameworks the Apple backends and power notifier use. +/// +/// A shared prism links these itself; a static one leaves them to the final link. +fn link_apple_frameworks() { + let frameworks = match env::var("CARGO_CFG_TARGET_OS").as_deref() { + Ok("macos") => MACOS_FRAMEWORKS, + Ok("ios") => IOS_FRAMEWORKS, + _ => return, + }; + for framework in frameworks { + println!("cargo:rustc-link-lib=framework={framework}"); } } diff --git a/crates/prism-sys/prism b/crates/prism-sys/prism index 77f3f43..6d87910 160000 --- a/crates/prism-sys/prism +++ b/crates/prism-sys/prism @@ -1 +1 @@ -Subproject commit 77f3f43fb459f585af00949d7e65390ed60c19d1 +Subproject commit 6d87910ae853dc1c61faeef9bd4677b4972f1aca