-
Notifications
You must be signed in to change notification settings - Fork 745
Option to use *mut objc::runtime::Object #1884
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
Comments
Hmm. Not really. You could try to blacklist some things but it's unclear how well that works and is liable to break some of the generated bindings. As of #1847, there are return types based on the structured objective-c names. Also, the Depending on what you're doing, putting the generated bindings in a sub-crate or another workspace (usually suffixed with |
Nevermind. Bindgen on objective-c files generates newtype structs containing pointers. Guess my first guess was correct. |
Where is this time spent? Can you use the whitelist to avoid generating most of the stuff you don't need? |
Probably parsing the entirety of I timed it, this #include <Cocoa/Cocoa.h>
struct BindgenHatesOpaque {
NSString* nsstring;
}; with
The project only contained an empty Additionally, this does not look opaque to me: https://hastebin.com/ihuqusawoh.rs This is okay: pub type id = *mut objc::runtime::Object;
#[repr(transparent)]
#[derive(Clone, Copy)]
pub struct NSString(pub id);
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct BindgenHatesOpaque {
pub nsstring: NSString,
} Since I asked for opaque, I don't need anything more. But bindgen decides to pull in all sorts of stuff, including stuff like NSCoder, NSData, NSZone etc...
Not really, because some struct pulls in NSView which inherits from something else which pulls in ... ... which has a method that returns ... ... ... ... 400,000 lines later ... As you can see above, specifying something as opaque has no effect and you could easily pull in hundreds of objects by accident. Sure, turning off recursion would almost work. That would require a manual typedef. Speaking of typedef, however, and luckily, the header file I'm generating bindings for doesn't actually have any Objective-C syntax in it. That brings me to my solution that doesn't even give bindgen any fluff to chew on... That's right. Void pointer to the rescue.
Ta-da, your C |
That's still terrible. We parse lots of C++ and never had such an issue where bindgen would take so long, there's likely a bad algorithm in the Objective-C specific code... Can you post the output of running bindgen with Ideally I'd take a perf profile of that but not sure how to do that with objective-c. |
So I think I figured out how to profile this from Linux, but this code crashes bindgen for me: @interface NSArray<__covariant ObjectType>
@property (readonly) unsigned count;
- (instancetype)initWithObjects:(const ObjectType [])objects count:(unsigned)cnt;
@end (We don't properly resolve the generic). cc @simlay, not sure if this crashes on mac and if not why not. |
Ok, so I worked around that for now... For reference, the way I'm profiling it is:
That takes about 6.933s on my machine. Which is not amazing. It seems like about 10% of the time is visiting clang cursors, so I guess there's a bunch of overhead from that which we may not be able to cut off. Then there's also rustfmt and the amount of items we generate. With Profiling only with There's a 12% of the time spent in There's a bunch of other stuff to optimize...
Anyhow, all in all, nice test-case :) |
What's weird about this As a side note, would there be some interest in some kind of bindgen "test suite" for objective-c that looks at a lot of the objective-c frameworks? I've got a repo that builds all the bindings for all the frameworks. Testing that repo against every PR on my personal system is frequently burdensome and it's not transparent on builds that a given thing compiles (or is actually runtime correct). Is there interest in adding something like this to CI? |
Basically, I have this header file that relies on some Objective-C types (NSString and stuff), but I don't want bindgen to spend 30 seconds generating hundreds of thousands of lines of useless bindings for them. I just want them all to be like
type NSString = *mut objc::runtime::Object
. Is it possible to do this?The text was updated successfully, but these errors were encountered: