-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
dart:ffi generate Dart bindings from C headers #35843
Comments
|
Hi, do we have rough estimation when can we have the first preview of this? within a month, a quarter or a year? |
Unfortunately we aren't planning to ship this feature in the first release, but it's possible to implement this functionality as tool outside the VM. For example, you could bind to |
Thanks, your suggested solution seems to be interesting to be taken by the community 😄 |
The
I think it should be even possible from the .h-file.
Yes, that's nice. (As mentioned before, I think building generator in the first place is the first step, the second step would be to hook it into the
We should reuse
This is extra work, I agree.
Yes. If we opt for a dart->dart generator, the users of your package would have to do this step manually over and over again.
I think it makes perfect sense to prefer a fluent API. :) We can sollicit input here from potential users what they would like to see as an API, but as a package developer your preference is very welcome :)
I'm not sure why it should not be. Can you elaborate or give an example?
See my comments inline. I think I'd prefer generating from .h files, because that would require package users to do nothing besides pointing the builder to the .h-files. Unless I'm missing something, and the .h-files miss information that has to be specified in a .dart file. |
Inspiration from Kotlin:
Source: https://kotlinlang.org/docs/tutorials/native/mapping-strings-from-c.html The reason for
Source: https://github.com/JetBrains/kotlin-native/blob/master/INTEROP.md#definition-file-hints |
For people interested in generating bindings for Objective-C libraries, it might be worth mentioning that cupertino_ffi has necessary helpers, but it still requires Dart SDK to implement #38578 . |
Project Panama (Java's new FFI) is also heavily invested in generating bindings from header files. Sources: |
|
Jextract is part of project panama, and Swig is a stand alone project, so they are definitely not equivalent. Jextract takes in an unmodified h file (see these samples). Swig takes in a swig file, but that can sometimes be just an h file:
http://www.swig.org/tutorial.html I think both approaches are fine. However, both approaches will be very different to implement:
|
I saw a few examples of using Jextract and SWIG (python) and both involved generating bindings from headers. So that made me think that they are doing the same thing. Well, now the difference is clear.
I'd love to do that. Is somebody already working on this?
Thanks for the insights @dcharkes . |
Hi, I'm working on the bindings to libclang. |
Hi @ctrysbita , |
@bitbeast18 That means user need to compile C wrapper manually. Maybe wait for official support of pass-by-value is better XD. By the way, I think pub may need functions to handle native code building like node-gyp? |
See #36712 for the current "solutions" for shipping native code. Yes, we definitely want a better solution for pub!
That is the way to go for the time being.
I'm working on it, but it will take some time. |
I've temporary solved it by writing a wrapper for the functions return/need a value. Now these necessary functions from libclang work well and we can parse C/C++ code and traverse through AST from dart side. However, the native code ships together with package means every user have to build native library manually after |
Yeah, it's either letting the users building the native code. Or committing the built binaries in the package for a range of OS/hardware combinations. See the discussion in #36712 (comment). |
I'm working on binding of native. But it depends on dart_native, which is a bridge between dart and iOS/Android using dart ffi. |
@mannprerak2 will work on this as a Google Summer of Code project! 🎉 Stay tuned for more! |
As a user of Nim also, the c2nim tool is pretty neat and can also serve as inspiration. It takes a C header (or C file actually) and produces a Nim file from it. You can modify the header files using |
An experimental FFI binding generator is now available: https://pub.dev/packages/ffigen! 🎉 Please check it out and leave your feedback and suggestions in the issue tracker: https://github.com/dart-lang/ffigen/issues. |
We have released |
Maintaining bindings by hand is error-prone, especially across different versions. We should have a tool that can generate Dart bindings from C Headers.
Update: see https://pub.dev/packages/ffigen.
The text was updated successfully, but these errors were encountered: