-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.rs
36 lines (31 loc) · 1.2 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
use std::fs;
use std::io::Write;
use std::path::Path;
use serde_yaml::Value;
fn main() {
println!("cargo:rerun-if-changed=config.yml");
let config_path = Path::new("config.yml");
let out_dir = std::env::var("OUT_DIR").expect("OUT_DIR not set");
let dest_path = Path::new(&out_dir).join("language_tests.rs");
// Read and parse `config.yml`
let config_content = fs::read_to_string(config_path).expect("Failed to read config.yml");
let config: Value = serde_yaml::from_str(&config_content).expect("Failed to parse config.yml");
let languages = config
.get("languages")
.expect("Missing 'languages' key in config.yml")
.as_mapping()
.expect("'languages' should be a mapping")
.keys()
.map(|k| k.as_str().expect("Language keys should be strings").to_string())
.collect::<Vec<String>>();
// Generate language tests in `language_tests.rs`
let mut file = fs::File::create(dest_path).expect("Failed to create language_tests.rs");
for lang in languages {
writeln!(
file,
"#[test]\nfn language_test_{}() {{ execute_language_template(\"{}\"); }}",
lang, lang
)
.unwrap();
}
}