-
Notifications
You must be signed in to change notification settings - Fork 72
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
Replace objc
with objc2
?
#28
Comments
100% on board, don’t even need to ask me twice. :)
I’ve been meaning to return to this and release 0.3 from the new branch anyway, so I could tie this into that.
Thanks for trying to make this stuff better! I’d thought about trying something similar about a year ago but couldn’t justify it in my list of things to do. :(
…On Sat, Jun 25, 2022 at 15:57, Mads Marquart ***@***.***> wrote:
Hey, macOS maintainer of winit here. I've been working on a replacement for objc called [objc2](https://github.com/madsmtm/objc2), and I think it could be interesting for this crate?
Some of the concrete improvements you'd reap benefit from, mainly in the category "improving correctness":
- Helper macro msg_send_id! for following cocoa's memory management rules - as a quick example, [NSString::new currently leaks](https://github.com/ryanmcgrath/cacao/blob/01d12396ef7a047a94949a528f8b7d70e88a6905/src/foundation/string.rs#L31) because it uses Id::from_ptr instead of Id::from_retained_ptr.
- Implementing Encode is now required for all types that go across msg_send! - this is great for catching bugs, for example [this code](https://github.com/ryanmcgrath/cacao/blob/f558f8e24d6c4f869a4135bd230222455a435dcf/src/listview/mod.rs#L404) in ListView::select_row_indexes is wrong, the type of index is &usize while it should be usize.
- Soundness fixes concerning message sending, autoreleasepools and reference counting.
I have an implementation of Foundation that you may be interested in using, at the very least it can be useful as an example of how to use objc2 well.
See also [my PR to the core-foundation-rs project](servo/core-foundation-rs#513).
Opening this issue to start the discussion, am a bit tired so sorry it's not more detailed. I would really like to work towards a completely safe interface over (the most commonly used parts of) Cocoa, but wanted to keep it out of the scope of objc2 itself - cacao seems like a nice work in that direction, would like to help out in this effort (other than just working on objc2).
—
Reply to this email directly, [view it on GitHub](#28), or [unsubscribe](https://github.com/notifications/unsubscribe-auth/AAAFROHUFQJ6XRAUBO2XKPTVQ6FF3ANCNFSM5Z27APDA).
You are receiving this because you are subscribed to this thread.Message ID: ***@***.***>
|
Yeah well, I thought about it a year ago, and it took me a year... Anyhow, wonderful that you're on board! I might whip up a PR at some point, focusing on the soundness stuff at first, should I target the Also, in |
If you get to it before I cut a 0.3, then yeah, Re: the format... I actually think |
Just to update - I haven't forgotten about these issues/PRs! Been incredibly busy the past week and a half, hoping to get to them soon. |
I know how it is, don't stress, I don't mind if it takes a few months! |
Just a heads up: I'm working on automatically generating bindings to all of AppKit and UIKit in madsmtm/objc2#264, which, combined with a few tricks to slowly carve out a safe subset (removing In effect, you'll basically never have to do |
Yeah, I'd seen mention of it before. :) The real question for me actually becomes whether cacao is worth it - not because your work erases it or anything, but Apple-specific UI work is in an odd place because most of the people looking to natively write apps for the platform are going to do it with the core languages (Swift/far increasingly less ObjC). Hard to gauge whether anyone would consume this crate. On the other hand, cacao does work around a lot of oddities... so there might still be a place for it. |
Also, something that is almost possible now using pub trait WebViewDelegate {
const NAME: &'static str;
fn on_message(&self, _name: &str, _body: &str) {}
// ...
}
declare_class!(
pub struct WebViewDelegateObject<T: WebViewDelegate> {
delegate: Ivarbox<Box<T>>,
}
unsafe impl<T: WebViewDelegate> ClassType for WebViewDelegateObject<T> {
type Super = NSObject;
const NAME: &'static str = <T as WebViewDelegate>::NAME;
}
unsafe impl<T: WebViewDelegate> Protocol<WKScriptMessageHandler> for WebViewDelegateObject {
#[sel(userContentController:didReceiveScriptMessage:)]
fn on_message(&self, _: &WKUserContentController, message: &WKScriptMessage) {
autoreleasepool(|pool| {
self.delegate.on_message(message.name().to_str(pool), message.body().as_str(pool))
})
}
// ...
}
);
pub struct WebView<T = ()> {
pub is_handle: bool,
pub obj: Id<WKWebView>,
pub layer: todo,
pub delegate: Option<Id<WebViewDelegateObject<T>>>,
// ... autolayout stuff
} |
I... Don't know about that - I guess it's hard for me to estimate what people actually want from Cocoa + Rust? What have you used it for yourself? I think a completely safe interface would be nice though, and while |
Heh, cacao originally started after I got tired of writing a cocoa backend for alchemy. Since then I've used it for small tools on my own, but nothing I've released yet - from what I can tell, others are the same. It's not something I'm deciding this instant anyway, and I'm mostly just openly musing on it. :) |
Following up on this: I've released Also to those that don't know, the automatic generation of AppKit is coming along pretty nicely, it's called |
I'm unsure what you think is the best way forward? In #30 (comment) you noted that you wanted to use The way I've been going about it was to slowly convert things to |
With |
Pretty much - e.g, I would not want to try to use a NSTableView with view reuse without cacao.
I’m happy to share the load with the ecosystem so I think this is all net good - though I can’t dig into Mads stuff until later this evening. Def want to get it merged tho.
…On Mon, Jul 31, 2023 at 18:21, Adam Gastineau ***@***.***(mailto:On Mon, Jul 31, 2023 at 18:21, Adam Gastineau <<a href=)> wrote:
With objc2 and the autogenerated API bindings, what role does Cacao serve? A Rust ergonomic interface to the underlying APIs?
—
Reply to this email directly, [view it on GitHub](#28 (comment)), or [unsubscribe](https://github.com/notifications/unsubscribe-auth/AAAFROA3GO7IH3XH74GJGPDXTBKYVANCNFSM5Z27APDA).
You are receiving this because you commented.Message ID: ***@***.***>
|
@madsmtm this is totally fine with me, yeah - it's likely the path of least resistance, no sense in making our lives harder. |
Hey, macOS maintainer of
winit
here. I've been working on a replacement forobjc
calledobjc2
, and I think it could be interesting for this crate?Some of the concrete improvements you'd reap benefit from, mainly in the category "improving correctness":
msg_send_id!
for following cocoa's memory management rules - as a quick example,NSString::new
currently leaks because it usesId::from_ptr
instead ofId::from_retained_ptr
.Encode
is now required for all types that go acrossmsg_send!
- this is great for catching bugs, for example this code inListView::select_row_indexes
is wrong, the type ofindex
is&usize
while it should beusize
.I have an implementation of
Foundation
that you may be interested in using, at the very least it can be useful as an example of how to useobjc2
well.See also my PR to the
core-foundation-rs
project.Opening this issue to start the discussion, am a bit tired so sorry it's not more detailed. I would really like to work towards a completely safe interface over (the most commonly used parts of) Cocoa, but wanted to keep it out of the scope of
objc2
itself -cacao
seems like a nice work in that direction, would like to help out in this effort (other than just working onobjc2
).The text was updated successfully, but these errors were encountered: