diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 7b9131355b..31d53cd738 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -79,7 +79,7 @@ jobs: - run: cargo install cargo-fuzz --vers "^0.7" - run: cargo fetch working-directory: ./fuzz - - run: cargo fuzz build --release --debug-assertions + - run: cargo fuzz build --release --debug-assertions --features binaryen # Our corpora are too large to run in full on every pull request, they just # take too long. Instead, we sample some of them and make sure that running # our fuzzers over the sampled inputs still works OK. diff --git a/crates/fuzzing/Cargo.toml b/crates/fuzzing/Cargo.toml index 807ac2bae9..872c623462 100644 --- a/crates/fuzzing/Cargo.toml +++ b/crates/fuzzing/Cargo.toml @@ -9,7 +9,7 @@ version = "0.12.0" [dependencies] anyhow = "1.0.22" arbitrary = { version = "0.4.0", features = ["derive"] } -binaryen = "0.10.0" +binaryen = { version = "0.10.0", optional = true } env_logger = "0.7.1" log = "0.4.8" rayon = "1.2.1" diff --git a/crates/fuzzing/src/generators.rs b/crates/fuzzing/src/generators.rs index b2504fc3e1..15715b3a44 100644 --- a/crates/fuzzing/src/generators.rs +++ b/crates/fuzzing/src/generators.rs @@ -8,20 +8,22 @@ //! wrapper over an external tool, such that the wrapper implements the //! `Arbitrary` trait for the wrapped external tool. +#[cfg(feature = "binaryen")] pub mod api; -use arbitrary::{Arbitrary, Unstructured}; -use std::fmt; +use arbitrary::Arbitrary; /// A Wasm test case generator that is powered by Binaryen's `wasm-opt -ttf`. #[derive(Clone)] +#[cfg(feature = "binaryen")] pub struct WasmOptTtf { /// The raw, encoded Wasm bytes. pub wasm: Vec, } -impl fmt::Debug for WasmOptTtf { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { +#[cfg(feature = "binaryen")] +impl std::fmt::Debug for WasmOptTtf { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { write!( f, "WasmOptTtf {{ wasm: wat::parse_str(r###\"\n{}\n\"###).unwrap() }}", @@ -30,8 +32,9 @@ impl fmt::Debug for WasmOptTtf { } } +#[cfg(feature = "binaryen")] impl Arbitrary for WasmOptTtf { - fn arbitrary(input: &mut Unstructured) -> arbitrary::Result { + fn arbitrary(input: &mut arbitrary::Unstructured) -> arbitrary::Result { crate::init_fuzzing(); let seed: Vec = Arbitrary::arbitrary(input)?; let module = binaryen::tools::translate_to_fuzz_mvp(&seed); @@ -39,7 +42,7 @@ impl Arbitrary for WasmOptTtf { Ok(WasmOptTtf { wasm }) } - fn arbitrary_take_rest(input: Unstructured) -> arbitrary::Result { + fn arbitrary_take_rest(input: arbitrary::Unstructured) -> arbitrary::Result { crate::init_fuzzing(); let seed: Vec = Arbitrary::arbitrary_take_rest(input)?; let module = binaryen::tools::translate_to_fuzz_mvp(&seed); diff --git a/crates/fuzzing/src/oracles.rs b/crates/fuzzing/src/oracles.rs index 3d7eb6eef2..361e5b2b70 100644 --- a/crates/fuzzing/src/oracles.rs +++ b/crates/fuzzing/src/oracles.rs @@ -110,7 +110,7 @@ pub fn compile(wasm: &[u8], strategy: Strategy) { /// or aren't enabled for different configs, we should get the same results when /// we call the exported functions for all of our different configs. pub fn differential_execution( - ttf: &crate::generators::WasmOptTtf, + wasm: &[u8], configs: &[crate::generators::DifferentialConfig], ) { crate::init_fuzzing(); @@ -131,13 +131,13 @@ pub fn differential_execution( }; let mut export_func_results: HashMap, Trap>> = Default::default(); - log_wasm(&ttf.wasm); + log_wasm(wasm); for config in &configs { let engine = Engine::new(config); let store = Store::new(&engine); - let module = match Module::new(&store, &ttf.wasm) { + let module = match Module::new(&store, wasm) { Ok(module) => module, // The module might rely on some feature that our config didn't // enable or something like that. @@ -283,6 +283,7 @@ fn assert_same_export_func_result( } /// Invoke the given API calls. +#[cfg(feature = "binaryen")] pub fn make_api_calls(api: crate::generators::api::ApiCalls) { use crate::generators::api::ApiCall; diff --git a/fuzz/Cargo.toml b/fuzz/Cargo.toml index b8f1a527d4..f32af6f4c0 100644 --- a/fuzz/Cargo.toml +++ b/fuzz/Cargo.toml @@ -34,15 +34,21 @@ name = "instantiate_translated" path = "fuzz_targets/instantiate_translated.rs" test = false doc = false +required-features = ['binaryen'] [[bin]] name = "api_calls" path = "fuzz_targets/api_calls.rs" test = false doc = false +required-features = ['binaryen'] [[bin]] name = "differential" path = "fuzz_targets/differential.rs" test = false doc = false +required-features = ['binaryen'] + +[features] +binaryen = ['wasmtime-fuzzing/binaryen'] diff --git a/fuzz/fuzz_targets/differential.rs b/fuzz/fuzz_targets/differential.rs index 5cf14f0523..edccf2daf8 100755 --- a/fuzz/fuzz_targets/differential.rs +++ b/fuzz/fuzz_targets/differential.rs @@ -9,5 +9,5 @@ fuzz_target!(|data: ( generators::WasmOptTtf )| { let (lhs, rhs, wasm) = data; - oracles::differential_execution(&wasm, &[lhs, rhs]); + oracles::differential_execution(&wasm.wasm, &[lhs, rhs]); });