Skip to content

Commit

Permalink
Merge pull request #354 from jonboh/main
Browse files Browse the repository at this point in the history
add llvm-path option
  • Loading branch information
fitzgen authored Jan 2, 2024
2 parents c4a4d33 + 94f7b8c commit 797740f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
6 changes: 6 additions & 0 deletions src/options/coverage.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::path::PathBuf;

use crate::{
options::{BuildOptions, FuzzDirWrapper},
project::FuzzProject,
Expand All @@ -14,6 +16,10 @@ pub struct Coverage {
#[command(flatten)]
pub fuzz_dir_wrapper: FuzzDirWrapper,

/// Sets the path to the LLVM bin directory. By default, it will use the one installed with rustc
#[arg(long)]
pub llvm_path: Option<PathBuf>,

/// Name of the fuzz target
pub target: String,

Expand Down
20 changes: 15 additions & 5 deletions src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,14 @@ impl FuzzProject {
.context("Failed to generage coverage data")?;
}
}
self.merge_coverage(&coverage_out_raw_dir, &coverage_out_file)?;

let mut profdata_bin_path = coverage.llvm_path.clone().unwrap_or(rustlib()?);
profdata_bin_path.push(format!("llvm-profdata{}", env::consts::EXE_SUFFIX));
self.merge_coverage(
&profdata_bin_path,
&coverage_out_raw_dir,
&coverage_out_file,
)?;

Ok(())
}
Expand Down Expand Up @@ -749,10 +756,13 @@ impl FuzzProject {
Ok((cmd, dummy_corpus))
}

fn merge_coverage(&self, profdata_raw_path: &Path, profdata_out_path: &Path) -> Result<()> {
let mut profdata_path = rustlib()?;
profdata_path.push(format!("llvm-profdata{}", env::consts::EXE_SUFFIX));
let mut merge_cmd = Command::new(profdata_path);
fn merge_coverage(
&self,
profdata_bin_path: &Path,
profdata_raw_path: &Path,
profdata_out_path: &Path,
) -> Result<()> {
let mut merge_cmd = Command::new(profdata_bin_path);
merge_cmd.arg("merge").arg("-sparse");
merge_cmd.arg(profdata_raw_path);
merge_cmd.arg("-o").arg(profdata_out_path);
Expand Down

0 comments on commit 797740f

Please sign in to comment.