-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.rs
44 lines (39 loc) · 1.34 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
use std::env;
use std::fs::File;
use std::io::{BufRead, BufReader, Write};
use std::path::PathBuf;
// Words that are candidates for answers
const WORDS_USED_FILENAME: &str = "words-used.txt";
const WORDS_XTRA_FILENAME: &str = "words-extra.txt";
pub fn main() {
// Parse the word lists and build into the binary. They don't change, and there aren't that many
let manifest_dir =
PathBuf::from(env::var("CARGO_MANIFEST_DIR").expect("ENV{CARGO_MANIFEST_DIR}"));
let mut wordfile =
File::create(PathBuf::from(env::var("OUT_DIR").expect("ENV{OUT_DIR}")).join("words.rs"))
.expect("File::create");
let words_used: Vec<String> =
BufReader::new(File::open(manifest_dir.join(WORDS_USED_FILENAME)).expect("open"))
.lines()
.take_while(Result::is_ok)
.map(Result::unwrap)
.collect();
write!(
wordfile,
"pub const WORDS_USED: &[&str] = &{:?};",
words_used
)
.expect("write");
let words_used: Vec<String> =
BufReader::new(File::open(manifest_dir.join(WORDS_XTRA_FILENAME)).expect("open"))
.lines()
.take_while(Result::is_ok)
.map(Result::unwrap)
.collect();
write!(
wordfile,
"pub const WORDS_XTRA: &[&str] = &{:?};",
words_used
)
.expect("write");
}