madsmtm / objc2

Bindings to Apple's frameworks in Rust
https://docs.rs/objc2/
MIT License
281 stars 35 forks source link

Split `icrate` into one crate per framework #592

Closed madsmtm closed 1 month ago

madsmtm commented 2 months ago

Fixes https://github.com/madsmtm/objc2/issues/537. Fixes https://github.com/madsmtm/objc2/issues/558. Fixes https://github.com/madsmtm/objc2/issues/482. Required for https://github.com/madsmtm/objc2/issues/408.

This should also improve compile times a bit, as Cargo can parallelize it much more, and it doesn't suffer from long download times.

The submodule path has been changed, in case git doesn't really show it you can view https://github.com/madsmtm/objc2-generated/commit/cf3442835f6121edbad2336eae871321cabc83a4 for the changed commit.

I'm fairly sure that the way we've chosen to do features won't turn into a breaking change, at the very least, #import <WebKit/WebView.h> makes the same, if not more types available to Objective-C, so it really shouldn't.

TODO:

MediaEnhanced commented 1 month ago

I tried this branch out with a very basic NSApplication, one NSWindow, slightly custom NSEvent, example and could only get it to compile (and run) after performing the following find and replaces over the generated files: use crate::AppKit::*; -> use crate::*; use crate::CoreData::*; -> use objc2_core_data::*; use crate::Foundation::*; -> use objc2_foundation::*; use crate::common::*; -> use objc2_helpers::*;

Not sure if that part in the "header-translator" has to be updated as this branch is WIP or if I setup something incorrectly. I also needed to remove the function feature restrictions for certain cross-framework restricted functions such as: NSWindow::initWithContentRect_styleMask_backing_defer and others even though my Cargo.toml had the following:

objc2 = { path = "src/icrate/crates/objc2" }
objc2-foundation = { path = "src/icrate/framework-crates/objc2-foundation", features = [
"Foundation_NSString",
"Foundation_NSGeometry",
"Foundation_NSNotification",
"Foundation_NSObject",
"Foundation_NSDate",
"Foundation_NSThread",
"Foundation_NSRunLoop",
"Foundation_NSObjCRuntime",
] }
objc2-app-kit = { path = "src/icrate/framework-crates/objc2-app-kit", features = [
"AppKit_NSApplication",
"AppKit_NSRunningApplication",
"AppKit_NSGraphics",
"AppKit_NSGraphicsContext",
"AppKit_NSEvent",
"AppKit_NSWindow",
"AppKit_NSResponder",
] }

This branch did seem to build faster on my 2010 iMac compared to the master branch!

madsmtm commented 1 month ago

The development here has been... quite haphazard. Will try to get it into a better state soon!

But I suspect that the issue you've been hitting is that git doesn't really like changing the path of a submodule, so you have to somehow tell it to re-initialize it - which I did manually by moving some directories, but there probably is a proper way of doing it.