forked from wasmerio/wasmer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rs
65 lines (56 loc) · 2.29 KB
/
build.rs
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
//! The logic that gets executed before building the binary and tests.
//! We use it to auto-generate the Wasm spectests for each of the
//! available compilers.
//!
//! Please try to keep this file as clean as possible.
use std::env;
use std::fs;
use std::path::PathBuf;
use std::process::Command;
use test_generator::{
build_ignores_from_textfile, test_directory, test_directory_module, wast_processor,
with_backends, with_test_module, Testsuite,
};
fn is_truthy_env(name: &str) -> bool {
env::var(name).map(|n| n == "1").unwrap_or_default()
}
fn main() -> anyhow::Result<()> {
println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rerun-if-changed=tests/ignores.txt");
let out_dir = PathBuf::from(
env::var_os("OUT_DIR").expect("The OUT_DIR environment variable must be set"),
);
let ignores = build_ignores_from_textfile("tests/ignores.txt".into())?;
// Spectests test generation
let mut spectests = Testsuite {
buffer: String::new(),
path: vec![],
ignores: ignores.clone(),
};
let backends = vec!["singlepass", "cranelift", "llvm"];
with_backends(&mut spectests, &backends, |mut spectests| {
with_test_module(&mut spectests, "spec", |spectests| {
let _spec_tests = test_directory(spectests, "tests/wast/spec", wast_processor)?;
test_directory_module(
spectests,
"tests/wast/spec/proposals/multi-value",
wast_processor,
)?;
// test_directory_module(spectests, "tests/wast/spec/proposals/bulk-memory-operations", wast_processor)?;
Ok(())
})?;
with_test_module(&mut spectests, "wasmer", |spectests| {
let _spec_tests = test_directory(spectests, "tests/wast/wasmer", wast_processor)?;
Ok(())
})?;
Ok(())
})?;
let spectests_output = out_dir.join("generated_spectests.rs");
fs::write(&spectests_output, spectests.buffer)?;
// Write out our auto-generated tests and opportunistically format them with
// `rustfmt` if it's installed.
// Note: We need drop because we don't want to run `unwrap` or `expect` as
// the command might fail, but we don't care about it's result.
drop(Command::new("rustfmt").arg(&spectests_output).status());
Ok(())
}