Questions about no_std compatible libraries

Is there a way to only include a dependency or only enable certain dependency features when a feature is not enabled?

I made this PR in the eskf repo to fix the broken no_std compatibility. The issue is the library depends on nalgebra and to make it work on no_std you need to disabled the default std feature, enable the libm feature and include the num-traits crate (and do a conditional import). I only want to include these dependencies/features when using in a no_std environment because they are not needed in a std environment and they introduce some conflicting imports in one of the dependencies. The only solution I could think of was to add a no_std feature but this goes against the standard practice to only have a std feature (enabled by default) that you disable to make the crate no_std compatible. In this case that won't work. Is there another way to do this?

Another question that came up in the PR is how to create an automated way to test for no_std compatibility. I found cargo-nono but this doesn't cargo build or cargo check the code so it relies on all the dependencies not breaking their own no_std compatibility to work correctly. Another option is to run cargo check with a target triple that doesn't support std but how do you do that in a project that has examples that depend on std?

These have to be fairly common issues but I wasn't able to find much discussion about them. Hopefully I missed something. Thanks.

Usually you are not supposed to disable features and they should be additive.

But default is an exception and it can be disabled as described in the documentation.

I'm aware but in this case I have a dependency and feature that I only want to enable when compiling for no_std.

I think you would have to do what nalgerba and num-traits do, too: add another feature, libm which passes libm requirement further.

So to use eskf-rs one would have to both disabled default and enable libm. It's annoying, but I don't see anything better.

As added nicety add compile-time error to askf-rs about the need to enable libm if you don't enable std.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.