-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
Feature flag to add repr(c) to bevy types #14362
base: main
Are you sure you want to change the base?
Conversation
Welcome, new contributor! Please make sure you've read our contributing guide and we look forward to reviewing your pull request shortly ✨ |
There is still some work to get bundle types working over FFI but this initial work allows the passing of core types like |
I can't really comment on the validity of this, but I want to mention that this PR looks prone to suffering from merge conflicts due to the amount of code touched, so it would be nice to get it sorted quickly. @ScottKane I notice that there is also a lot of tiny refactoring in this PR. While that is generally appreciated, I think it will make life harder for you in this case, as it makes an already large and controversial PR harder to review and increases the chance that you run into merge conflicts. |
Do you have a specific use-case for For instance, I could see how this would be useful when working with dynamic libraries, but actual C FFI is far less compelling. (And even then, the amount of generics we use limits dynamic libraries significantly.) |
I would be much more inclined towards moving forward with this if the needed changes involving quaternions or whatever were made upstream in |
@janhohenheim the minor changes are there to support calling functions using the Quat wrapper, the alternative would be the user having to call .into() everywhere which felt like a bad idea. @BD103 I am currently writing C# bindings for bevy using the new dynamic API's (SystemBuilder/QueryBuilder) and this work allows bevy built-ins to be shared with the C# implementation, the alternative would be that anyone wanting to bind to bevy would have to duplicate all of these types into their native code to allow it to pass over FFI. For the most part ignoring the @mweatherley I agree, I could open a PR in glam with this Quat code which would massively reduce the complexity of maintaining this. If I can get that PR accepted into glam I will amend this PR to update glam version and only add conditional repr(C)'s where needed. |
Ok. That reasoning makes sense, though I think a maintainer should probably weigh in here as well. I'm going to mark this as "waiting for author" until the |
Objective
To add repr(C) to bevy types that could/should be able to be sent over FFI behind a feature flag.
Solution
Added
repr_c
feature which propagates to relevant crates to conditionally add#[repr(C)]
to bevy built in component/math/bundle types.Testing
I have run through the test suite with everything working as expected, I have also created test bevy apps to compare struct layouts being as expected and working correctly. I have also tested with my C# bindings to bevy (the original motivation behind this PR) to ensure the struct layout for all types is correct when sent over FFI.
This has only been tested on Fedora x86 64.
Migration Guide
There aren't any breaking changes as such however there is a few minor changes in some function calls that depend on
glam::Quat
, the reason for this is that#[repr(simd)]
types currently aren't compatible with FFI (see rust-lang/rust#53346) so I had to create a wrapper type that can switch between the glam version and a repr(C) compatible Quat. As a result of this, the glam types we are using have functions that expect aglam::Quat
and not the new wrapper. I have moved these specific functions into the wrapper for now but I think the best option would likely be to have wrappers for all of the glam types we use so the usage would stay exactly the same.