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

feat: add --no-build to cook #260

Merged
merged 2 commits into from
Feb 29, 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
20 changes: 14 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,11 @@ pub struct Cook {
/// the `cargo-zigbuild` crate and the Zig compiler toolchain separately
#[clap(long)]
zigbuild: bool,
/// 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,
}

fn _main() -> Result<(), anyhow::Error> {
Expand Down Expand Up @@ -189,6 +194,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.");
Expand Down Expand Up @@ -235,12 +241,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 {
Expand Down Expand Up @@ -287,6 +294,7 @@ fn _main() -> Result<(), anyhow::Error> {
frozen,
verbose,
bins,
no_build,
})
.context("Failed to cook recipe.")?;
}
Expand Down
7 changes: 7 additions & 0 deletions src/recipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub enum CommandArg {
Check,
Clippy,
Zigbuild,
NoBuild,
}

pub struct CookArgs {
Expand All @@ -45,6 +46,7 @@ pub struct CookArgs {
pub no_std: bool,
pub bin: Option<Vec<String>>,
pub bins: bool,
pub no_build: bool,
}

impl Recipe {
Expand All @@ -57,6 +59,9 @@ impl Recipe {
let current_directory = std::env::current_dir()?;
self.skeleton
.build_minimum_project(&current_directory, args.no_std)?;
if args.no_build {
return Ok(());
}
build_dependencies(&args);
self.skeleton
.remove_compiled_dummies(
Expand Down Expand Up @@ -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);
Expand All @@ -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");
Expand Down