Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cargo wrongly activates an optional feature in cross-compilation #7292

Closed
librelois opened this issue Aug 23, 2019 · 1 comment
Closed

Cargo wrongly activates an optional feature in cross-compilation #7292

librelois opened this issue Aug 23, 2019 · 1 comment
Labels
C-bug Category: bug

Comments

@librelois
Copy link

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

  1. Create a lib crate and add dependency to sha2 with asm feature for supported target :
[target.'cfg(all(unix, any(target_arch = "x86", target_arch = "x86_64")))'.dependencies]
sha2 = { version = "0.8.0", features = ["asm"] }
  1. Compile with target armv7-unknown-linux-gnueabihf" -> it's work
  2. Add dependency to scrypt :
[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

  1. Compile with target armv7-unknown-linux-gnueabihf" -> Cargo tries to compile sha2 with the asm functionality when it should compile without it :
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 (c4fcfb7 2019-05-15)
rustc 1.36.0 (a53f9df32 2019-07-03) toolchain stable

@librelois librelois added the C-bug Category: bug label Aug 23, 2019
@ehuss
Copy link
Contributor

ehuss commented Aug 23, 2019

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.

@ehuss ehuss closed this as completed Aug 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug
Projects
None yet
Development

No branches or pull requests

2 participants