diff --git a/src/cli.rs b/src/cli.rs index f9dc4e6..f314e53 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -48,6 +48,14 @@ pub(crate) struct Cli { #[arg(short = 'j', long)] pub jobs: Option, + /// Cargo profile to use for building + #[arg(long, default_value = "release")] + pub cargo_profile: String, + + /// Cargo features to enable for building + #[arg(long)] + pub cargo_features: Option, + /// Install binaries for a specific network (e.g., tempo) #[arg(short = 'n', long)] pub network: Option, diff --git a/src/install.rs b/src/install.rs index bda2d53..1e12910 100644 --- a/src/install.rs +++ b/src/install.rs @@ -74,20 +74,28 @@ async fn install_from_local(config: &Config, local_path: &Path, args: &Cli) -> R say!("installing from {}", local_path.display()); let mut cmd = tokio::process::Command::new("cargo"); - cmd.arg("build").arg("--bins").arg("--release").current_dir(local_path); + cmd.arg("build") + .arg("--bins") + .arg("--profile") + .arg(&args.cargo_profile) + .current_dir(local_path); cmd.env("RUSTFLAGS", rustflags()); if let Some(jobs) = args.jobs { cmd.arg("--jobs").arg(jobs.to_string()); } + if let Some(ref features) = args.cargo_features { + cmd.arg("--features").arg(features); + } let status = cmd.status().await.wrap_err("failed to run cargo build")?; if !status.success() { bail!("cargo build failed"); } + let target_dir = profile_target_dir(&args.cargo_profile); for bin in config.network.bins { - let src = local_path.join("target/release").join(bin_name(bin)); + let src = local_path.join("target").join(target_dir).join(bin_name(bin)); let dest = config.bin_path(bin); if dest.exists() { @@ -104,6 +112,10 @@ async fn install_from_local(config: &Config, local_path: &Path, args: &Cli) -> R Ok(()) } +fn profile_target_dir(profile: &str) -> &str { + if profile == "dev" { "debug" } else { profile } +} + async fn install_from_source(config: &Config, repo: &str, args: &Cli) -> Result<()> { let branch = if let Some(pr) = args.pr { format!("refs/pull/{pr}/head") @@ -171,12 +183,19 @@ async fn install_from_source(config: &Config, repo: &str, args: &Cli) -> Result< say!("installing version {version}"); let mut cmd = tokio::process::Command::new("cargo"); - cmd.arg("build").arg("--bins").arg("--release").current_dir(&repo_path); + cmd.arg("build") + .arg("--bins") + .arg("--profile") + .arg(&args.cargo_profile) + .current_dir(&repo_path); cmd.env("RUSTFLAGS", rustflags()); if let Some(jobs) = args.jobs { cmd.arg("--jobs").arg(jobs.to_string()); } + if let Some(ref features) = args.cargo_features { + cmd.arg("--features").arg(features); + } let status = cmd.status().await.wrap_err("failed to run cargo build")?; if !status.success() { @@ -186,8 +205,9 @@ async fn install_from_source(config: &Config, repo: &str, args: &Cli) -> Result< let version_dir = config.version_dir(repo, &version); fs::create_dir_all(&version_dir)?; + let target_dir = profile_target_dir(&args.cargo_profile); for bin in config.network.bins { - let src = repo_path.join("target/release").join(bin_name(bin)); + let src = repo_path.join("target").join(target_dir).join(bin_name(bin)); if src.exists() { fs::rename(&src, version_dir.join(bin_name(bin)))?; } diff --git a/tests/it/main.rs b/tests/it/main.rs index 316aed6..6d87477 100644 --- a/tests/it/main.rs +++ b/tests/it/main.rs @@ -67,6 +67,14 @@ Options: -j, --jobs Number of CPUs to use for building (default: all) + --cargo-profile + Cargo profile to use for building + + [default: release] + + --cargo-features + Cargo features to enable for building + -n, --network Install binaries for a specific network (e.g., tempo)