Skip to content

Commit

Permalink
add all-features as a flag (#1) (#196)
Browse files Browse the repository at this point in the history
  • Loading branch information
ClementTsang authored Mar 19, 2023
1 parent cca116c commit 4d22f0c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
mod recipe;
mod skeleton;

pub use recipe::{CommandArg, CookArgs, DefaultFeatures, OptimisationProfile, Recipe, TargetArgs};
pub use recipe::{
AllFeatures, CommandArg, CookArgs, DefaultFeatures, OptimisationProfile, Recipe, TargetArgs,
};
pub use skeleton::*;
15 changes: 14 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use anyhow::{anyhow, Context};
use chef::{CommandArg, CookArgs, DefaultFeatures, OptimisationProfile, Recipe, TargetArgs};
use chef::{
AllFeatures, CommandArg, CookArgs, DefaultFeatures, OptimisationProfile, Recipe, TargetArgs,
};
use clap::crate_version;
use clap::Parser;
use fs_err as fs;
Expand Down Expand Up @@ -87,6 +89,9 @@ pub struct Cook {
/// Do not activate the `default` feature.
#[clap(long)]
no_default_features: bool,
/// Enable all features.
#[clap(long)]
all_features: bool,
/// Space or comma separated list of features to activate.
#[clap(long, value_delimiter = ',')]
features: Option<Vec<String>>,
Expand Down Expand Up @@ -152,6 +157,7 @@ fn _main() -> Result<(), anyhow::Error> {
clippy,
target,
no_default_features,
all_features,
features,
unstable_features,
target_dir,
Expand Down Expand Up @@ -227,6 +233,12 @@ fn _main() -> Result<(), anyhow::Error> {
DefaultFeatures::Enabled
};

let all_features = if all_features {
AllFeatures::Enabled
} else {
AllFeatures::Disabled
};

let serialized = fs::read_to_string(recipe_path)
.context("Failed to read recipe from the specified path.")?;
let recipe: Recipe =
Expand All @@ -242,6 +254,7 @@ fn _main() -> Result<(), anyhow::Error> {
profile,
command,
default_features,
all_features,
features,
unstable_features,
target,
Expand Down
11 changes: 11 additions & 0 deletions src/recipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub struct CookArgs {
pub profile: OptimisationProfile,
pub command: CommandArg,
pub default_features: DefaultFeatures,
pub all_features: AllFeatures,
pub features: Option<HashSet<String>>,
pub unstable_features: Option<HashSet<String>>,
pub target: Option<Vec<String>>,
Expand Down Expand Up @@ -78,11 +79,18 @@ pub enum DefaultFeatures {
Disabled,
}

#[derive(Debug, Clone, Copy, Eq, PartialEq)]
pub enum AllFeatures {
Enabled,
Disabled,
}

fn build_dependencies(args: &CookArgs) {
let CookArgs {
profile,
command: command_arg,
default_features,
all_features,
features,
unstable_features,
target,
Expand Down Expand Up @@ -116,6 +124,9 @@ fn build_dependencies(args: &CookArgs) {
let feature_flag = features.iter().cloned().collect::<Vec<String>>().join(",");
command_with_args.arg("--features").arg(feature_flag);
}
if all_features == &AllFeatures::Enabled {
command_with_args.arg("--all-features");
}
if let Some(unstable_features) = unstable_features {
for unstable_feature in unstable_features.iter().cloned() {
command_with_args.arg("-Z").arg(unstable_feature);
Expand Down

0 comments on commit 4d22f0c

Please sign in to comment.