forked from serde-rs/json
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rs
54 lines (47 loc) · 1.63 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
44
45
46
47
48
49
50
51
52
53
54
use std::env;
use std::process::Command;
use std::str::{self, FromStr};
fn main() {
println!("cargo:rerun-if-changed=build.rs");
// Decide ideal limb width for arithmetic in the float parser. Refer to
// src/lexical/math.rs for where this has an effect.
let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap();
match target_arch.as_str() {
"aarch64" | "mips64" | "powerpc64" | "x86_64" => {
println!("cargo:rustc-cfg=limb_width_64");
}
_ => {
println!("cargo:rustc-cfg=limb_width_32");
}
}
let minor = match rustc_minor_version() {
Some(minor) => minor,
None => return,
};
// BTreeMap::get_key_value
// https://blog.rust-lang.org/2019/12/19/Rust-1.40.0.html#additions-to-the-standard-library
if minor < 40 {
println!("cargo:rustc-cfg=no_btreemap_get_key_value");
}
// BTreeMap::remove_entry
// https://blog.rust-lang.org/2020/07/16/Rust-1.45.0.html#library-changes
if minor < 45 {
println!("cargo:rustc-cfg=no_btreemap_remove_entry");
}
// BTreeMap::retain
// https://blog.rust-lang.org/2021/06/17/Rust-1.53.0.html#stabilized-apis
if minor < 53 {
println!("cargo:rustc-cfg=no_btreemap_retain");
}
}
fn rustc_minor_version() -> Option<u32> {
let rustc = env::var_os("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;
}
let next = pieces.next()?;
u32::from_str(next).ok()
}