-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rs
23 lines (18 loc) · 876 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
// NOTE: This file is excluded from Cargo.toml !
// docs.rs instead configures this via [package.metadata.docs.rs]
use std::process::Command;
fn main() {
if is_nightly().unwrap_or(false) {
println!("cargo:rustc-cfg=external_doc");
}
}
fn is_nightly() -> Result<bool, Box<dyn std::error::Error>> {
let o = Command::new("rustc").arg("--version").output()?;
let stdout = String::from_utf8(o.stdout)?;
let mut fragments = stdout.split(' ');
let _rustc = fragments.next().unwrap_or(""); // "rustc"
let _ver = fragments.next().unwrap_or(""); // "1.47.0-nightly"
let _hash = fragments.next().unwrap_or("").trim_start_matches('('); // "(bf4342114"
let _date = fragments.next().unwrap_or("").trim_end_matches(')'); // "2020-08-25)"
Ok(_ver.ends_with("-nightly"))
}