-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Add no_std
Support to bevy_math
#15810
Conversation
Co-Authored-By: Benjamin Brienen <benjamin.brienen@outlook.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few notes:
-
The purpose of the
ops
module is (or perhaps was) to guarantee that alternatives tostd
floating-point functions with unspecified precision were available, in the interest of cross-platform determinism. Sincelibm
isno_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
std
math 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_std
compatibility are actually discoverable. -
cubic_splines
is feature-gated behindalloc
, but plenty of other areas usealloc
as 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 <2975848+mweatherley@users.noreply.github.com> Co-Authored-By: Joona Aalto <jondolf.dev@gmail.com>
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`
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 <benjamin.brienen@outlook.com> Co-authored-by: Matty <2975848+mweatherley@users.noreply.github.com> Co-authored-by: Joona Aalto <jondolf.dev@gmail.com>
# 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 <benjamin.brienen@outlook.com> Co-authored-by: Matty <2975848+mweatherley@users.noreply.github.com> Co-authored-by: Joona Aalto <jondolf.dev@gmail.com>
Objective
no_std
Bevy #15460Solution
std
(default) andalloc
, gatingstd
andalloc
behind them respectively.f32
functions tostd_ops
as required. Thesef32
methods have been added to theclippy.toml
deny list to aid inno_std
development.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 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 thealloc
feature is enabled by default, this is not a breaking change.