Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quicker Mac builds by removing dependencies #2220

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 1 addition & 8 deletions Cargo.toml
Expand Up @@ -42,18 +42,11 @@ ndk-glue = "0.6"

[target.'cfg(any(target_os = "ios", target_os = "macos"))'.dependencies]
objc = "0.2.7"
libc = "0.2.64"

[target.'cfg(target_os = "macos")'.dependencies]
cocoa = "0.24"
core-foundation = "0.9"
core-graphics = "0.22"
dispatch = "0.2.0"

[target.'cfg(target_os = "macos")'.dependencies.core-video-sys]
version = "0.1.4"
default_features = false
features = ["display_link"]

[target.'cfg(target_os = "windows")'.dependencies]
parking_lot = "0.12"

Expand Down
26 changes: 11 additions & 15 deletions src/platform_impl/macos/app.rs
@@ -1,9 +1,6 @@
use std::collections::VecDeque;

use cocoa::{
appkit::{self, NSEvent},
base::id,
};
use super::thin_cocoa::{id, NSEvent, NSEventModifierFlags, NSEventType};
use objc::{
declare::ClassDecl,
runtime::{Class, Object, Sel},
Expand Down Expand Up @@ -40,11 +37,8 @@ extern "C" fn send_event(this: &Object, _sel: Sel, event: id) {
// but that doesn't really matter here.
let event_type = event.eventType();
let modifier_flags = event.modifierFlags();
if event_type == appkit::NSKeyUp
&& util::has_flag(
modifier_flags,
appkit::NSEventModifierFlags::NSCommandKeyMask,
)
if event_type == NSEventType::NSKeyUp
&& util::has_flag(modifier_flags, NSEventModifierFlags::NSCommandKeyMask)
{
let key_window: id = msg_send![this, keyWindow];
let _: () = msg_send![key_window, sendEvent: event];
Expand All @@ -59,10 +53,10 @@ extern "C" fn send_event(this: &Object, _sel: Sel, event: id) {
unsafe fn maybe_dispatch_device_event(event: id) {
let event_type = event.eventType();
match event_type {
appkit::NSMouseMoved
| appkit::NSLeftMouseDragged
| appkit::NSOtherMouseDragged
| appkit::NSRightMouseDragged => {
NSEventType::NSMouseMoved
| NSEventType::NSLeftMouseDragged
| NSEventType::NSOtherMouseDragged
| NSEventType::NSRightMouseDragged => {
let mut events = VecDeque::with_capacity(3);

let delta_x = event.deltaX() as f64;
Expand Down Expand Up @@ -99,7 +93,9 @@ unsafe fn maybe_dispatch_device_event(event: id) {

AppState::queue_events(events);
}
appkit::NSLeftMouseDown | appkit::NSRightMouseDown | appkit::NSOtherMouseDown => {
NSEventType::NSLeftMouseDown
| NSEventType::NSRightMouseDown
| NSEventType::NSOtherMouseDown => {
let mut events = VecDeque::with_capacity(1);

events.push_back(EventWrapper::StaticEvent(Event::DeviceEvent {
Expand All @@ -112,7 +108,7 @@ unsafe fn maybe_dispatch_device_event(event: id) {

AppState::queue_events(events);
}
appkit::NSLeftMouseUp | appkit::NSRightMouseUp | appkit::NSOtherMouseUp => {
NSEventType::NSLeftMouseUp | NSEventType::NSRightMouseUp | NSEventType::NSOtherMouseUp => {
let mut events = VecDeque::with_capacity(1);

events.push_back(EventWrapper::StaticEvent(Event::DeviceEvent {
Expand Down
2 changes: 1 addition & 1 deletion src/platform_impl/macos/app_delegate.rs
@@ -1,6 +1,6 @@
use crate::{platform::macos::ActivationPolicy, platform_impl::platform::app_state::AppState};

use cocoa::base::id;
use super::thin_cocoa::id;
use objc::{
declare::ClassDecl,
runtime::{Class, Object, Sel},
Expand Down
8 changes: 2 additions & 6 deletions src/platform_impl/macos/app_state.rs
Expand Up @@ -12,11 +12,7 @@ use std::{
time::Instant,
};

use cocoa::{
appkit::{NSApp, NSApplication, NSWindow},
base::{id, nil},
foundation::NSSize,
};
use super::thin_cocoa::{id, nil, NSApp, NSApplication, NSSize, NSWindow};
use objc::{
rc::autoreleasepool,
runtime::{Object, BOOL, NO, YES},
Expand Down Expand Up @@ -482,7 +478,7 @@ unsafe fn window_activation_hack(ns_app: id) {
}
fn apply_activation_policy(app_delegate: &Object) {
unsafe {
use cocoa::appkit::NSApplicationActivationPolicy::*;
use super::thin_cocoa::NSApplicationActivationPolicy::*;
let ns_app = NSApp();
// We need to delay setting the activation policy and activating the app
// until `applicationDidFinishLaunching` has been called. Otherwise the
Expand Down
7 changes: 2 additions & 5 deletions src/platform_impl/macos/event.rs
@@ -1,9 +1,6 @@
use std::os::raw::c_ushort;

use cocoa::{
appkit::{NSEvent, NSEventModifierFlags},
base::id,
};
use super::thin_cocoa::{id, NSEvent, NSEventModifierFlags};

use crate::{
dpi::LogicalSize,
Expand Down Expand Up @@ -263,7 +260,7 @@ pub fn event_mods(event: id) -> ModifiersState {
m
}

pub fn get_scancode(event: cocoa::base::id) -> c_ushort {
pub fn get_scancode(event: super::thin_cocoa::id) -> c_ushort {
// In AppKit, `keyCode` refers to the position (scancode) of a key rather than its character,
// and there is no easy way to navtively retrieve the layout-dependent character.
// In winit, we use keycode to refer to the key's character, and so this function aligns
Expand Down
11 changes: 5 additions & 6 deletions src/platform_impl/macos/event_loop.rs
Expand Up @@ -11,10 +11,9 @@ use std::{
sync::mpsc,
};

use cocoa::{
appkit::{NSApp, NSEventModifierFlags, NSEventSubtype, NSEventType::NSApplicationDefined},
base::{id, nil, BOOL, NO, YES},
foundation::{NSInteger, NSPoint, NSTimeInterval},
use super::thin_cocoa::{
id, nil, NSApp, NSEventModifierFlags, NSEventSubtype, NSEventType::NSApplicationDefined,
NSInteger, NSPoint, NSTimeInterval, BOOL, NO, YES,
};
use objc::rc::autoreleasepool;

Expand Down Expand Up @@ -92,13 +91,13 @@ impl<T: 'static> EventLoopWindowTarget<T> {
impl<T> EventLoopWindowTarget<T> {
pub(crate) fn hide_application(&self) {
let cls = objc::runtime::Class::get("NSApplication").unwrap();
let app: cocoa::base::id = unsafe { msg_send![cls, sharedApplication] };
let app: super::thin_cocoa::id = unsafe { msg_send![cls, sharedApplication] };
unsafe { msg_send![app, hide: 0] }
}

pub(crate) fn hide_other_applications(&self) {
let cls = objc::runtime::Class::get("NSApplication").unwrap();
let app: cocoa::base::id = unsafe { msg_send![cls, sharedApplication] };
let app: super::thin_cocoa::id = unsafe { msg_send![cls, sharedApplication] };
unsafe { msg_send![app, hideOtherApplications: 0] }
}
}
Expand Down
11 changes: 4 additions & 7 deletions src/platform_impl/macos/ffi.rs
Expand Up @@ -4,14 +4,11 @@

use std::ffi::c_void;

use cocoa::{
base::id,
foundation::{NSInteger, NSUInteger},
};
use core_foundation::{
use super::thin_cocoa::{id, NSInteger, NSUInteger};
use super::thin_core_foundation::{
array::CFArrayRef, dictionary::CFDictionaryRef, string::CFStringRef, uuid::CFUUIDRef,
};
use core_graphics::{
use super::thin_core_graphics::{
base::CGError,
display::{CGDirectDisplayID, CGDisplayConfigRef},
};
Expand Down Expand Up @@ -219,5 +216,5 @@ extern "C" {
pub fn CGDisplayModeGetRefreshRate(mode: CGDisplayModeRef) -> f64;
pub fn CGDisplayModeCopyPixelEncoding(mode: CGDisplayModeRef) -> CFStringRef;
pub fn CGDisplayModeRetain(mode: CGDisplayModeRef);
pub fn CGDisplayModeRelease(mode: CGDisplayModeRef);
// pub fn CGDisplayModeRelease(mode: CGDisplayModeRef);
}
6 changes: 3 additions & 3 deletions src/platform_impl/macos/menu.rs
@@ -1,7 +1,7 @@
use super::thin_cocoa::{nil, selector};
use super::thin_cocoa::{NSApp, NSApplication, NSEventModifierFlags, NSMenu, NSMenuItem};
use super::thin_cocoa::{NSProcessInfo, NSString};
use super::util::IdRef;
use cocoa::appkit::{NSApp, NSApplication, NSEventModifierFlags, NSMenu, NSMenuItem};
use cocoa::base::{nil, selector};
use cocoa::foundation::{NSProcessInfo, NSString};
use objc::{
rc::autoreleasepool,
runtime::{Object, Sel},
Expand Down
7 changes: 6 additions & 1 deletion src/platform_impl/macos/mod.rs
Expand Up @@ -3,6 +3,11 @@
#[macro_use]
mod util;

pub use util::thin_cocoa;
pub use util::thin_core_foundation;
pub use util::thin_core_graphics;
pub use util::thin_core_video_sys;

mod app;
mod app_delegate;
mod app_state;
Expand Down Expand Up @@ -54,7 +59,7 @@ pub struct Window {

#[derive(Debug)]
pub enum OsError {
CGError(core_graphics::base::CGError),
CGError(super::thin_core_graphics::base::CGError),
CreationError(&'static str),
}

Expand Down
31 changes: 15 additions & 16 deletions src/platform_impl/macos/monitor.rs
@@ -1,25 +1,21 @@
use std::{collections::VecDeque, fmt};

use super::{ffi, util};
use crate::{
dpi::{PhysicalPosition, PhysicalSize},
monitor::{MonitorHandle as RootMonitorHandle, VideoMode as RootVideoMode},
};
use cocoa::{
appkit::NSScreen,
base::{id, nil},
foundation::NSUInteger,
};
use core_foundation::{
use super::thin_cocoa::{id, nil, NSScreen, NSUInteger};
use super::thin_core_foundation::{
array::{CFArrayGetCount, CFArrayGetValueAtIndex},
base::{CFRelease, TCFType},
string::CFString,
//string:CFString,
CFRelease,
};
use core_graphics::display::{CGDirectDisplayID, CGDisplay, CGDisplayBounds};
use core_video_sys::{
use super::thin_core_graphics::display::{CGDirectDisplayID, CGDisplay, CGDisplayBounds};
use super::thin_core_video_sys::{
kCVReturnSuccess, kCVTimeIsIndefinite, CVDisplayLinkCreateWithCGDisplay,
CVDisplayLinkGetNominalOutputVideoRefreshPeriod, CVDisplayLinkRelease,
};
use super::{ffi, util};
use crate::{
dpi::{PhysicalPosition, PhysicalSize},
monitor::{MonitorHandle as RootMonitorHandle, VideoMode as RootVideoMode},
};

#[derive(Clone)]
pub struct VideoMode {
Expand Down Expand Up @@ -68,7 +64,7 @@ unsafe impl Send for NativeDisplayMode {}
impl Drop for NativeDisplayMode {
fn drop(&mut self) {
unsafe {
ffi::CGDisplayModeRelease(self.0);
super::thin_core_graphics::display::CGDisplayModeRelease(self.0 as *mut _);
}
}
}
Expand Down Expand Up @@ -269,6 +265,7 @@ impl MonitorHandle {
cv_refresh_rate
};

/*
let pixel_encoding =
CFString::wrap_under_create_rule(ffi::CGDisplayModeCopyPixelEncoding(mode))
.to_string();
Expand All @@ -281,6 +278,8 @@ impl MonitorHandle {
} else {
unimplemented!()
};
*/
let bit_depth = 32;

let video_mode = VideoMode {
size: (
Expand Down
6 changes: 2 additions & 4 deletions src/platform_impl/macos/util/async.rs
Expand Up @@ -3,10 +3,8 @@ use std::{
sync::{Mutex, Weak},
};

use cocoa::{
appkit::{CGFloat, NSScreen, NSWindow, NSWindowStyleMask},
base::{id, nil},
foundation::{NSPoint, NSSize, NSString},
use super::thin_cocoa::{
id, nil, CGFloat, NSPoint, NSScreen, NSSize, NSString, NSWindow, NSWindowStyleMask,
};
use dispatch::Queue;
use objc::rc::autoreleasepool;
Expand Down
6 changes: 1 addition & 5 deletions src/platform_impl/macos/util/cursor.rs
@@ -1,8 +1,4 @@
use cocoa::{
appkit::NSImage,
base::{id, nil},
foundation::{NSDictionary, NSPoint, NSString},
};
use super::thin_cocoa::{id, nil, NSDictionary, NSImage, NSPoint, NSString};
use objc::{runtime::Sel, runtime::NO};
use std::cell::RefCell;

Expand Down
14 changes: 7 additions & 7 deletions src/platform_impl/macos/util/mod.rs
@@ -1,17 +1,17 @@
mod r#async;
mod cursor;
pub mod thin_cocoa;
pub mod thin_core_foundation;
pub mod thin_core_graphics;
pub mod thin_core_video_sys;

pub use self::{cursor::*, r#async::*};

use std::ops::{BitAnd, Deref};

use cocoa::{
appkit::{NSApp, NSWindowStyleMask},
base::{id, nil},
foundation::{NSPoint, NSRect, NSString, NSUInteger},
};
use core_graphics::display::CGDisplay;
use objc::runtime::{Class, Object};
use thin_cocoa::{id, nil, NSApp, NSPoint, NSRect, NSString, NSUInteger, NSWindowStyleMask};
use thin_core_graphics::display::CGDisplay;

use crate::dpi::LogicalPosition;
use crate::platform_impl::platform::ffi;
Expand Down Expand Up @@ -159,7 +159,7 @@ pub unsafe fn open_emoji_picker() {
}

pub unsafe fn toggle_style_mask(window: id, view: id, mask: NSWindowStyleMask, on: bool) {
use cocoa::appkit::NSWindow;
use thin_cocoa::NSWindow;

let current_style_mask = window.styleMask();
if on {
Expand Down