Skip to content

Commit

Permalink
Allow use of custom profiles
Browse files Browse the repository at this point in the history
  • Loading branch information
ijc committed Sep 18, 2024
1 parent 971aee9 commit f556347
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
23 changes: 19 additions & 4 deletions src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,17 @@ pub enum BuildMode {

#[derive(Clone, Debug, Eq, PartialEq, Parser)]
pub struct BuildOptions {
#[arg(short = 'D', long, conflicts_with = "release")]
#[arg(short = 'D', long, conflicts_with_all = ["release", "profile"])]
/// Build artifacts in development mode, without optimizations
pub dev: bool,

#[arg(short = 'O', long, conflicts_with = "dev")]
#[arg(short = 'O', long, conflicts_with_all = ["dev", "profile"])]
/// Build artifacts in release mode, with optimizations
pub release: bool,

#[arg(long, conflicts_with_all = ["dev", "release"])]
pub profile: Option<String>,

#[arg(short = 'a', long)]
/// Build artifacts with debug assertions and overflow checks enabled (default if not -O)
pub debug_assertions: bool,
Expand Down Expand Up @@ -169,8 +172,11 @@ pub struct BuildOptions {

impl BuildOptions {
pub fn profile_name(&self) -> &str {
// we default to release mode unless debug mode is explicitly requested
if !self.dev {
// if no explicit profile is given then we default to release
// mode unless debug mode is explicitly requested.
if let Some(profile) = &self.profile {
profile
} else if !self.dev {
"release"
} else {
"dev"
Expand All @@ -188,6 +194,10 @@ impl stdfmt::Display for BuildOptions {
write!(f, " -O")?;
}

if let Some(profile) = &self.profile {
write!(f, " --profile {profile}")?;
}

if self.debug_assertions {
write!(f, " -a")?;
}
Expand Down Expand Up @@ -260,6 +270,7 @@ mod test {
let default_opts = BuildOptions {
dev: false,
release: false,
profile: None,
debug_assertions: false,
verbose: false,
no_default_features: false,
Expand Down Expand Up @@ -288,6 +299,10 @@ mod test {
release: true,
..default_opts.clone()
},
BuildOptions {
profile: Some("fuzz".to_string()),
..default_opts.clone()
},
BuildOptions {
debug_assertions: true,
..default_opts.clone()
Expand Down
8 changes: 4 additions & 4 deletions src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -747,10 +747,10 @@ impl FuzzProject {
) -> Result<(Command, tempfile::TempDir)> {
let bin_path = {
// See https://doc.rust-lang.org/cargo/guide/build-cache.html for the mapping.
let profile_subdir = if coverage.build.profile_name() == "dev" {
"debug"
} else {
"release"
let profile_subdir = match coverage.build.profile_name() {
"dev" | "test" => "debug",
"release" | "bench" => "release",
other => other,
};

let target_dir = self
Expand Down

0 comments on commit f556347

Please sign in to comment.