Skip to content

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

Closed
@ScottKane

Description

@ScottKane

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#.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-Cross-CuttingImpacts the entire engineC-FeatureA new feature, making something new possibleX-ControversialThere is active debate or serious implications around merging this PR

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions