//! This file will run at build time to autogenerate the Emscripten tests //! It will compile the files indicated in TESTS, to:executable and .wasm //! - Compile using cc and get the output from it (expected output) //! - Compile using emcc and get the .wasm from it (wasm) //! - Generate the test that will compare the output of running the .wasm file //! with wasmer with the expected output use std::env; use std::fs; use std::path::PathBuf; static BANNER: &str = "// Rust test file autogenerated with cargo build (build/emtests.rs). // Please do NOT modify it by hand, as it will be reseted on next build.\n"; const TESTS: [&str; 1] = [ "emtests/localtime.c" ]; pub fn build() { let rust_test_modpath = concat!(env!("CARGO_MANIFEST_DIR"), "/src/emtests/mod.rs"); let mut modules: Vec = Vec::new(); // modules.reserve_exact(TESTS.len()); modules.insert(0, BANNER.to_string()); // We add an empty line modules.push("".to_string()); let modfile: String = modules.join("\n"); let source = fs::read(&rust_test_modpath).unwrap(); // We only modify the mod file if has changed if source != modfile.as_bytes() { fs::write(&rust_test_modpath, modfile.as_bytes()).unwrap(); } }