From 1c72d78ed98ed4ca6b4e76deb96e8cbb06d85adc Mon Sep 17 00:00:00 2001 From: Bernardo Meurer Costa Date: Thu, 29 Feb 2024 02:47:59 +0000 Subject: [PATCH 1/2] feat: add --no-build to cook --- src/main.rs | 18 ++++++++++++------ src/recipe.rs | 7 +++++++ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/main.rs b/src/main.rs index b256848..542a75e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -149,6 +149,9 @@ pub struct Cook { /// the `cargo-zigbuild` crate and the Zig compiler toolchain separately #[clap(long)] zigbuild: bool, + /// Do not perform any kind of build, only prepare the source for a build. + #[clap(long)] + no_build: bool, } fn _main() -> Result<(), anyhow::Error> { @@ -189,6 +192,7 @@ fn _main() -> Result<(), anyhow::Error> { bin, zigbuild, bins, + no_build, }) => { if std::io::stdout().is_terminal() { eprintln!("WARNING stdout appears to be a terminal."); @@ -235,12 +239,13 @@ fn _main() -> Result<(), anyhow::Error> { (false, Some(custom_profile)) => OptimisationProfile::Other(custom_profile), (true, Some(_)) => Err(anyhow!("You specified both --release and --profile arguments. Please remove one of them, or both"))? }; - let command = match (check, clippy, zigbuild) { - (true, false, false) => CommandArg::Check, - (false, true, false) => CommandArg::Clippy, - (false, false, true) => CommandArg::Zigbuild, - (false, false, false) => CommandArg::Build, - _ => Err(anyhow!("Only one (or none) of the `clippy`, `check` and `zigbuild` arguments are allowed. Please remove some of them, or all"))?, + let command = match (check, clippy, zigbuild, no_build) { + (true, false, false, false) => CommandArg::Check, + (false, true, false, false) => CommandArg::Clippy, + (false, false, true, false) => CommandArg::Zigbuild, + (false, false, false, true) => CommandArg::NoBuild, + (false, false, false, false) => CommandArg::Build, + _ => Err(anyhow!("Only one (or none) of the `clippy`, `check`, `zigbuild`, and `no-build` arguments are allowed. Please remove some of them, or all"))?, }; let default_features = if no_default_features { @@ -287,6 +292,7 @@ fn _main() -> Result<(), anyhow::Error> { frozen, verbose, bins, + no_build, }) .context("Failed to cook recipe.")?; } diff --git a/src/recipe.rs b/src/recipe.rs index 36d7894..1f26f76 100644 --- a/src/recipe.rs +++ b/src/recipe.rs @@ -22,6 +22,7 @@ pub enum CommandArg { Check, Clippy, Zigbuild, + NoBuild, } pub struct CookArgs { @@ -45,6 +46,7 @@ pub struct CookArgs { pub no_std: bool, pub bin: Option>, pub bins: bool, + pub no_build: bool, } impl Recipe { @@ -57,6 +59,9 @@ impl Recipe { let current_directory = std::env::current_dir()?; self.skeleton .build_minimum_project(¤t_directory, args.no_std)?; + if args.no_build { + return Ok(()); + } build_dependencies(&args); self.skeleton .remove_compiled_dummies( @@ -111,6 +116,7 @@ fn build_dependencies(args: &CookArgs) { bin, no_std: _no_std, bins, + no_build: _no_build, } = 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); @@ -119,6 +125,7 @@ fn build_dependencies(args: &CookArgs) { CommandArg::Check => command.arg("check"), CommandArg::Clippy => command.arg("clippy"), CommandArg::Zigbuild => command.arg("zigbuild"), + CommandArg::NoBuild => return, }; if profile == &OptimisationProfile::Release { command_with_args.arg("--release"); From 79c8893d78d439ebc49fcc6917eb7b766428e0b3 Mon Sep 17 00:00:00 2001 From: Luca Palmieri <20745048+LukeMathWalker@users.noreply.github.com> Date: Thu, 29 Feb 2024 15:22:49 +0100 Subject: [PATCH 2/2] Update src/main.rs --- src/main.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 542a75e..f890af3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -149,7 +149,9 @@ pub struct Cook { /// the `cargo-zigbuild` crate and the Zig compiler toolchain separately #[clap(long)] zigbuild: bool, - /// Do not perform any kind of build, only prepare the source for a build. + /// Modify the current workspace to maximise cache reuse, but don't invoke `cargo build`. + /// This option exist to leverage `cargo-chef` when trying to cache dependencies in Rust + /// projects that rely on a custom build system (i.e. not `cargo`). #[clap(long)] no_build: bool, }