File: build.rs

package info (click to toggle)
rust-wasmtime 26.0.1%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 48,492 kB
  • sloc: ansic: 4,003; sh: 561; javascript: 542; cpp: 254; asm: 175; ml: 96; makefile: 55
file content (42 lines) | stat: -rw-r--r-- 1,387 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// A small build script to include the contents of the wast 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 dirs = [
        "tests/spec_testsuite",
        "tests/misc_testsuite",
        "tests/misc_testsuite/multi-memory",
        "tests/misc_testsuite/simd",
        "tests/misc_testsuite/threads",
    ];
    let mut root = env::current_dir().unwrap();
    root.pop(); // chop off 'fuzzing'
    root.pop(); // chop off 'crates'
    let mut code = format!("static FILES: &[(&str, &str)] = &[\n");

    let mut entries = Vec::new();
    for dir in dirs {
        for entry in root.join(dir).read_dir().unwrap() {
            let entry = entry.unwrap();
            let path = entry.path();
            if path.extension().and_then(|s| s.to_str()) == Some("wast") {
                entries.push(path);
            }
        }
    }
    entries.sort();
    for path in entries {
        let path = path.to_str().expect("path is not valid utf-8");
        code.push_str(&format!("({path:?}, include_str!({path:?})),\n"));
    }
    code.push_str("];\n");
    std::fs::write(out_dir.join("wasttests.rs"), code).unwrap();
}