-
Notifications
You must be signed in to change notification settings - Fork 67
Generated ffi_bindings.dart.m doesn't handle platform differences #1469
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
Can you share your ffigen config? Usually when I specify entry point headers, there's a mac or ios in the path. So if you've got significant platform differences, maybe you need a separate ffigen run for ios vs macos?
If the classes you don't want are gated behind ifdefs, you could just add those defines to the |
@liamappelbe Does this also occur in the platform headers that we might want to pre-generate a package for? Because then we'd really like to avoid duplicating all of them? Or maybe in general we'd like to avoid duplicating. (Both the Dart and objc generated code.) Some thoughts for if we want to solve this:
|
In this case the relevant entry point is my own header within the plugin, where I have a class that has one
I have probably 95% shared code, and one platform difference. I'm not clear on how separate ffigen runs would work. The result would be two large Dart files that are almost all identical, and two native files that are maybe half identical (much more once I can do method filtering to get rid of all the parts I don't want). On the native side, I could fully conditionally compile them (although conceptually it would be a bit weird because of the duplication), but what would I do on the Dart side? Import both of them prefixed, and arbitrary use one almost all of the time? That would be weird, because I'd have a bunch of cross-platform code using, say
In this particular case I could probably restructure things artificially to hide this difference from ffigen-visible headers, but that's not going to be the case in general. What if we want to convert It isn't that I don't want the classes, it's that they only exist on, and can thus only be compiled for, one of the two platforms I'm implementing. |
Right, we could be generating the Dart wrappers as the union of everything (except for conflicts). This would be similar to an API not being available on either MacOS/iOS (#1338). However, the generated objective swift code should be ifdeffed. Maybe we can try to run libclang twice (the parse step) and pass in (As an even deeper question, what about C code that is if-deffed differently for Windows vs Linux vs MacOS etc.? We have so far not supported that at all. We don't generate native code for normal C bindings. But we also don't merge the Dart bindings.) |
clang might give me the availability info I need without running twice. If so, I can scan each block signature, and put them behind ifdefs if any of the args or returns are platform specific. Actually I thought of a way simpler solution, but it's a bit of a kludge. All these trampolines are doing is calling retain, so I don't actually care what type the arg is. I can probably just use |
I'm using
ffigen
on code that supports both iOS and macOS, and because of #1439 I'm ending up with a bunch of macOS-specific types likeNSMenu
inffi_bindings.dart.m
. There's no target platform#ifdef
ing in the generated file, so it doesn't compile on iOS. (In my case I think it will compile on macOS, but it wouldn't be hard to construct a situation where it wouldn't compile on either one.)Ideally the transitive walk of headers should track platform ifdefs, and then automatically ifdef accordingly in the generated file. Failing that, a manual workaround could be a way to list platform exclusions in the ffigen config file.
The text was updated successfully, but these errors were encountered: