From 0d0a136d917623893415ddeef7d414bfd6a60b67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Ml=C3=A1dek?= Date: Tue, 27 Feb 2024 09:18:40 +0100 Subject: [PATCH] Add `--bins` and allow `--bin` to be called multiple times (#241) * Add --bins flag * Allow multiple --bin flags to be passed --- src/main.rs | 10 +++++++--- src/recipe.rs | 11 +++++++++-- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index 45cbf9d..e81d040 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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, + bin: Option>, + /// 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)] @@ -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."); @@ -282,6 +285,7 @@ fn _main() -> Result<(), anyhow::Error> { locked, frozen, verbose, + bins, }) .context("Failed to cook recipe.")?; } diff --git a/src/recipe.rs b/src/recipe.rs index 72a4ebb..36d7894 100644 --- a/src/recipe.rs +++ b/src/recipe.rs @@ -43,7 +43,8 @@ pub struct CookArgs { pub verbose: bool, pub timings: bool, pub no_std: bool, - pub bin: Option, + pub bin: Option>, + pub bins: bool, } impl Recipe { @@ -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); @@ -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"); @@ -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); }