Skip to content

Commit 0726ed8

Browse files
committed
Update objc2 crates
Changes relevant to Winit: - `icrate` has been deprecated in favour of separate crates per framework, in our case `objc2-foundation` and `objc2-app-kit` (and in the future `objc2-ui-kit` on iOS). - Moved `MainThreadMarker::run_on_main` to free-standing function `run_on_main`. - Changed how features work, this should result in less code that we need to compile. - Enums are now real structs instead of type-aliases and free constants.
1 parent 575d978 commit 0726ed8

38 files changed

+288
-269
lines changed

Cargo.toml

+55-42
Original file line numberDiff line numberDiff line change
@@ -88,58 +88,71 @@ ndk-sys = "0.5.0"
8888

8989
[target.'cfg(any(target_os = "ios", target_os = "macos"))'.dependencies]
9090
core-foundation = "0.9.3"
91-
objc2 = "0.5.0"
91+
objc2 = "0.5.1"
9292

9393
[target.'cfg(target_os = "macos")'.dependencies]
9494
core-graphics = "0.23.1"
9595

96-
[target.'cfg(target_os = "macos")'.dependencies.icrate]
97-
version = "0.1.0"
96+
[target.'cfg(target_os = "macos")'.dependencies.objc2-foundation]
97+
version = "0.2.0"
9898
features = [
9999
"dispatch",
100-
"Foundation",
101-
"Foundation_NSArray",
102-
"Foundation_NSAttributedString",
103-
"Foundation_NSMutableAttributedString",
104-
"Foundation_NSData",
105-
"Foundation_NSDictionary",
106-
"Foundation_NSString",
107-
"Foundation_NSProcessInfo",
108-
"Foundation_NSThread",
109-
"Foundation_NSNumber",
110-
"AppKit",
111-
"AppKit_NSAppearance",
112-
"AppKit_NSApplication",
113-
"AppKit_NSBitmapImageRep",
114-
"AppKit_NSButton",
115-
"AppKit_NSColor",
116-
"AppKit_NSControl",
117-
"AppKit_NSCursor",
118-
"AppKit_NSEvent",
119-
"AppKit_NSGraphicsContext",
120-
"AppKit_NSImage",
121-
"AppKit_NSImageRep",
122-
"AppKit_NSMenu",
123-
"AppKit_NSMenuItem",
124-
"AppKit_NSPasteboard",
125-
"AppKit_NSResponder",
126-
"AppKit_NSScreen",
127-
"AppKit_NSTextInputContext",
128-
"AppKit_NSView",
129-
"AppKit_NSWindow",
130-
"AppKit_NSWindowTabGroup",
100+
"NSArray",
101+
"NSAttributedString",
102+
"NSData",
103+
"NSDictionary",
104+
"NSEnumerator",
105+
"NSObjCRuntime",
106+
"NSString",
107+
"NSPathUtilities",
108+
"NSProcessInfo",
109+
"NSThread",
110+
"NSValue",
131111
]
132112

133-
[target.'cfg(target_os = "ios")'.dependencies.icrate]
134-
version = "0.1.0"
113+
[target.'cfg(target_os = "macos")'.dependencies.objc2-app-kit]
114+
version = "0.2.0"
115+
features = [
116+
"NSAppearance",
117+
"NSApplication",
118+
"NSBitmapImageRep",
119+
"NSButton",
120+
"NSColor",
121+
"NSControl",
122+
"NSCursor",
123+
"NSDragging",
124+
"NSEvent",
125+
"NSGraphics",
126+
"NSGraphicsContext",
127+
"NSImage",
128+
"NSImageRep",
129+
"NSMenu",
130+
"NSMenuItem",
131+
"NSOpenGLView",
132+
"NSPasteboard",
133+
"NSResponder",
134+
"NSRunningApplication",
135+
"NSScreen",
136+
"NSTextInputClient",
137+
"NSTextInputContext",
138+
"NSView",
139+
"NSWindow",
140+
"NSWindowScripting",
141+
"NSWindowTabGroup",
142+
]
143+
144+
[target.'cfg(target_os = "ios")'.dependencies.objc2-foundation]
145+
version = "0.2.0"
135146
features = [
136147
"dispatch",
137-
"Foundation",
138-
"Foundation_NSArray",
139-
"Foundation_NSString",
140-
"Foundation_NSProcessInfo",
141-
"Foundation_NSThread",
142-
"Foundation_NSSet",
148+
"NSArray",
149+
"NSEnumerator",
150+
"NSGeometry",
151+
"NSObjCRuntime",
152+
"NSString",
153+
"NSProcessInfo",
154+
"NSThread",
155+
"NSSet",
143156
]
144157

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

