Why is it ok to have a dependency with std support for a crate with #[no_std]

If I have a crate which is supposed to be #![no_std] then if it has any dependency which is not #![no_std] then it is kind of lying it. Is there anyway to mention/restrict the usage of std features in a no_std crate through its dependencies

If I don't depend on serde but a dependency of mine does, I'm not lying, but serde will still be required.

I don't know how to prevent dependencies that rely on std (or a specific crate) offhand.

I don't believe there is anything built into Rust that will directly prevent a dependency of yours from linking with std.

As far as I know, the best way to ensure all transitive dependencies are no_std is by cross-compiling your code for a platform that doesn't include the standard library (e.g. cargo build --target thumbv6m-none-eabi).

The cargo no-no tool might also work for you:

2 Likes