-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Closed
Labels
A-build-scriptsArea: build.rs scriptsArea: build.rs scriptsA-featuresArea: features — conditional compilationArea: features — conditional compilationC-feature-requestCategory: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`S-needs-designStatus: Needs someone to work further on the design for the feature or fix. NOT YET accepted.Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted.
Description
Build scripts receive information about activated features as environment variables CARGO_FEATURE_$name
, where $name
is the feature name uppercased and with dashes converted to underscores.
However, feature names are allowed to contain underscores, so this transformation can create collisions. Example:
- Cargo.toml
[package] name = "tester" version = "0.1.0" build = "build.rs" [features] foo-bar = [] foo_bar = []
- build.rs
use std::env; fn main() { for (k, v) in env::vars() { if k.starts_with("CARGO_FEATURE") { println!("{} => {}", k, v); } } panic!(); // so cargo prints the output }
cargo build --features "foo_bar foo-bar"
--- stdout CARGO_FEATURE_FOO_BAR => 1 --- stderr thread 'main' panicked at 'explicit panic', build.rs:9 note: Run with `RUST_BACKTRACE=1` for a backtrace.
Metadata
Metadata
Assignees
Labels
A-build-scriptsArea: build.rs scriptsArea: build.rs scriptsA-featuresArea: features — conditional compilationArea: features — conditional compilationC-feature-requestCategory: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`S-needs-designStatus: Needs someone to work further on the design for the feature or fix. NOT YET accepted.Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted.