forked from Gigoteur/UnicornConsole
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rs
34 lines (27 loc) · 950 Bytes
/
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
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 screen_width = match env::var_os("PX8_SCREEN_WIDTH") {
Some(v) => v.into_string().unwrap(),
None => "128".to_string(),
};
let screen_height = match env::var_os("PX8_SCREEN_HEIGHT") {
Some(v) => v.into_string().unwrap(),
None => "128".to_string(),
};
let mut f = File::create(&dest_path).unwrap();
f.write_all(format!("pub const SCREEN_WIDTH: usize = {:?};\n", screen_width.parse::<u32>().unwrap()).as_bytes());
f.write_all(format!("pub const SCREEN_HEIGHT: usize = {:?};\n", screen_height.parse::<u32>().unwrap()).as_bytes());
Ok(())
}
fn main() {
match prebuild() {
Err(e) => panic!("Error: {}", e),
Ok(()) => (),
}
}