Backed out 2 changesets (bug 903746) for causing non-unified build bustages on nsIPri...
[gecko.git] / third_party / rust / serde_json / build.rs
blob0e12602e466fb746f0baaf21abf5b06bf9acd57f
1 use std::env;
2 use std::process::Command;
3 use std::str::{self, FromStr};
5 fn main() {
6     println!("cargo:rerun-if-changed=build.rs");
8     // Decide ideal limb width for arithmetic in the float parser. Refer to
9     // src/lexical/math.rs for where this has an effect.
10     let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap();
11     match target_arch.as_str() {
12         "aarch64" | "mips64" | "powerpc64" | "x86_64" => {
13             println!("cargo:rustc-cfg=limb_width_64");
14         }
15         _ => {
16             println!("cargo:rustc-cfg=limb_width_32");
17         }
18     }
20     let minor = match rustc_minor_version() {
21         Some(minor) => minor,
22         None => return,
23     };
25     // BTreeMap::get_key_value
26     // https://blog.rust-lang.org/2019/12/19/Rust-1.40.0.html#additions-to-the-standard-library
27     if minor < 40 {
28         println!("cargo:rustc-cfg=no_btreemap_get_key_value");
29     }
31     // BTreeMap::remove_entry
32     // https://blog.rust-lang.org/2020/07/16/Rust-1.45.0.html#library-changes
33     if minor < 45 {
34         println!("cargo:rustc-cfg=no_btreemap_remove_entry");
35     }
37     // BTreeMap::retain
38     // https://blog.rust-lang.org/2021/06/17/Rust-1.53.0.html#stabilized-apis
39     if minor < 53 {
40         println!("cargo:rustc-cfg=no_btreemap_retain");
41     }
44 fn rustc_minor_version() -> Option<u32> {
45     let rustc = env::var_os("RUSTC")?;
46     let output = Command::new(rustc).arg("--version").output().ok()?;
47     let version = str::from_utf8(&output.stdout).ok()?;
48     let mut pieces = version.split('.');
49     if pieces.next() != Some("rustc 1") {
50         return None;
51     }
52     let next = pieces.next()?;
53     u32::from_str(next).ok()