xref: /wasmtime-44.0.1/crates/fuzzing/build.rs (revision daee7fda)
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 
main()9 fn main() {
10     println!("cargo:rerun-if-changed=build.rs");
11     println!("cargo:rustc-check-cfg=cfg(arc_try_new)");
12 
13     let out_dir = PathBuf::from(env::var_os("OUT_DIR").unwrap());
14 
15     let mut root = env::current_dir().unwrap();
16     root.pop(); // chop off 'fuzzing'
17     root.pop(); // chop off 'crates'
18 
19     let mut tests = wasmtime_test_util::wast::find_tests(&root).unwrap();
20     tests.sort_by_key(|test| test.path.clone());
21 
22     let mut code = format!("static FILES: &[fn() -> wasmtime_test_util::wast::WastTest] = &[\n");
23 
24     for test in tests {
25         let WastTest {
26             path,
27             contents: _,
28             config,
29         } = test;
30         println!("cargo:rerun-if-changed={}", path.to_str().unwrap());
31         code.push_str(&format!(
32             "|| {{
33                 wasmtime_test_util::wast::WastTest {{
34                     path: {path:?}.into(),
35                     contents: include_str!({path:?}).into(),
36                     config: wasmtime_test_util::wast::{config:?},
37                 }}
38             }},"
39         ));
40     }
41 
42     code.push_str("];\n");
43     std::fs::write(out_dir.join("wasttests.rs"), code).unwrap();
44 }
45