no_std crates should not permit non-no_std dependencies
I couldn't find this exact problem mentioned elsewhere.
Problem
Cargo rightly produces errors for uses of std within a crate but will not complain about dependencies that rely on std when building for platforms that support std. This means that an implicit std requirement can quietly sneak into a project. It seems rather bizarre that cargo does not catch this issue.
Possible Solution(s)
- Make cargo search for uses of
stdwhen building dependencies and produce an error - Do not permit
stdas a dependency in the dependency graph forno_stdcrates - Only permit dependencies that are explicitly tagged with
#![no_std]forno_stdcrates
Current workaround: compile/cargo check for a target that is known to have no standard library.
Also there is the issue that Cargo.toml doesn't contain any info that a crate is no_std. It's specified in the Rust code only.
FYI build-std is looking at allowing core/alloc/std being represented in Cargo's dependencies which would allow for this
rust-lang/rfcs#3875 is up which will elevate no_std into the dependency tree for analysis.
It does not specify that we will lint the dependency tree for correctness but that could be built on top of it.