cargo icon indicating copy to clipboard operation
cargo copied to clipboard

no_std crates should not permit non-no_std dependencies

Open zesterer opened this issue 5 years ago • 1 comments

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 std when building dependencies and produce an error
  • Do not permit std as a dependency in the dependency graph for no_std crates
  • Only permit dependencies that are explicitly tagged with #![no_std] for no_std crates

zesterer avatar Oct 20 '20 09:10 zesterer

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.

est31 avatar Oct 21 '20 21:10 est31

FYI build-std is looking at allowing core/alloc/std being represented in Cargo's dependencies which would allow for this

epage avatar Sep 19 '25 21:09 epage

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.

epage avatar Oct 31 '25 19:10 epage