From f556347a7820f1dddb6a0eb5f5a11f4a580acb88 Mon Sep 17 00:00:00 2001 From: Ian Campbell Date: Wed, 18 Sep 2024 09:10:43 +0100 Subject: [PATCH] Allow use of custom profiles --- src/options.rs | 23 +++++++++++++++++++---- src/project.rs | 8 ++++---- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/options.rs b/src/options.rs index 677b632..a653ad9 100644 --- a/src/options.rs +++ b/src/options.rs @@ -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, + #[arg(short = 'a', long)] /// Build artifacts with debug assertions and overflow checks enabled (default if not -O) pub debug_assertions: bool, @@ -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" @@ -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")?; } @@ -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, @@ -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() diff --git a/src/project.rs b/src/project.rs index 2a7b72a..1afd983 100644 --- a/src/project.rs +++ b/src/project.rs @@ -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