-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.rs
More file actions
47 lines (39 loc) · 1.37 KB
/
build.rs
File metadata and controls
47 lines (39 loc) · 1.37 KB
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
use std::env;
use std::fs::File;
use std::io::Write;
use std::path::Path;
fn main() {
let out_dir = env::var("OUT_DIR").unwrap();
let dest_path = Path::new(&out_dir).join("cmake_versions.rs");
let mut f = File::create(&dest_path).unwrap();
// Generate the enum.
writeln!(f, "#[derive(Debug, Clone, ValueEnum)]").unwrap();
writeln!(f, "pub enum CMakeVersion {{").unwrap();
let versions = vec![
(4, 0..=2), // 4.0 to 4.2
(3, 0..=31), // 3.0 to 3.31
];
for (major, minor_range) in &versions {
for minor in minor_range.clone() {
writeln!(f, " #[value(name = \"{}.{}\")]", major, minor).unwrap();
writeln!(f, " CMake{}_{},\n", major, minor).unwrap();
}
}
writeln!(f, "}}\n").unwrap();
// Generate the as_str method.
writeln!(f, "impl CMakeVersion {{").unwrap();
writeln!(f, " pub fn as_str(&self) -> &'static str {{").unwrap();
writeln!(f, " match self {{").unwrap();
for (major, minor_range) in &versions {
for minor in minor_range.clone() {
writeln!(
f,
" CMakeVersion::CMake{}_{} => \"{}.{}\",",
major, minor, major, minor
).unwrap();
}
}
writeln!(f, " }}").unwrap();
writeln!(f, " }}").unwrap();
writeln!(f, "}}").unwrap();
}