Skip to content

Enabling target features in .cargo/config does not work for cfg statements in Cargo.toml #6858

@newpavlov

Description

@newpavlov

Originally reported in RustCrypto/stream-ciphers#11

Create a project with following files. Cargo.toml:

[target.'cfg(target_feature="aes")'.dependencies]
either = "*"

.cargo/config:

[target.'cfg(any(windows, unix))']
rustflags = ["-Ctarget-feature=+aes"]

src/main.rs:

#[cfg(target_feature="aes")]
fn main() { println!("aes enabled"); }

#[cfg(not(target_feature="aes"))]
fn main() { println!("aes disabled"); }

Running cargo run outputs "aes disabled" as expected, but either crate does not get downloaded, i.e. cfg statement in Cargo.toml does not work as expected. And as a consequence adding #[cfg(target_feature="aes")] extern crate either; to main.rs results in a compilation error. Meanwhile RUSTFLAGS="-C target-feature=+aes" cargo run works as expected without any issues.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-configurationArea: cargo config files and env varsC-bugCategory: bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions