blob: e9ec7d56aeb40c51610f6e696b2f3d4d1eb5576c [file] [log] [blame]
Yi Kongd600cb02020-08-31 01:25:28 +08001use std::env;
Chih-Hung Hsiehb93bfcb2020-10-26 13:16:59 -07002use std::process::Command;
3use std::str::{self, FromStr};
Yi Kongd600cb02020-08-31 01:25:28 +08004
5fn main() {
6 // Decide ideal limb width for arithmetic in the float parser. Refer to
7 // src/lexical/math.rs for where this has an effect.
8 let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap();
9 match target_arch.as_str() {
10 "aarch64" | "mips64" | "powerpc64" | "x86_64" => {
11 println!("cargo:rustc-cfg=limb_width_64");
12 }
13 _ => {
14 println!("cargo:rustc-cfg=limb_width_32");
15 }
16 }
Chih-Hung Hsiehb93bfcb2020-10-26 13:16:59 -070017
18 let minor = match rustc_minor_version() {
19 Some(minor) => minor,
20 None => return,
21 };
22
23 // BTreeMap::get_key_value
24 // https://blog.rust-lang.org/2019/12/19/Rust-1.40.0.html#additions-to-the-standard-library
25 if minor < 40 {
26 println!("cargo:rustc-cfg=no_btreemap_get_key_value");
27 }
28
29 // BTreeMap::remove_entry
30 // https://blog.rust-lang.org/2020/07/16/Rust-1.45.0.html#library-changes
31 if minor < 45 {
32 println!("cargo:rustc-cfg=no_btreemap_remove_entry");
33 }
David LeGare2f2c4652022-03-02 16:21:22 +000034
35 // BTreeMap::retain
36 // https://blog.rust-lang.org/2021/06/17/Rust-1.53.0.html#stabilized-apis
37 if minor < 53 {
38 println!("cargo:rustc-cfg=no_btreemap_retain");
39 }
Chih-Hung Hsiehb93bfcb2020-10-26 13:16:59 -070040}
41
42fn rustc_minor_version() -> Option<u32> {
43 let rustc = env::var_os("RUSTC")?;
44 let output = Command::new(rustc).arg("--version").output().ok()?;
45 let version = str::from_utf8(&output.stdout).ok()?;
46 let mut pieces = version.split('.');
47 if pieces.next() != Some("rustc 1") {
48 return None;
49 }
50 let next = pieces.next()?;
51 u32::from_str(next).ok()
Yi Kongd600cb02020-08-31 01:25:28 +080052}