]> git.proxmox.com Git - cargo.git/blob - vendor/semver/build.rs
New upstream version 0.63.1
[cargo.git] / vendor / semver / build.rs
1 use std::env;
2 use std::process::Command;
3 use std::str;
4
5 fn main() {
6 let compiler = match rustc_minor_version() {
7 Some(compiler) => compiler,
8 None => return,
9 };
10
11 if compiler < 33 {
12 // Exhaustive integer patterns. On older compilers, a final `_` arm is
13 // required even if every possible integer value is otherwise covered.
14 // https://github.com/rust-lang/rust/issues/50907
15 println!("cargo:rustc-cfg=no_exhaustive_int_match");
16 }
17
18 if compiler < 36 {
19 // extern crate alloc.
20 // https://blog.rust-lang.org/2019/07/04/Rust-1.36.0.html#the-alloc-crate-is-stable
21 println!("cargo:rustc-cfg=no_alloc_crate");
22 }
23
24 if compiler < 39 {
25 // const Vec::new.
26 // https://doc.rust-lang.org/std/vec/struct.Vec.html#method.new
27 println!("cargo:rustc-cfg=no_const_vec_new");
28 }
29
30 if compiler < 40 {
31 // #[non_exhaustive].
32 // https://blog.rust-lang.org/2019/12/19/Rust-1.40.0.html#non_exhaustive-structs-enums-and-variants
33 println!("cargo:rustc-cfg=no_non_exhaustive");
34 }
35
36 if compiler < 45 {
37 // String::strip_prefix.
38 // https://doc.rust-lang.org/std/primitive.str.html#method.strip_prefix
39 println!("cargo:rustc-cfg=no_str_strip_prefix");
40 }
41
42 if compiler < 46 {
43 // #[track_caller].
44 // https://blog.rust-lang.org/2020/08/27/Rust-1.46.0.html#track_caller
45 println!("cargo:rustc-cfg=no_track_caller");
46 }
47
48 if compiler < 52 {
49 // #![deny(unsafe_op_in_unsafe_fn)].
50 // https://github.com/rust-lang/rust/issues/71668
51 println!("cargo:rustc-cfg=no_unsafe_op_in_unsafe_fn_lint");
52 }
53
54 if compiler < 53 {
55 // Efficient intrinsics for count-leading-zeros and count-trailing-zeros
56 // on NonZero integers stabilized in 1.53.0. On many architectures these
57 // are more efficient than counting zeros on ordinary zeroable integers.
58 // https://doc.rust-lang.org/std/num/struct.NonZeroU64.html#method.leading_zeros
59 // https://doc.rust-lang.org/std/num/struct.NonZeroU64.html#method.trailing_zeros
60 println!("cargo:rustc-cfg=no_nonzero_bitscan");
61 }
62 }
63
64 fn rustc_minor_version() -> Option<u32> {
65 let rustc = env::var_os("RUSTC")?;
66 let output = Command::new(rustc).arg("--version").output().ok()?;
67 let version = str::from_utf8(&output.stdout).ok()?;
68 let mut pieces = version.split('.');
69 if pieces.next() != Some("rustc 1") {
70 return None;
71 }
72 pieces.next()?.parse().ok()
73 }