Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add llvm-path option #354

Merged
merged 1 commit into from
Jan 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -18,7 +18,7 @@
/// The project with fuzz targets
fuzz_dir: PathBuf,
/// The project being fuzzed
project_dir: PathBuf,

Check warning on line 21 in src/project.rs

View workflow job for this annotation

GitHub Actions / build

field `project_dir` is never read
targets: Vec<String>,
}

Expand Down Expand Up @@ -699,7 +699,14 @@
.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 @@
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
Loading