-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathbuild.rs
More file actions
38 lines (32 loc) · 1.08 KB
/
build.rs
File metadata and controls
38 lines (32 loc) · 1.08 KB
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::ffi::OsString;
use std::process::{self, Command};
use std::str;
fn main() {
println!("cargo:rerun-if-changed=build.rs");
let rustc = rustc_minor_version().unwrap_or(u32::MAX);
if rustc >= 80 {
println!("cargo:rustc-check-cfg=cfg(exhaustive)");
println!("cargo:rustc-check-cfg=cfg(zmij_no_select_unpredictable)");
}
if rustc < 88 {
// https://doc.rust-lang.org/std/hint/fn.select_unpredictable.html
println!("cargo:rustc-cfg=zmij_no_select_unpredictable");
}
}
fn rustc_minor_version() -> Option<u32> {
let rustc = cargo_env_var("RUSTC");
let output = Command::new(rustc).arg("--version").output().ok()?;
let version = str::from_utf8(&output.stdout).ok()?;
let mut pieces = version.split('.');
if pieces.next() != Some("rustc 1") {
return None;
}
pieces.next()?.parse().ok()
}
fn cargo_env_var(key: &str) -> OsString {
env::var_os(key).unwrap_or_else(|| {
eprintln!("Environment variable ${key} is not set during execution of build script");
process::exit(1);
})
}