-
Notifications
You must be signed in to change notification settings - Fork 256
Expand file tree
/
Copy pathbuild.rs
More file actions
25 lines (22 loc) · 736 Bytes
/
build.rs
File metadata and controls
25 lines (22 loc) · 736 Bytes
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
use std::env;
use std::process::Command;
use std::str;
fn main() {
let minor_ver = rustc_minor().expect("failed to get rustc version");
if minor_ver >= 40 {
println!("cargo:rustc-cfg=getrandom_non_exhaustive");
}
}
// Based on libc's implementation:
// https://github.com/rust-lang/libc/blob/74e81a50c2528b01507e9d03f594949c0f91c817/build.rs#L168-L205
fn rustc_minor() -> Option<u32> {
let rustc = env::var_os("RUSTC")?;
let output = Command::new(rustc).arg("--version").output().ok()?.stdout;
let version = str::from_utf8(&output).ok()?;
let mut pieces = version.split('.');
if pieces.next()? != "rustc 1" {
return None;
}
let minor = pieces.next()?;
minor.parse().ok()
}