Problem
In a specific case detailed above, cargo tries to compile sha2 with the asm feature while it is not enabled for this target.
Expected : Cargo should respect the conditions for activating a feature in any case. In the specific case detailed above, cargo should compile sha2 without the asm feature.
Steps
[target.'cfg(all(unix, any(target_arch = "x86", target_arch = "x86_64")))'.dependencies]
sha2 = { version = "0.8.0", features = ["asm"] }
[dependencies]
scrypt = { version = "0.2", default-features = false }
scrypt depends on sha2 but without the feature asm : https://github.com/RustCrypto/password-hashing/blob/master/scrypt/Cargo.toml
cargo build --target armv7-unknown-linux-gnueabihf
Compiling rand_xorshift v0.1.1
Compiling rand_hc v0.1.0
Compiling rand_isaac v0.1.1
Compiling backtrace-sys v0.1.31
Compiling sha2-asm v0.5.2
error: failed to run custom build command for `sha2-asm v0.5.2`
Caused by:
process didn't exit successfully: `/builds/nodes/rust/duniter-rs/target/release/build/sha2-asm-d4367bc86b505e80/build-script-build` (exit code: 1)
--- stdout
TARGET = Some("armv7-unknown-linux-gnueabihf")
OPT_LEVEL = Some("3")
HOST = Some("x86_64-unknown-linux-gnu")
CC_armv7-unknown-linux-gnueabihf = None
CC_armv7_unknown_linux_gnueabihf = Some("arm-linux-gnueabihf-gcc")
CFLAGS_armv7-unknown-linux-gnueabihf = None
CFLAGS_armv7_unknown_linux_gnueabihf = None
TARGET_CFLAGS = None
CFLAGS = None
CRATE_CC_NO_DEFAULTS = None
DEBUG = Some("false")
CARGO_CFG_TARGET_FEATURE = None
running: "arm-linux-gnueabihf-gcc" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "-march=armv7-a" "-Wall" "-Wextra" "-c" "-o" "/builds/nodes/rust/duniter-rs/target/armv7-unknown-linux-gnueabihf/release/build/sha2-asm-9a9a487af1a69d3e/out/src/sha256_x64.o" "-c" "src/sha256_x64.S"
cargo:warning=src/sha256_x64.S: Assembler messages:
Possible Solution(s)
Modify the algorithm determining the optional features to be enabled to properly handle this case.
Notes
Output of cargo version: cargo 1.36.0 (c4fcfb725 2019-05-15)
rustc 1.36.0 (a53f9df32 2019-07-03) toolchain stable
Thanks for the report! This is a well known issue where features of target dependencies are unified across the entire graph, even if the target is not enabled. This is tracked in various other issues (like #1197 and #2524), so I'm going to close in favor of those.
Most helpful comment
Thanks for the report! This is a well known issue where features of target dependencies are unified across the entire graph, even if the target is not enabled. This is tracked in various other issues (like #1197 and #2524), so I'm going to close in favor of those.