-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.rs
54 lines (51 loc) · 1.37 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
use std::env;
use std::fs;
use std::io::Write;
use std::path::Path;
fn main() {
let out_dir = env::var_os("OUT_DIR").unwrap();
let dest_path = Path::new(&out_dir).join("data.rs");
let mut target = fs::File::create(&dest_path).unwrap();
target
.write(
r#"
use lazy_static::lazy_static;
use std::collections::BTreeSet;
lazy_static! {
pub static ref TRAINING_SETS: BTreeSet<&'static str> =
BTreeSet::from([
"#
.as_bytes(),
)
.unwrap();
for entry in fs::read_dir("assets/data").unwrap() {
let entry = entry.unwrap();
if entry.file_type().unwrap().is_file()
&& entry.file_name().to_string_lossy().ends_with(".txt")
{
let filename = entry.file_name().to_string_lossy().to_string();
target
.write(
format!(
"// {}\nstd::str::from_utf8({:?}.as_slice()).unwrap(),\n",
filename,
&filename[..filename.len() - 4].as_bytes(),
)
.as_bytes(),
)
.unwrap();
}
}
target
.write(
r#"
]
);
}
"#
.as_bytes(),
)
.unwrap();
println!("cargo:rerun-if-changed=data");
println!("cargo:rerun-if-changed=build.rs");
}