-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.rs
30 lines (25 loc) · 862 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
use std::{env, fs, path::PathBuf};
fn main() {
println!("cargo:rustc-cfg=const_fn_has_build_script");
let version = match Version::new() {
Some(version) => format!("{:#?}\n", version),
None => panic!("unexpected output from `rustc --version`"),
};
let out_dir = env::var_os("OUT_DIR").map(PathBuf::from).expect("OUT_DIR not set");
let out_file = out_dir.join("version.rs");
fs::write(out_file, version).expect("failed to write version.rs");
}
#[derive(Debug)]
struct Version {
minor: u16,
patch: u16,
nightly: bool,
}
impl Version {
fn new() -> Option<Self> {
let (version, channel, _date) = version_check::triple()?;
let (_major, minor, patch) = version.to_mmp();
let nightly = channel.is_nightly() || channel.is_dev();
Some(Version { minor, patch, nightly })
}
}