-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathbuild.rs
38 lines (30 loc) · 1.2 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
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("config.rs");
let gps_period: u32 = option_env!("GPS_PERIOD")
.map(|p| p.parse::<u32>().unwrap())
.unwrap_or(60);
let gps_heartbeat: i32 = option_env!("GPS_HEARTBEAT")
.map(|p| p.parse::<i32>().unwrap())
.unwrap_or(1);
let sync_period: u32 = option_env!("SYNC_PERIOD")
.map(|p| p.parse::<u32>().unwrap())
.unwrap_or(20);
let fd = fs::File::create(&dest_path).unwrap();
writeln!(&fd, "pub const GPS_PERIOD: u32 = {gps_period};").unwrap();
writeln!(&fd, "pub const GPS_HEARTBEAT: i32 = {gps_heartbeat};").unwrap();
writeln!(&fd, "pub const SYNC_PERIOD: u32 = {sync_period};").unwrap();
if option_env!("BUOYSN").is_none() {
println!("cargo:warning=BUOYSN: No buoy name supplied, using device id or previously configured.");
}
if option_env!("BUOYPR").is_none() {
println!(
"cargo:warning=BUOYPR: No notehub modem product supplied, using previously configured."
);
}
println!("cargo:rerun-if-changed=build.rs");
}