Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --bins and allow --bin to be called multiple times #241

Merged
merged 2 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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