-
Notifications
You must be signed in to change notification settings - Fork 717
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
Higher level objective-c support. #1722
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So as you may imagine I am not particularly an objc expert, so this review is mostly superficial.
I think this is not terrible, though it seems a bit weird to have struct_Foo
and interface_Foo
separated. I'd probably at least just make the struct be Foo
, if we're generating wrapped structs, wdyt?
The struct should probably be #[repr(transparent)]
, or at least some sort of ffi-safe representation.
I have a couple other questions about the code below... It'd probably take me a bit of time to do a proper review, may be useful to try to get @scoopr to take a look if they have the time. Pretty sure their feedback would be much more on-point than mine :)
Thanks for improving the ObjectiveC support btw, it's great! (Just realized that my comment above read a bit negative... sorry, quite late here :)). |
I was kind of just trying to keep with some of the conventions. Also part of the distinction between the two (
It wasn't too negative. I really appreciate the feedback. I'm just glad this is in the right direction. |
It was so long ago that I've effectively unloaded all that I remembered about this whole thing. But I'm really glad that there is progress on it again! Looking at the generated code, there is some Also not sure about the I'm also having hard time remembering what the blocker issues were for me to getting the foundation frameworks generated, but I remember being really close and the issues were kind of stupid but I didn't have the knowledge to workaround them. But if I had my blockers fixed, my next step that I was dreading to think, but I felt was quite necessary, was generating compatible types for frameworks separately. What I mean is, that when there is a foundation-sys crate that has NSString, that the uikit-sys you have could use (or depend on) those types, but I had no idea how to approach that (can I detect which framework the type came from?). That is a separate endeavor but thinking aloud, if you have any thoughts on it. EDIT: one of my blockers might of been the generics support that I saw you did earlier, nice! |
FWIW, the way I usually deal with this kind of stuff from C/C++ at least is to do the equivalent to blacklist |
I did a small test, and I got this to run! mod foundation;
use std::ffi;
use crate::foundation::NSLog;
use crate::foundation::struct_NSString;
use crate::foundation::NSString_NSStringExtensionMethods;
fn main() {
let nsstring = unsafe { struct_NSString::stringWithUTF8String_(
ffi::CString::new("Hello").unwrap().as_ptr()
) };
unsafe { NSLog( nsstring ); }
} For file generated from the whole Foundation on macos I think the trait bound for methods is not quite right, I had to comment out the one for Having all the protocols be separate traits causes us having to Some interesting tidbits from the generated code, which are not really about objc support,
This is really good progress! |
I like this idea. As it is now, in my test uikit-sys crate, it generates all the bindings for everything that UIKit depends on all the way up to the
I'm also not sure how I feel about it. I kinda like
Yeah, there's a lot of domain specific knowledge around these things. I hope to eventually put them in the bindgen book. My actual concern is usage of some of the protocol methods on This header:
produces
Something that would consume this would be:
I get this error:
Thoughts? |
You're implementing objc::Message on the |
I resolved it by changing the Deref implementation to be return I'm not big on having Also, in #109, the author mentions having Also, after messing around with
Seems a lot cleaner to me. wdyt? |
This comment has been minimized.
This comment has been minimized.
The last commit fixes the above issue I mentioned but now requires blacklisting of |
After a bit of thought and some testing on my uikit-sys bindings, I changed the names from Also, I've added @emilio @scoopr What do you guys think? Shall I fix CI and let's merge this? |
I'm excited this is going forward! I'm sorry that I don't have proper time to look at it for now though. On a cursory glance it looks like a good direction, though. The example you linked seems really clean looking! Shouldn't the unit tests be updated in the commit, the CI tests would pass, but also it is nicer to review what the expected output is. If I had the time, one thing I would like to look at is framework like Metal, where everything is just a protocol without concrete interfaces. But that's minor stuff. I suppose just having the CI go green, this could go in, and followup PRs could then improve it if further issues arise? |
Yes, that sounds like a good way forward. |
Some documentation about how are people supposed to use this would be great too, but doesn't need to block I guess :) |
Yup. That's the plan. I totally intend to add documentation to the book to use this along with all the annoying things you've gotta blacklist. My next PRs are going to be:
I'm just trying to keep this PR small as it's already pretty big.
I'm hoping publish a uikit-sys crate (and probably some sub-crates to deal with compile time) with this soon so, I'm sure I'll think of more features/issues and fix them. Anyway, I updated the tests to fix CI! 🚀 |
@emilio bump |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, and sorry for the lag (bindgen is not my full-time job).
This looks good to me with a few nits. Mind taking a look at the comment, squashing, and I'm happy to get this merged.
Thanks!
738d37d
to
e8136e5
Compare
e8136e5
to
1a1215e
Compare
Done and done! I just wanna say thanks @emilio, I'm really glad you maintain this project and keep the quality up when it comes these PRs. I hope I didn't come off pushy earlier. I'm just excited about having more complete objective-c support. |
Thank you! |
I took a whack at doing a bit of #109. There hasn't been much movement on the issue so I wanted some feedback on some of the trait constraints generated.
Here's a summary of the changes:
Foo
now has astruct_Foo
which wraps theid
as mentioned in Objective-C support #109.impl interface_Foo for id { all_the_trait_fns }
and replaced it withpub trait interface_Foo { all_the_trait_fns }
, and addedimpl interface_Foo for struct_Foo { }
. This allows some of the simple inheritance.Sized + std::ops::Deref + objc::Message
, to mimic the objc-foundation crate.impl struct_Foo { fn alloc() {...}}
for creation of methods.I still need to add animpl struct_Foo { fn alloc() {...}}
for the structs as a convenience method.Also, I think it might be useful to have things that return a different type from a given function to be of that wrapped type So, when a
interface_Foo
trait has a property of typeBar
, it'd returnBar(id)
. Thoughts?I've tested this out with generating bindings for a uikit-sys crate I've been working on and it compiles. That being said, it's still a WIP.