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

Clarify that libm is needed for no_std #415

Open
ChocolateLoverRaj opened this issue Aug 17, 2024 · 7 comments
Open

Clarify that libm is needed for no_std #415

ChocolateLoverRaj opened this issue Aug 17, 2024 · 7 comments
Labels
documentation Related to things like README or the API documentation.

Comments

@ChocolateLoverRaj
Copy link

There are tons of errors when trying to build palette with --no-default-features.

How To Reproduce

  • Can reproduce on cargo 1.82.0-nightly (2f738d617 2024-08-13) and cargo 1.80.1 (376290515 2024-07-16)
  • Clone this repo
  • cd palette
  • Run cargo b --no-default-features

Expected Outcome

Builds without errors

Actual Outcome

32 errors. Here is one of them:

error[E0277]: the trait bound `f32: Round` is not satisfied
   --> palette/src/angle.rs:127:40
    |
127 |                     self - Round::ceil(((self + 180.0) / 360.0) - 1.0) * 360.0
    |                            ----------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Round` is not implemented for `f32`
    |                            |
    |                            required by a bound introduced by this call
...
179 | impl_angle_float!(f32, f64);
    | --------------------------- in this macro invocation
    |
help: this trait has no implementations, consider adding one
   --> palette/src/num.rs:234:1
    |
234 | pub trait Round {
    | ^^^^^^^^^^^^^^^
    = note: this error originates in the macro `impl_angle_float` (in Nightly builds, run with -Z macro-backtrace for more info)

Additional Details

I am trying to use palette on the thumbv6m-none-eabi target. I am trying to use palette to control the onboard RGB LED on a RP2040 Zero.

  • Cargo.toml entry: no changes
  • Rust version(s): cargo 1.82.0-nightly (2f738d617 2024-08-13) and cargo 1.80.1 (376290515 2024-07-16)
  • Target platform: x86_64-unknown-linux-gnu and thumbv6m-none-eabi
@ChocolateLoverRaj ChocolateLoverRaj added the defect Something that isn't as or doesn't work as intended label Aug 17, 2024
@Ogeon
Copy link
Owner

Ogeon commented Aug 17, 2024

Hi! Many floating point functions need a library implementation and that's usually provided by std. When disabling std, you can enable the "libm" feature, as shown in the readme example:

[dependencies.palette]
version = "0.7.6"
default-features = false
features = ["libm"] # Uses libm instead of std for floating point math

The corresponding argument to cargo build would be --features libm.

@Ogeon Ogeon removed the defect Something that isn't as or doesn't work as intended label Aug 17, 2024
@ChocolateLoverRaj
Copy link
Author

Thanks, that fixed it. I think the fact that libm is required for no_std should be added to the docs. Or maybe there should be a feature called no_std which activates the libm feature.

@Ogeon
Copy link
Owner

Ogeon commented Aug 17, 2024

I suppose it could be added to the getting started part of the crate root docs too. 🤔 Was that where you were looking?

@ChocolateLoverRaj
Copy link
Author

Was that where you were looking?

Yes. I also looked in the list of features to see if there was a no_std feature.

@Ogeon
Copy link
Owner

Ogeon commented Aug 17, 2024

I see, thanks. A no_std feature tends to be an anti-pattern, as it's a "negative feature". I'm happy to clarify things, though. The section at https://crates.io/crates/palette could perhaps highlight it more, for example. It's hard to see these things for me, who's familiar with it already.

@Ogeon Ogeon added the documentation Related to things like README or the API documentation. label Aug 18, 2024
@Ogeon Ogeon changed the title Fails to build on no_std Clarify that libm is needed for no_std Aug 18, 2024
@spookyvision
Copy link

I'd love a "crate features" section in the docs!
(feature flags are sadly imho a rather weak spot in Rust/cargo. You can't express mandatory sets of features/combinations apart from rolling your own with compile_error!, and rustdoc doesn't parse feature comments in Cargo.toml…)

@Ogeon
Copy link
Owner

Ogeon commented Aug 24, 2024

Absolutely, that's also a possible improvement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Related to things like README or the API documentation.
Projects
None yet
Development

No branches or pull requests

3 participants