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

Windows Support #379

Draft
wants to merge 14 commits into
base: main
Choose a base branch
from
99 changes: 87 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ toml = "0.5.9"
rustc_version = "0.4.0"
cargo_metadata = "0.18.1"

[target.'cfg(target_env = "msvc")'.dependencies]
cc = "1.1"
windows-sys = { version = "0.52", features = ["Win32_Foundation", "Win32_Security","Win32_System_Threading", "Win32_System_JobObjects"] }

[dev-dependencies]
assert_cmd = "2.0.7"
predicates = "2.1.4"
54 changes: 42 additions & 12 deletions src/project.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use crate::options::{self, BuildMode, BuildOptions, Sanitizer};
use crate::utils::default_target;
use crate::utils::{create_job_object, default_target};
use anyhow::{anyhow, bail, Context, Result};
use cargo_metadata::MetadataCommand;
use cc::windows_registry::VsVers;
use std::collections::HashSet;
use std::io::Read;
use std::io::Write;
Expand Down Expand Up @@ -187,17 +188,24 @@ impl FuzzProject {
rustflags.push_str(" -Cinstrument-coverage");
}

match build.sanitizer {
Sanitizer::None => {}
Sanitizer::Memory => {
// Memory sanitizer requires more flags to function than others:
// https://doc.rust-lang.org/unstable-book/compiler-flags/sanitizer.html#memorysanitizer
rustflags.push_str(" -Zsanitizer=memory -Zsanitizer-memory-track-origins")
if cfg!(windows) {
match build.sanitizer {
Sanitizer::Address | Sanitizer::None => rustflags.push_str(" -Zsanitizer=address"),
sanitizer => bail!("Windows does not support sanitizer '{sanitizer}'"),
}
} else {
match build.sanitizer {
Sanitizer::None => {}
Sanitizer::Memory => {
// Memory sanitizer requires more flags to function than others:
// https://doc.rust-lang.org/unstable-book/compiler-flags/sanitizer.html#memorysanitizer
rustflags.push_str(" -Zsanitizer=memory -Zsanitizer-memory-track-origins")
}
_ => rustflags.push_str(&format!(
" -Zsanitizer={sanitizer}",
sanitizer = build.sanitizer
)),
}
_ => rustflags.push_str(&format!(
" -Zsanitizer={sanitizer}",
sanitizer = build.sanitizer
)),
}

if build.careful_mode {
Expand Down Expand Up @@ -272,6 +280,28 @@ impl FuzzProject {
artifact_arg.push(self.artifacts_for(fuzz_target)?);
cmd.arg("--").arg(artifact_arg);

#[cfg(target_env = "msvc")]
{
use crate::utils::{append_to_pathvar, get_asan_path};
// On Windows asan is in a DLL. This DLL is not on PATH by default, so the recommended
// action is to add the directory to PATH when running

match (get_asan_path(), cc::windows_registry::find_vs_version()) {
(_, Ok(VsVers::Vs14 | VsVers::Vs15)) => {
bail!("AddressSanitizer is not supported on this MSVC version, 2019 or later is required.")
}
(None, _) => {
bail!("could not find AddressSanitizer DLL")
}
(Some(asan), _) => {
let new_path = append_to_pathvar(&asan).unwrap_or(asan.into_os_string());
cmd.env("PATH", new_path);
}
}

create_job_object()?;
}

Ok(cmd)
}

Expand Down Expand Up @@ -335,7 +365,7 @@ impl FuzzProject {
) -> Result<HashSet<PathBuf>> {
let mut artifacts = HashSet::new();

let artifacts_dir = self.artifacts_for(target)?;
let artifacts_dir = dbg!(self.artifacts_for(target)?);

for entry in fs::read_dir(&artifacts_dir).with_context(|| {
format!(
Expand Down
Loading