forked from Gigoteur/UnicornConsole
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rs
40 lines (33 loc) · 1.05 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
use std::env;
use std::fs::File;
use std::io::Write;
use std::path::Path;
use std::io;
fn prebuild() -> io::Result<()> {
let out_dir = env::var("OUT_DIR").unwrap();
let dest_path = Path::new(&out_dir).join("parameters.rs");
let map_width = match env::var_os("PX8_MAP_WIDTH") {
Some(v) => v.into_string().unwrap(),
None => "128".to_string(),
};
let map_height = match env::var_os("PX8_MAP_HEIGHT") {
Some(v) => v.into_string().unwrap(),
None => "32".to_string(),
};
let mut f = File::create(&dest_path).unwrap();
f.write_all(format!("pub const MAP_WIDTH: usize = {:?};\n",
map_width.parse::<u32>().unwrap())
.as_bytes())
.unwrap();
f.write_all(format!("pub const MAP_HEIGHT: usize = {:?};\n",
map_height.parse::<u32>().unwrap())
.as_bytes())
.unwrap();
Ok(())
}
fn main() {
match prebuild() {
Err(e) => panic!("Error: {}", e),
Ok(()) => (),
}
}