From aa810f018e9e65e996e99dd479147f5fc663a587 Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Tue, 30 Nov 2021 00:09:17 +0100 Subject: [PATCH] Fix CGDisplayCreateUUIDFromDisplayID linking (again) See also https://github.com/rust-windowing/winit/pull/1626. The `cocoa` crate links to AppKit, which made the symbol `CGDisplayCreateUUIDFromDisplayID` from ColorSync (which AppKit uses internally) available to us (on macOS 10.13 or above). Lately something changed in rustc so that this no longer works, see https://github.com/rust-lang/rust/issues/91372. So instead, we link to AppKit directly within the `winit` crate, which, for now, allows us to use the private symbol. --- README.md | 10 ---------- build.rs | 10 ---------- src/platform_impl/macos/ffi.rs | 21 ++++++++++----------- 3 files changed, 10 insertions(+), 31 deletions(-) delete mode 100644 build.rs diff --git a/README.md b/README.md index fcbc973973c..7a53a685c6a 100644 --- a/README.md +++ b/README.md @@ -119,13 +119,3 @@ fn main() { ``` And run the application with `cargo apk run --example request_redraw_threaded` - -#### MacOS - -To ensure compatibility with older MacOS systems, winit links to -CGDisplayCreateUUIDFromDisplayID through the CoreGraphics framework. -However, under certain setups this function is only available to be linked -through the newer ColorSync framework. So, winit provides the -`WINIT_LINK_COLORSYNC` environment variable which can be set to `1` or `true` -while compiling to enable linking via ColorSync. - diff --git a/build.rs b/build.rs deleted file mode 100644 index a092e63631d..00000000000 --- a/build.rs +++ /dev/null @@ -1,10 +0,0 @@ -fn main() { - // If building for macos and WINIT_LINK_COLORSYNC is set to true - // use CGDisplayCreateUUIDFromDisplayID from ColorSync instead of CoreGraphics - if std::env::var("CARGO_CFG_TARGET_OS").map_or(false, |os| os == "macos") - && std::env::var("WINIT_LINK_COLORSYNC") - .map_or(false, |v| v == "1" || v.eq_ignore_ascii_case("true")) - { - println!("cargo:rustc-cfg=use_colorsync_cgdisplaycreateuuidfromdisplayid"); - } -} diff --git a/src/platform_impl/macos/ffi.rs b/src/platform_impl/macos/ffi.rs index 991b3f331d5..7d7968a21e3 100644 --- a/src/platform_impl/macos/ffi.rs +++ b/src/platform_impl/macos/ffi.rs @@ -165,20 +165,19 @@ pub const IO8BitOverlayPixels: &str = "O8"; pub type CGWindowLevel = i32; pub type CGDisplayModeRef = *mut c_void; -#[cfg_attr( - not(use_colorsync_cgdisplaycreateuuidfromdisplayid), - link(name = "CoreGraphics", kind = "framework") -)] -#[cfg_attr( - use_colorsync_cgdisplaycreateuuidfromdisplayid, - link(name = "ColorSync", kind = "framework") -)] -extern "C" { - pub fn CGDisplayCreateUUIDFromDisplayID(display: CGDirectDisplayID) -> CFUUIDRef; -} +// HACK: +// `CGDisplayCreateUUIDFromDisplayID` moved from `CoreGraphics` to `ColorSync` +// in macOS 10.13 (which is also where `ColorSync` was introduced). +// +// Since we want to support older versions, we can't link to `ColorSync` +// directly. Fortunately `AppKit` links to `ColorSync` internally, so by +// linking to `AppKit` in this crate, the symbol becomes available. +#[link(name = "AppKit", kind = "framework")] +extern "C" {} #[link(name = "CoreGraphics", kind = "framework")] extern "C" { + pub fn CGDisplayCreateUUIDFromDisplayID(display: CGDirectDisplayID) -> CFUUIDRef; pub fn CGRestorePermanentDisplayConfiguration(); pub fn CGDisplayCapture(display: CGDirectDisplayID) -> CGError; pub fn CGDisplayRelease(display: CGDirectDisplayID) -> CGError;