Skip to content
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 #14172

Open
ScottKane opened this issue Jul 6, 2024 · 2 comments
Open

Feature flag to add repr(c) to bevy types #14172

ScottKane opened this issue Jul 6, 2024 · 2 comments
Labels
A-Cross-Cutting Impacts the entire engine A-Modding Supporting infrastructure for player-controlled modifications to games C-Feature A new feature, making something new possible X-Controversial There is active debate or serious implications around merging this PR

Comments

@ScottKane
Copy link

What problem does this solve or what need does it fill?

I am developing bindings to bevy in C# using the new QueryBuilder/SytemBuilder API's. I am at the point where I can spawn entities with componenets and have systems run against them. This currently only works for custom types definied on the C# side as there is no nice way to pass a bevy Transform or math/bundle types over FFI.

What solution would you like?

Add a repr-c feature which would tag relevant structs in components/math/bundles with a repr(c) allowing them to be passed over FFI without duplication/hacky solutions.

Something like:

#[derive(Debug, PartialEq, Clone, Copy)]
#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(
    feature = "bevy-support",
    derive(Component, Reflect),
    reflect(Component, Default, PartialEq)
)]
#[cfg_attr(feature = "repr-c", repr(C))]
pub struct Transform {
    /// Position of the entity. In 2d, the last value of the `Vec3` is used for z-ordering.
    ///
    /// See the [`translations`] example for usage.
    ///
    /// [`translations`]: https://github.com/bevyengine/bevy/blob/latest/examples/transforms/translation.rs
    pub translation: Vec3,
    /// Rotation of the entity.
    ///
    /// See the [`3d_rotation`] example for usage.
    ///
    /// [`3d_rotation`]: https://github.com/bevyengine/bevy/blob/latest/examples/transforms/3d_rotation.rs
    pub rotation: Quat,
    /// Scale of the entity.
    ///
    /// See the [`scale`] example for usage.
    ///
    /// [`scale`]: https://github.com/bevyengine/bevy/blob/latest/examples/transforms/scale.rs
    pub scale: Vec3,
}

What alternative(s) have you considered?

I would either have to duplicate all of the component/math/bundle types into my rust library or devise some way to calculate the struct layout so I can match it from C#.

@ScottKane ScottKane added C-Feature A new feature, making something new possible S-Needs-Triage This issue needs to be labelled labels Jul 6, 2024
@alice-i-cecile alice-i-cecile added A-Modding Supporting infrastructure for player-controlled modifications to games X-Controversial There is active debate or serious implications around merging this PR A-Cross-Cutting Impacts the entire engine and removed S-Needs-Triage This issue needs to be labelled labels Jul 6, 2024
@ScottKane
Copy link
Author

So far the biggest problem I can see with implementing this is that some types that come from glam aren't repr(C) so would need some work to get this feature working. Does anyone have any suggestions?

@ScottKane
Copy link
Author

Could be an issue as glam is using simd vector types which right now dont work properly over FFI:

rust-lang/rust#53346

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Cross-Cutting Impacts the entire engine A-Modding Supporting infrastructure for player-controlled modifications to games C-Feature A new feature, making something new possible X-Controversial There is active debate or serious implications around merging this PR
Projects
None yet
Development

No branches or pull requests

2 participants