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 a flag to toggle -Zbuild-std, and default to using it #292

Closed
wants to merge 1 commit into from
Closed
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
9 changes: 9 additions & 0 deletions src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@ pub struct BuildOptions {
/// Use a specific sanitizer
pub sanitizer: Sanitizer,

#[arg(long = "build-std")]
/// Pass -Zbuild-std to Cargo, which will build the standard library with all the build
/// settings for the fuzz target, including debug assertions, and a sanitizer if requested.
/// Currently this conflicts with coverage instrumentation but -Zbuild-std enables detecting
/// more bugs so this option defaults to true, but when using `cargo fuzz coverage` it
/// defaults to false.
pub build_std: Option<bool>,

#[arg(long = "target", default_value(crate::utils::default_target()))]
/// Target triple of the fuzz target
pub triple: String,
Expand Down Expand Up @@ -209,6 +217,7 @@ mod test {
no_default_features: false,
all_features: false,
features: None,
build_std: None,
sanitizer: Sanitizer::Address,
triple: String::from(crate::utils::default_target()),
unstable_flags: Vec::new(),
Expand Down
8 changes: 7 additions & 1 deletion src/options/coverage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::{
project::FuzzProject,
RunCommand,
};
use anyhow::Result;
use anyhow::{bail, Result};
use clap::Parser;

#[derive(Clone, Debug, Parser)]
Expand All @@ -27,6 +27,12 @@ pub struct Coverage {

impl RunCommand for Coverage {
fn run_command(&mut self) -> Result<()> {
if self.build.build_std.unwrap_or(false) {
bail!(
"-Zbuild-std is currently incompatible with -Zinstrument-coverage, \
see https://github.com/rust-lang/wg-cargo-std-aware/issues/63"
);
}
let project = FuzzProject::new(self.fuzz_dir_wrapper.fuzz_dir.to_owned())?;
self.build.coverage = true;
project.exec_coverage(self)
Expand Down
2 changes: 2 additions & 0 deletions src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ impl FuzzProject {
}
if let Sanitizer::Memory = build.sanitizer {
cmd.arg("-Z").arg("build-std");
} else if build.build_std.unwrap_or(true) && !build.coverage {
cmd.arg("-Z").arg("build-std");
}

let mut rustflags: String = "-Cpasses=sancov-module \
Expand Down