Skip to content

Commit

Permalink
Fix CGDisplayCreateUUIDFromDisplayID linking (again)
Browse files Browse the repository at this point in the history
See also rust-windowing#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 rust-lang/rust#91372. So instead, we link to AppKit directly within the `winit` crate, which, for now, allows us to use the private symbol.
  • Loading branch information
madsmtm committed Nov 29, 2021
1 parent 29a078f commit aa810f0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 31 deletions.
10 changes: 0 additions & 10 deletions README.md
Expand Up @@ -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.

10 changes: 0 additions & 10 deletions build.rs

This file was deleted.

21 changes: 10 additions & 11 deletions src/platform_impl/macos/ffi.rs
Expand Up @@ -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;
Expand Down

0 comments on commit aa810f0

Please sign in to comment.