Files
wasmtime/crates/fuzzing/build.rs
Alex Crichton d6f64ec88e Make spectest fuzzing more deterministic
Currently spectest fuzzing indexes into a compile-time-created array of
strings which is the list of input files, but the order of this array is
dependent on the filesystem that we're reading from. This means that
inputs from oss-fuzz may not be easily reproducible locally because
files could be read in different orders, so indexes could be distinct.

This commit instead reads the directory paths, then sorts them, then
includes them for testing. That way fuzz inputs at a specific commit
should be consistent.
2020-08-06 08:08:20 -07:00

30 lines
945 B
Rust

// A small build script to include the contents of the spec test suite into the
// final fuzzing binary so the fuzzing binary can be run elsewhere and doesn't
// rely on the original source tree.
use std::env;
use std::path::PathBuf;
fn main() {
println!("cargo:rerun-if-changed=build.rs");
let out_dir = PathBuf::from(env::var_os("OUT_DIR").unwrap());
let dir = env::current_dir()
.unwrap()
.join("../../tests/spec_testsuite");
let mut code = format!("static FILES: &[(&str, &str)] = &[\n");
let entries = dir
.read_dir()
.unwrap()
.map(|p| p.unwrap().path().display().to_string())
.collect::<Vec<_>>();
for path in entries {
if !path.ends_with(".wast") {
continue;
}
code.push_str(&format!("({:?}, include_str!({0:?})),\n", path));
}
code.push_str("];\n");
std::fs::write(out_dir.join("spectests.rs"), code).unwrap();
}