No std builds and dev-dependencies with feature unification

I'm hit by cargo wanting to take the union of feature flags in the dependency tree across dependencies and dev-dependencies. This seems to be a four year old issue, so it doesn't look like it will be resolved soon. This means I need to work around it somehow.

The problem is concretely:

itertools = { version = "0.8.0", default_features = false }

criterion = "0.2.10"

I need itertools to be build without the std feature, but criterion depends on itertools with default features, which includes std. cargo build --lib will thus build itertools with std, despite me explicitly disabling it and a --lib build not requiring dev-dependencies.

How to best work around this?

It's actually really hard to avoid including std accidentally, and the build will just continue until you try to build a binary and it turns out a number of duplicate symbols appear like panic_impl.

One ugly but functional workaround to get the compiler to break as soon as possible in a no-std build is to use a target for which std does not exist. In particular thumbv7m-none-eabi seems to work.

So building with cargo build --lib --no-default-features --target=thumbv7m-none-eabi will show you where std enters the equation. In my case, it will show that itertools is being build with std.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.