Problem
When having log as both a dependency and a transitive build-dependency, cargo seems to compile the dependency with the wrong features.
Steps
rustup target add thumbv7em-none-eabihfCargo.toml[package]
name = "testlib"
version = "0.1.0"
authors = ["Dario Nieuwenhuis <[email protected]>"]
edition = "2018"
[dependencies]
log = { version = "0.4.8", default-features = false }
[build-dependencies]
bindgen = "0.54.1"
src/lib.rs#![no_std]
cargo build --target thumbv7em-none-eabihf --verbose Fresh cfg-if v0.1.10
Compiling log v0.4.8
Running `rustc --crate-name log /home/dirbaio/.cargo/registry/src/github.com-1ecc6299db9ec823/log-0.4.8/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts --crate-type lib --emit=dep-info,metadata,link -Cembed-bitcode=no -C debuginfo=2 --cfg 'feature="std"' -C metadata=a51f589eb4222210 -C extra-filename=-a51f589eb4222210 --out-dir /home/dirbaio/akiles/testlib/target/thumbv7em-none-eabihf/debug/deps --target thumbv7em-none-eabihf -L dependency=/home/dirbaio/akiles/testlib/target/thumbv7em-none-eabihf/debug/deps -L dependency=/home/dirbaio/akiles/testlib/target/debug/deps --extern cfg_if=/home/dirbaio/akiles/testlib/target/thumbv7em-none-eabihf/debug/deps/libcfg_if-39845f5cb495a51a.rmeta --cap-lints allow --cfg atomic_cas`
error[E0463]: can't find crate for `std`
|
= note: the `thumbv7em-none-eabihf` target may not be installed
error: aborting due to previous error
For more information about this error, try `rustc --explain E0463`.
error: could not compile `log`.
Caused by:
process didn't exit successfully: `rustc --crate-name log /home/dirbaio/.cargo/registry/src/github.com-1ecc6299db9ec823/log-0.4.8/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts --crate-type lib --emit=dep-info,metadata,link -Cembed-bitcode=no -C debuginfo=2 --cfg 'feature="std"' -C metadata=a51f589eb4222210 -C extra-filename=-a51f589eb4222210 --out-dir /home/dirbaio/akiles/testlib/target/thumbv7em-none-eabihf/debug/deps --target thumbv7em-none-eabihf -L dependency=/home/dirbaio/akiles/testlib/target/thumbv7em-none-eabihf/debug/deps -L dependency=/home/dirbaio/akiles/testlib/target/debug/deps --extern cfg_if=/home/dirbaio/akiles/testlib/target/thumbv7em-none-eabihf/debug/deps/libcfg_if-39845f5cb495a51a.rmeta --cap-lints allow --cfg atomic_cas` (exit code: 1)
As you can see, cargo is trying to build log with --target thumbv7em-none-eabihf and --cfg 'feature="std"', which is impossible.
If you remove either the log dependency or the bindgen build-dependency, then there's no errors. It only happens when both are there. The features for the log crate are somehow mixed up between build dependencies and runtime dependencies.
Notes
[dirbaio@mars testlib]$ cargo version
cargo 1.46.0-nightly (fede83ccf 2020-07-02)
[dirbaio@mars testlib]$ rustc --version
rustc 1.46.0-nightly (8ac1525e0 2020-07-07)
[dirbaio@mars testlib]$ rustup show
Default host: x86_64-unknown-linux-gnu
rustup home: /home/dirbaio/.rustup
installed toolchains
--------------------
nightly-x86_64-unknown-linux-gnu (default)
installed targets for active toolchain
--------------------------------------
thumbv7em-none-eabi
thumbv7em-none-eabihf
x86_64-unknown-linux-gnu
active toolchain
----------------
nightly-x86_64-unknown-linux-gnu (default)
rustc 1.46.0-nightly (8ac1525e0 2020-07-07)
You can use -Zfeatures=host_dep to decouple the features. More details in the documentation: https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#features
Closing as duplicate of #7915.
Most helpful comment
You can use
-Zfeatures=host_depto decouple the features. More details in the documentation: https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#featuresClosing as duplicate of #7915.