Skip to content

Commit

Permalink
Add --bins and allow --bin to be called multiple times (#241)
Browse files Browse the repository at this point in the history
* Add --bins flag

* Allow multiple --bin flags to be passed
  • Loading branch information
mladedav authored Feb 27, 2024
1 parent 131c052 commit 0d0a136
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
10 changes: 7 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,12 @@ pub struct Cook {
/// Cook using `#[no_std]` configuration (does not affect `proc-macro` crates)
#[clap(long)]
no_std: bool,
/// When --bin is specified, `cargo-chef` will ignore all members of the workspace
/// that are not necessary to successfully compile the specific binary.
/// Build only the specified binary. This can be specified with multiple binaries.
#[clap(long)]
bin: Option<String>,
bin: Option<Vec<String>>,
/// Build all binaries and ignore everything else.
#[clap(long)]
bins: bool,
/// Run `cargo zigbuild` instead of `cargo build`. You need to install
/// the `cargo-zigbuild` crate and the Zig compiler toolchain separately
#[clap(long)]
Expand Down Expand Up @@ -185,6 +187,7 @@ fn _main() -> Result<(), anyhow::Error> {
no_std,
bin,
zigbuild,
bins,
}) => {
if atty::is(atty::Stream::Stdout) {
eprintln!("WARNING stdout appears to be a terminal.");
Expand Down Expand Up @@ -282,6 +285,7 @@ fn _main() -> Result<(), anyhow::Error> {
locked,
frozen,
verbose,
bins,
})
.context("Failed to cook recipe.")?;
}
Expand Down
11 changes: 9 additions & 2 deletions src/recipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ pub struct CookArgs {
pub verbose: bool,
pub timings: bool,
pub no_std: bool,
pub bin: Option<String>,
pub bin: Option<Vec<String>>,
pub bins: bool,
}

impl Recipe {
Expand Down Expand Up @@ -109,6 +110,7 @@ fn build_dependencies(args: &CookArgs) {
timings,
bin,
no_std: _no_std,
bins,
} = args;
let cargo_path = std::env::var("CARGO").expect("The `CARGO` environment variable was not set. This is unexpected: it should always be provided by `cargo` when invoking a custom sub-command, allowing `cargo-chef` to correctly detect which toolchain should be used. Please file a bug.");
let mut command = Command::new(cargo_path);
Expand Down Expand Up @@ -167,7 +169,9 @@ fn build_dependencies(args: &CookArgs) {
}
}
if let Some(binary_target) = bin {
command_with_args.arg("--bin").arg(binary_target);
for binary_target in binary_target {
command_with_args.arg("--bin").arg(binary_target);
}
}
if *workspace {
command_with_args.arg("--workspace");
Expand All @@ -187,6 +191,9 @@ fn build_dependencies(args: &CookArgs) {
if *timings {
command_with_args.arg("--timings");
}
if *bins {
command_with_args.arg("--bins");
}

execute_command(command_with_args);
}
Expand Down

0 comments on commit 0d0a136

Please sign in to comment.