src/platform/ios.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ impl MonitorHandleExtIOS for MonitorHandle {
336336
#[inline]
337337
fn ui_screen(&self) -> *mut c_void {
338338
// SAFETY: The marker is only used to get the pointer of the screen
339-
let mtm = unsafe { icrate::Foundation::MainThreadMarker::new_unchecked() };
339+
let mtm = unsafe { objc2_foundation::MainThreadMarker::new_unchecked() };
340340
objc2::rc::Id::as_ptr(self.inner.ui_screen(mtm)) as *mut c_void
341341
}
342342

src/platform/macos.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ impl MonitorHandleExtMacOS for MonitorHandle {
383383

384384
fn ns_screen(&self) -> Option<*mut c_void> {
385385
// SAFETY: We only use the marker to get a pointer
386-
let mtm = unsafe { icrate::Foundation::MainThreadMarker::new_unchecked() };
386+
let mtm = unsafe { objc2_foundation::MainThreadMarker::new_unchecked() };
387387
self.inner
388388
.ns_screen(mtm)
389389
.map(|s| objc2::rc::Id::as_ptr(&s) as _)

src/platform_impl/ios/app_delegate.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use icrate::Foundation::{MainThreadMarker, NSObject, NSObjectProtocol};
21
use objc2::{declare_class, mutability, ClassType, DeclaredClass};
2+
use objc2_foundation::{MainThreadMarker, NSObject, NSObjectProtocol};
33

44
use super::app_state::{self, EventWrapper};
55
use super::uikit::{UIApplication, UIWindow};

src/platform_impl/ios/app_state.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ use core_foundation::runloop::{
1616
kCFRunLoopCommonModes, CFRunLoopAddTimer, CFRunLoopGetMain, CFRunLoopRef, CFRunLoopTimerCreate,
1717
CFRunLoopTimerInvalidate, CFRunLoopTimerRef, CFRunLoopTimerSetNextFireDate,
1818
};
19-
use icrate::Foundation::{
20-
CGRect, CGSize, MainThreadMarker, NSInteger, NSOperatingSystemVersion, NSProcessInfo,
21-
};
2219
use objc2::rc::Id;
2320
use objc2::runtime::AnyObject;
2421
use objc2::{msg_send, sel};
22+
use objc2_foundation::{
23+
CGRect, CGSize, MainThreadMarker, NSInteger, NSOperatingSystemVersion, NSProcessInfo,
24+
};
2525

2626
use super::uikit::UIView;
2727
use super::window::WinitUIWindow;

src/platform_impl/ios/event_loop.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ use core_foundation::runloop::{
1313
CFRunLoopObserverCreate, CFRunLoopObserverRef, CFRunLoopSourceContext, CFRunLoopSourceCreate,
1414
CFRunLoopSourceInvalidate, CFRunLoopSourceRef, CFRunLoopSourceSignal, CFRunLoopWakeUp,
1515
};
16-
use icrate::Foundation::{MainThreadMarker, NSString};
1716
use objc2::ClassType;
17+
use objc2_foundation::{MainThreadMarker, NSString};
1818

1919
use crate::{
2020
error::EventLoopError,

src/platform_impl/ios/monitor.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ use std::{
55
fmt, hash, ptr,
66
};
77

8-
use icrate::Foundation::{MainThreadBound, MainThreadMarker, NSInteger};
98
use objc2::mutability::IsRetainable;
109
use objc2::rc::Id;
1110
use objc2::Message;
11+
use objc2_foundation::{run_on_main, MainThreadBound, MainThreadMarker, NSInteger};
1212

1313
use super::uikit::{UIScreen, UIScreenMode};
1414
use crate::{
@@ -23,7 +23,7 @@ struct MainThreadBoundDelegateImpls<T>(MainThreadBound<Id<T>>);
2323

2424
impl<T: IsRetainable + Message> Clone for MainThreadBoundDelegateImpls<T> {
2525
fn clone(&self) -> Self {
26-
Self(MainThreadMarker::run_on_main(|mtm| {
26+
Self(run_on_main(|mtm| {
2727
MainThreadBound::new(Id::clone(self.0.get(mtm)), mtm)
2828
}))
2929
}
@@ -100,7 +100,7 @@ pub struct MonitorHandle {
100100

101101
impl Clone for MonitorHandle {
102102
fn clone(&self) -> Self {
103-
MainThreadMarker::run_on_main(|mtm| Self {
103+
run_on_main(|mtm| Self {
104104
ui_screen: MainThreadBound::new(self.ui_screen.get(mtm).clone(), mtm),
105105
})
106106
}
@@ -155,7 +155,7 @@ impl MonitorHandle {
155155
}
156156

157157
pub fn name(&self) -> Option<String> {
158-
MainThreadMarker::run_on_main(|mtm| {
158+
run_on_main(|mtm| {
159159
let main = UIScreen::main(mtm);
160160
if *self.ui_screen(mtm) == main {
161161
Some("Primary".to_string())
@@ -197,7 +197,7 @@ impl MonitorHandle {
197197
}
198198

199199
pub fn video_modes(&self) -> impl Iterator<Item = VideoModeHandle> {
200-
MainThreadMarker::run_on_main(|mtm| {
200+
run_on_main(|mtm| {
201201
let ui_screen = self.ui_screen(mtm);
202202
// Use Ord impl of RootVideoModeHandle
203203

@@ -218,7 +218,7 @@ impl MonitorHandle {
218218
}
219219

220220
pub fn preferred_video_mode(&self) -> VideoModeHandle {
221-
MainThreadMarker::run_on_main(|mtm| {
221+
run_on_main(|mtm| {
222222
VideoModeHandle::new(
223223
self.ui_screen(mtm).clone(),
224224
self.ui_screen(mtm).preferredMode().unwrap(),

src/platform_impl/ios/uikit/application.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use icrate::Foundation::{CGRect, MainThreadMarker, NSArray, NSObject};
21
use objc2::rc::Id;
32
use objc2::{extern_class, extern_methods, msg_send_id, mutability, ClassType};
3+
use objc2_foundation::{CGRect, MainThreadMarker, NSArray, NSObject};
44

55
use super::{UIResponder, UIWindow};
66

src/platform_impl/ios/uikit/coordinate_space.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use icrate::Foundation::NSObject;
21
use objc2::{extern_class, mutability, ClassType};
2+
use objc2_foundation::NSObject;
33

44
extern_class!(
55
#[derive(Debug, PartialEq, Eq, Hash)]

src/platform_impl/ios/uikit/device.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
use icrate::Foundation::{MainThreadMarker, NSInteger, NSObject};
21
use objc2::encode::{Encode, Encoding};
32
use objc2::rc::Id;
43
use objc2::{extern_class, extern_methods, msg_send_id, mutability, ClassType};
4+
use objc2_foundation::{MainThreadMarker, NSInteger, NSObject};
55

66
extern_class!(
77
#[derive(Debug, PartialEq, Eq, Hash)]

src/platform_impl/ios/uikit/event.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use icrate::Foundation::NSObject;
21
use objc2::{extern_class, mutability, ClassType};
2+
use objc2_foundation::NSObject;
33

44
extern_class!(
55
#[derive(Debug, PartialEq, Eq, Hash)]

src/platform_impl/ios/uikit/geometry.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use icrate::Foundation::NSUInteger;
21
use objc2::encode::{Encode, Encoding};
2+
use objc2_foundation::NSUInteger;
33

44
#[repr(transparent)]
55
#[derive(Clone, Copy, Debug, PartialEq, Eq)]

src/platform_impl/ios/uikit/gesture_recognizer.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
use icrate::Foundation::{CGFloat, NSInteger, NSObject, NSUInteger};
21
use objc2::{
32
encode::{Encode, Encoding},
43
extern_class, extern_methods, mutability, ClassType,
54
};
5+
use objc2_foundation::{CGFloat, NSInteger, NSObject, NSUInteger};
66

77
// https://developer.apple.com/documentation/uikit/uigesturerecognizer
88
extern_class!(

src/platform_impl/ios/uikit/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
use std::os::raw::{c_char, c_int};
55

6-
use icrate::Foundation::NSString;
6+
use objc2_foundation::NSString;
77

88
mod application;
99
mod coordinate_space;

src/platform_impl/ios/uikit/responder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use icrate::Foundation::NSObject;
21
use objc2::{extern_class, mutability, ClassType};
2+
use objc2_foundation::NSObject;
33

44
extern_class!(
55
#[derive(Debug, PartialEq, Eq, Hash)]

src/platform_impl/ios/uikit/screen.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
use icrate::Foundation::{CGFloat, CGRect, MainThreadMarker, NSArray, NSInteger, NSObject};
21
use objc2::encode::{Encode, Encoding};
32
use objc2::rc::Id;
43
use objc2::{extern_class, extern_methods, msg_send_id, mutability, ClassType};
4+
use objc2_foundation::{CGFloat, CGRect, MainThreadMarker, NSArray, NSInteger, NSObject};
55

66
use super::{UICoordinateSpace, UIScreenMode};
77

src/platform_impl/ios/uikit/screen_mode.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use icrate::Foundation::{CGSize, NSObject};
21
use objc2::{extern_class, extern_methods, mutability, ClassType};
2+
use objc2_foundation::{CGSize, NSObject};
33

44
extern_class!(
55
#[derive(Debug, PartialEq, Eq, Hash)]

src/platform_impl/ios/uikit/status_bar_style.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use icrate::Foundation::NSInteger;
1+
use objc2_foundation::NSInteger;
22
use objc2::encode::{Encode, Encoding};
33

44
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]

src/platform_impl/ios/uikit/touch.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use icrate::Foundation::{CGFloat, CGPoint, NSInteger, NSObject};
21
use objc2::encode::{Encode, Encoding};
32
use objc2::{extern_class, extern_methods, mutability, ClassType};
3+
use objc2_foundation::{CGFloat, CGPoint, NSInteger, NSObject};
44

55
use super::UIView;
66

src/platform_impl/ios/uikit/trait_collection.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use icrate::Foundation::{NSInteger, NSObject};
21
use objc2::encode::{Encode, Encoding};
32
use objc2::{extern_class, extern_methods, mutability, ClassType};
3+
use objc2_foundation::{NSInteger, NSObject};
44

55
extern_class!(
66
#[derive(Debug, PartialEq, Eq, Hash)]

src/platform_impl/ios/uikit/view.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
use icrate::Foundation::{CGFloat, CGRect, NSObject};
21
use objc2::encode::{Encode, Encoding};
32
use objc2::rc::Id;
43
use objc2::{extern_class, extern_methods, msg_send_id, mutability, ClassType};
4+
use objc2_foundation::{CGFloat, CGRect, NSObject};
55

66
use super::{UICoordinateSpace, UIGestureRecognizer, UIResponder, UIViewController};
77

src/platform_impl/ios/uikit/view_controller.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
use icrate::Foundation::{NSObject, NSUInteger};
21
use objc2::encode::{Encode, Encoding};
32
use objc2::rc::Id;
43
use objc2::{extern_class, extern_methods, msg_send_id, mutability, ClassType};
4+
use objc2_foundation::{NSObject, NSUInteger};
55

66
use super::{UIResponder, UIView};
77

src/platform_impl/ios/uikit/window.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use icrate::Foundation::NSObject;
21
use objc2::rc::Id;
32
use objc2::{extern_class, extern_methods, msg_send_id, mutability, ClassType};
3+
use objc2_foundation::NSObject;
44

55
use super::{UIResponder, UIScreen, UIView};
66

src/platform_impl/ios/view.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#![allow(clippy::unnecessary_cast)]
22
use std::cell::RefCell;
33

4-
use icrate::Foundation::{CGFloat, CGRect, MainThreadMarker, NSObject, NSSet};
54
use objc2::rc::Id;
65
use objc2::runtime::AnyClass;
76
use objc2::{
87
declare_class, extern_methods, msg_send, msg_send_id, mutability, sel, ClassType, DeclaredClass,
98
};
9+
use objc2_foundation::{CGFloat, CGRect, MainThreadMarker, NSObject, NSSet};
1010

1111
use super::app_state::{self, EventWrapper};
1212
use super::uikit::{

src/platform_impl/ios/view_controller.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use std::cell::Cell;
22

3-
use icrate::Foundation::{MainThreadMarker, NSObject};
43
use objc2::rc::Id;
54
use objc2::{declare_class, msg_send_id, mutability, ClassType, DeclaredClass};
5+
use objc2_foundation::{MainThreadMarker, NSObject};
66

77
use super::app_state::{self};
88
use super::uikit::{

src/platform_impl/ios/window.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
use std::collections::VecDeque;
44

5-
use icrate::Foundation::{CGFloat, CGPoint, CGRect, CGSize, MainThreadBound, MainThreadMarker};
65
use objc2::rc::Id;
76
use objc2::runtime::{AnyObject, NSObject};
87
use objc2::{class, declare_class, msg_send, msg_send_id, mutability, ClassType, DeclaredClass};
8+
use objc2_foundation::{CGFloat, CGPoint, CGRect, CGSize, MainThreadBound, MainThreadMarker};
99
use tracing::{debug, warn};
1010

1111
use super::app_state::EventWrapper;

0 commit comments

Comments
 (0)