Add no_std Support to bevy_math#15810
Conversation
Co-Authored-By: Benjamin Brienen <[email protected]>
mweatherley
left a comment
There was a problem hiding this comment.
A few notes:
-
The purpose of the
opsmodule is (or perhaps was) to guarantee that alternatives tostdfloating-point functions with unspecified precision were available, in the interest of cross-platform determinism. Sincelibmisno_std-compatible, I think this extension of that is pretty reasonable, but this is a break from its original purpose. -
I have concerns about the ongoing maintenance burden of these changes. For example, we lint against
stdmath operations with unspecified precision for the aforementioned determinism reasons; right now, as far as I'm aware, this doesn't extend to the new methods added, so I'm not sure if breaks tono_stdcompatibility are actually discoverable. -
cubic_splinesis feature-gated behindalloc, but plenty of other areas useallocas well. What is the logic behind this?
That makes sense, thanks for clarifying the original intent of the module for me! I think to highlight this change in intent I'll update the module documentation to say there are two reasons you'd want to use
I'll look into adding these new methods to the lint as well, with some documentation explaining that it's for
My reasoning here was I saw a large amount of |
- Only referenced new `ops` methods via `ops` namespace (no direct import) - Moved the new `no_std` ops into their own module within `ops` to clarify intent - Updated documentation for `ops` module clarifying it can also be used to assist with `no_std` compatibility - Moved `alloc` feature gate to within `cubic_spline` to clarify which items require its inclusion - Updated tests to improve compatibility with `no_std` environments - Added `f32` methods which are not available in `no_std` to the `clippy.toml` deny list with an explanation around the `no_std` compatibility. Co-Authored-By: Matty <[email protected]> Co-Authored-By: Joona Aalto <[email protected]>
|
Added to the 0.16 milestone to indicate this is not intended to be merged during the 0.15 release cycle. |
Also fixed issues with `serialize` being enabled without `alloc`
Jondolf
left a comment
There was a problem hiding this comment.
This does increase maintenance burden somewhat / make some things slightly uglier, but I would say it's worth it for no_std support, and to move the no_std efforts as a whole forward. Changes look good to me, didn't notice anything wrong.
mweatherley
left a comment
There was a problem hiding this comment.
Just one thing that I found kind of confusing at first glance.
My main concern with this is just making sure that we have enough tools (in CI or otherwise) to maintain this matrix of features without breaking compilation in some combination.
Reduces line-count, and generally preferred.
Idea is to provide a standard set of names for maths functions which are normally provided by `std::f32` but might not be on `no_std` platforms.
Agreed. I've added |
# Objective - Contributes to #15460 ## Solution - Added two new features, `std` (default) and `alloc`, gating `std` and `alloc` behind them respectively. - Added missing `f32` functions to `std_ops` as required. These `f32` methods have been added to the `clippy.toml` deny list to aid in `no_std` development. ## Testing - CI - `cargo clippy -p bevy_math --no-default-features --features libm --target "x86_64-unknown-none"` - `cargo test -p bevy_math --no-default-features --features libm` - `cargo test -p bevy_math --no-default-features --features "libm, alloc"` - `cargo test -p bevy_math --no-default-features --features "libm, alloc, std"` - `cargo test -p bevy_math --no-default-features --features "std"` ## Notes The following items require the `alloc` feature to be enabled: - `CubicBSpline` - `CubicBezier` - `CubicCardinalSpline` - `CubicCurve` - `CubicGenerator` - `CubicHermite` - `CubicNurbs` - `CyclicCubicGenerator` - `RationalCurve` - `RationalGenerator` - `BoxedPolygon` - `BoxedPolyline2d` - `BoxedPolyline3d` - `SampleCurve` - `SampleAutoCurve` - `UnevenSampleCurve` - `UnevenSampleAutoCurve` - `EvenCore` - `UnevenCore` - `ChunkedUnevenCore` This requirement could be relaxed in certain cases, but I had erred on the side of gating rather than modifying. Since `no_std` is a new set of platforms we are adding support to, and the `alloc` feature is enabled by default, this is not a breaking change. --------- Co-authored-by: Benjamin Brienen <[email protected]> Co-authored-by: Matty <[email protected]> Co-authored-by: Joona Aalto <[email protected]>
# Objective - Contributes to bevyengine#15460 ## Solution - Added two new features, `std` (default) and `alloc`, gating `std` and `alloc` behind them respectively. - Added missing `f32` functions to `std_ops` as required. These `f32` methods have been added to the `clippy.toml` deny list to aid in `no_std` development. ## Testing - CI - `cargo clippy -p bevy_math --no-default-features --features libm --target "x86_64-unknown-none"` - `cargo test -p bevy_math --no-default-features --features libm` - `cargo test -p bevy_math --no-default-features --features "libm, alloc"` - `cargo test -p bevy_math --no-default-features --features "libm, alloc, std"` - `cargo test -p bevy_math --no-default-features --features "std"` ## Notes The following items require the `alloc` feature to be enabled: - `CubicBSpline` - `CubicBezier` - `CubicCardinalSpline` - `CubicCurve` - `CubicGenerator` - `CubicHermite` - `CubicNurbs` - `CyclicCubicGenerator` - `RationalCurve` - `RationalGenerator` - `BoxedPolygon` - `BoxedPolyline2d` - `BoxedPolyline3d` - `SampleCurve` - `SampleAutoCurve` - `UnevenSampleCurve` - `UnevenSampleAutoCurve` - `EvenCore` - `UnevenCore` - `ChunkedUnevenCore` This requirement could be relaxed in certain cases, but I had erred on the side of gating rather than modifying. Since `no_std` is a new set of platforms we are adding support to, and the `alloc` feature is enabled by default, this is not a breaking change. --------- Co-authored-by: Benjamin Brienen <[email protected]> Co-authored-by: Matty <[email protected]> Co-authored-by: Joona Aalto <[email protected]>
Objective
no_stdBevy #15460Solution
std(default) andalloc, gatingstdandallocbehind them respectively.f32functions tostd_opsas required. Thesef32methods have been added to theclippy.tomldeny list to aid inno_stddevelopment.Testing
cargo clippy -p bevy_math --no-default-features --features libm --target "x86_64-unknown-none"cargo test -p bevy_math --no-default-features --features libmcargo test -p bevy_math --no-default-features --features "libm, alloc"cargo test -p bevy_math --no-default-features --features "libm, alloc, std"cargo test -p bevy_math --no-default-features --features "std"Notes
The following items require the
allocfeature to be enabled:CubicBSplineCubicBezierCubicCardinalSplineCubicCurveCubicGeneratorCubicHermiteCubicNurbsCyclicCubicGeneratorRationalCurveRationalGeneratorBoxedPolygonBoxedPolyline2dBoxedPolyline3dSampleCurveSampleAutoCurveUnevenSampleCurveUnevenSampleAutoCurveEvenCoreUnevenCoreChunkedUnevenCoreThis requirement could be relaxed in certain cases, but I had erred on the side of gating rather than modifying. Since
no_stdis a new set of platforms we are adding support to, and theallocfeature is enabled by default, this is not a breaking change.