Skip to content

Commit

Permalink
Conditionally link through ColorSync only if WINIT_LINK_COLORSYNC is set
Browse files Browse the repository at this point in the history
to true
  • Loading branch information
Imberflur committed Feb 3, 2021
1 parent 42df4f1 commit ec02393
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
10 changes: 10 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
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");
}
}
9 changes: 8 additions & 1 deletion src/platform_impl/macos/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,14 @@ pub const IO8BitOverlayPixels: &str = "O8";
pub type CGWindowLevel = i32;
pub type CGDisplayModeRef = *mut libc::c_void;

#[link(name = "ColorSync", kind = "framework")]
#[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;
}
Expand Down

0 comments on commit ec02393

Please sign in to comment.