1 // A small build script to include the contents of the wast test suite into the 2 // final fuzzing binary so the fuzzing binary can be run elsewhere and doesn't 3 // rely on the original source tree. 4 5 use std::env; 6 use std::path::PathBuf; 7 use wasmtime_test_util::wast::WastTest; 8 9 fn main() { 10 println!("cargo:rerun-if-changed=build.rs"); 11 12 let out_dir = PathBuf::from(env::var_os("OUT_DIR").unwrap()); 13 14 let mut root = env::current_dir().unwrap(); 15 root.pop(); // chop off 'fuzzing' 16 root.pop(); // chop off 'crates' 17 18 let mut tests = wasmtime_test_util::wast::find_tests(&root).unwrap(); 19 tests.sort_by_key(|test| test.path.clone()); 20 21 let mut code = format!("static FILES: &[fn() -> wasmtime_test_util::wast::WastTest] = &[\n"); 22 23 for test in tests { 24 let WastTest { 25 path, 26 contents: _, 27 config, 28 } = test; 29 println!("cargo:rerun-if-changed={}", path.to_str().unwrap()); 30 code.push_str(&format!( 31 "|| {{ 32 wasmtime_test_util::wast::WastTest {{ 33 path: {path:?}.into(), 34 contents: include_str!({path:?}).into(), 35 config: wasmtime_test_util::wast::{config:?}, 36 }} 37 }}," 38 )); 39 } 40 41 code.push_str("];\n"); 42 std::fs::write(out_dir.join("wasttests.rs"), code).unwrap(); 43 } 44