Skip to content

Commit

Permalink
Add support for custom profiles
Browse files Browse the repository at this point in the history
This patch adds the new --profile NAME option to support cargo's
custom profiles. The behavior hasn't changed when --release is
passed or when nothing related to profiles are given.
  • Loading branch information
maoe authored and cmyr committed Apr 26, 2022
1 parent db39b61 commit 4c09a3c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ fn make_compile_opts(cargo_options: &CargoOpts, cfg: &Config) -> Result<CompileO
use cargo::ops::CompileFilter;

let mut compile_options = CompileOptions::new(cfg, CompileMode::Build)?;
let profile = if cargo_options.release { "release" } else { "dev" };
let profile = &cargo_options.profile;

compile_options.build_config.requested_profile = InternedString::new(profile);
compile_options.cli_features = cargo_options.features.clone();
Expand Down
14 changes: 11 additions & 3 deletions src/opt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,13 @@ pub(crate) struct AppConfig {
bench: Option<String>,

/// Pass --release to cargo
#[structopt(long)]
#[structopt(long, conflicts_with = "profile")]
release: bool,

/// Pass --profile NAME to cargo
#[structopt(long, value_name = "NAME")]
profile: Option<String>,

/// Output .trace file to the given path
///
/// Defaults to `target/instruments/{name}_{template-name}_{date}.trace`.
Expand Down Expand Up @@ -155,7 +159,7 @@ impl fmt::Display for Target {
pub(crate) struct CargoOpts {
pub(crate) package: Package,
pub(crate) target: Target,
pub(crate) release: bool,
pub(crate) profile: String,
pub(crate) features: CliFeatures,
}

Expand All @@ -169,7 +173,11 @@ impl AppConfig {
self.all_features,
!self.no_default_features,
)?;
Ok(CargoOpts { package, target, release: self.release, features })
let profile = self
.profile
.clone()
.unwrap_or_else(|| (if self.release { "release" } else { "dev" }).to_owned());
Ok(CargoOpts { package, target, profile, features })
}

fn get_package(&self) -> Package {
Expand Down

0 comments on commit 4c09a3c

Please sign in to comment.