Skip to content

Commit

Permalink
Implemented feature flag support.
Browse files Browse the repository at this point in the history
We now support `--features`, `--all-features` in addition to
`--no-default-features`. This closes rust-lang#91.
  • Loading branch information
ibabushkin committed Jun 15, 2019
1 parent 091939b commit bdefd58
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions src/bin/cargo_semver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,6 @@ fn run(config: &cargo::Config, matches: &getopts::Matches) -> Result<()> {
child.args(&["--target", &target]);
}

if !matches.opt_present("no-default-features") {
child.args(&["--cfg", "feature=\"default\""]);
}

let mut child = child
.arg("-")
.stdin(Stdio::piped())
Expand Down Expand Up @@ -207,10 +203,6 @@ fn run(config: &cargo::Config, matches: &getopts::Matches) -> Result<()> {
child.args(&["--target", &target]);
}

if !matches.opt_present("no-default-features") {
child.args(&["--cfg", "feature=\"default\""]);
}

let child = child
.arg("-")
.stdin(Stdio::piped())
Expand Down Expand Up @@ -284,6 +276,17 @@ mod cli {
"api-guidelines",
"report only changes that are breaking according to the API-guidelines",
);
opts.optopt(
"",
"features",
"Space-separated list of features to activate",
"FEATURES",
);
opts.optflag(
"",
"all-features",
"Activate all available features",
);
opts.optflag(
"",
"no-default-features",
Expand Down Expand Up @@ -458,9 +461,13 @@ impl<'a> WorkInfo<'a> {
if let Some(target) = matches.opt_str("target") {
opts.build_config.requested_target = Some(target);
}
opts.no_default_features = matches.opt_present("no-default-features");

// TODO: this is where we could insert feature flag builds (or using the CLI mechanisms)
if let Some(s) = matches.opt_str("features") {
opts.features = s.split(" ").map(str::to_owned).collect();
}

opts.all_features = matches.opt_present("all-features");
opts.no_default_features = matches.opt_present("no-default-features");

env::set_var(
"RUSTFLAGS",
Expand Down

0 comments on commit bdefd58

Please sign in to comment.