-
Notifications
You must be signed in to change notification settings - Fork 43
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
Support size_t, int, and other common C types // platform independent bindings #530
Comments
We can map the three 3 types that we already support to the right |
Why does |
Ffigen will usually disregard the type name, types like If |
This is blocked by dart-lang/sdk#42563. When that is added to |
I understand the complete solution is blocked by not having a proper matching type. but I still think changing to
|
Using In its current form, @mannprerak2, does our current configuration allow users to overwrite what type is generated by matching the name of the C type and then selecting the name for the Dart type to be generated? (If I'm not mistaken, we can only match on name and select a size, correct?) It might be worth implementing this as a workaround for the time being such that users can opt in to that. I'll leave that decision up to you. The final solution should be multi platform bindings, but it might be some time until we get around to dart-lang/sdk#42563. |
Our current configuration has Internally, however, we map So we can just expose this to the users as a config option. Something like typedef-map:
'size_t': 'IntPtr` |
@dcharkes @vaind |
Just following up on this. For our use case it would be really useful if the Dart code generated by |
This issue is blocked in We'll address it once that is supported. |
@dcharkes -- looks like the blocking issue landed, any update on this? |
Yeah, I guess we can start working on this now. Any idea when this will be available on the latest dev channel? |
When we release a dev build after Version 2.16.0-118.0.dev. P.S. Feel free to copy https://github.com/dart-lang/sdk/blob/main/tests/ffi/abi_specific_ints.dart into ffigen for code generation until I move them to |
I guess I'll atleast wait for the dev release. I've been thinking about how to expose this in ffigen. Here's what I came up with -
library-imports:
my_lib: 'package:my_app/some/file.dart'
type-map:
'wchar_t':
'lib': 'ffi'
'type': 'Int32'
'unsigned int':
'lib': 'pkg_ffi'
'type': 'UintPtr'
wdyt @dcharkes ? |
I like it. We want to name the library imports to avoid name clashes in generated code I presume? It would be slightly more convenient for users if we don't prefix the imports, and the list of libraries is just a list and the type-map is a simple map. library-imports:
- 'package:my_app/some/file.dart'
type-map:
'wchar_t' : 'WChar' But I'm not sure if we can make the prefixes optional. It would work in the type map. But it would not work in the libraries (something cannot have list and map entries in yaml). library-imports:
- 'package:my_app/some/file.dart'
my_other_lib : 'package:my_other_lib/some/file.dart' #invalid yaml?
type-map:
'wchar_t' : 'WChar'
'unsigned int':
'lib': 'my_other_lib'
'type': 'UintPtr' |
Primarily yes. |
@cmc5788 checkout ffigen(5.0.0-dev.0), it uses ffi(1.2.0-dev.0) to generate platform specific ints. |
Now that Dart 2.17 is out, can we use the types from |
You mean running test/regen.dart? There's been some debate around whether those generated goldens are a good way of writing tests, and this is a pretty good argument against them. I hadn't considered that they make it hard to contribute code from non-mac devices. Now I'm thinking we should remove them, at least for tests that are platform dependent. I'll file a separate bug about this. |
A |
We should support generating some
dart:ffi
type forsize_t
,int
,long
, etc., whendart:ffi
starts supporting this: dart-lang/sdk#36140.Example
Comparing generated files on Linux x64 and MacOS x64 which uses
size_t
:The lack of 'named' integer types that vary in size on different platforms currently makes ffigen only generate correct bindings for its host platform. In order to make ffigen generate platform independent bindings we should address this issue.
The text was updated successfully, but these errors were encountered: