Skip to content

Commit

Permalink
Inline sanitizer flag selection now that it's infallible
Browse files Browse the repository at this point in the history
  • Loading branch information
Shnatsel committed Jul 12, 2024
1 parent 3eecd3d commit 92ebfee
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 14 deletions.
7 changes: 5 additions & 2 deletions src/project.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::options::{self, BuildMode, BuildOptions, Sanitizer};
use crate::rustc_version::{is_nightly, rust_version_string, sanitizer_flag, RustVersion};
use crate::rustc_version::{is_nightly, rust_version_string, RustVersion};
use crate::utils::default_target;
use anyhow::{anyhow, bail, Context, Result};
use cargo_metadata::MetadataCommand;
Expand Down Expand Up @@ -195,7 +195,10 @@ impl FuzzProject {
let rust_version_string = rust_version_string()?;
let rust_version =
RustVersion::from_str(&rust_version_string).map_err(|e| anyhow::anyhow!(e))?;
let sanitizer_flag = sanitizer_flag(&rust_version)?;
let sanitizer_flag = match rust_version.has_sanitizers_on_stable() {
true => "-Csanitizer",
false => "-Zsanitizer",
};

// Set rustc CLI arguments for the chosen sanitizer
match build.sanitizer {
Expand Down
12 changes: 0 additions & 12 deletions src/rustc_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,6 @@ pub fn rust_version_string() -> anyhow::Result<String> {
String::from_utf8(raw_output).context("`rustc --version` returned non-text output somehow")
}

/// Returns either "-Zsanitizer" or "-Csanitizer" depending on the compiler version.
///
/// Stabilization of sanitizers has removed the "-Zsanitizer" flag, even on nightly,
/// so we have to choose the appropriate flag for the compiler version.
/// More info: <https://github.com/rust-lang/rust/pull/123617>
pub fn sanitizer_flag(version: &RustVersion) -> anyhow::Result<&'static str> {
match version.has_sanitizers_on_stable() {
true => Ok("-Csanitizer"),
false => Ok("-Zsanitizer"),
}
}

#[derive(Debug, Copy, Clone, Eq, PartialEq, PartialOrd)]
pub struct RustVersion {
pub major: u32,
Expand Down

0 comments on commit 92ebfee

Please sign in to comment.