forked from frugalos/frugalos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.rs
43 lines (38 loc) · 1.36 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
#[macro_use]
extern crate trackable;
use std::env;
use std::fs::File;
use std::io::Write;
use std::path::Path;
use std::process::Command;
macro_rules! track_any_err_unwrap {
($expr:expr) => {
track_try_unwrap!(track_any_err!($expr))
};
}
fn main() {
/*
* for `PROFILE`, `RUSTC`, and `OUT_DIR` options, see the following:
* https://doc.rust-lang.org/cargo/reference/environment-variables.html#environment-variables-cargo-sets-for-build-scripts
*/
let profile = track_any_err_unwrap!(env::var("PROFILE"));
let rustc = track_any_err_unwrap!(env::var("RUSTC"));
let version = track_any_err_unwrap!(Command::new(rustc).arg("--version").output()).stdout;
let version = track_any_err_unwrap!(String::from_utf8(version));
let version = version.trim();
let out_dir = track_any_err_unwrap!(env::var("OUT_DIR"));
let dest_path = Path::new(&out_dir).join("build_information.rs");
let mut file = track_any_err_unwrap!(File::create(&dest_path));
track_any_err_unwrap!(file.write_all(
format!(
"
/// This takes one of \"debug\" or \"release\", that we've used to build this frugalos.
pub static BUILD_PROFILE: &str = \"{}\";\n\n
/// This means the rustc version that we've used to build this frugalos.
pub static BUILD_VERSION: &str = \"{}\";
",
profile, version
)
.as_bytes(),
));
}