-
-
Notifications
You must be signed in to change notification settings - Fork 130
/
build.rs
87 lines (75 loc) · 3.17 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
use std::env;
use std::process::Command;
use std::str;
fn main() {
println!("cargo:rerun-if-changed=build.rs");
let compiler = match rustc_minor_version() {
Some(compiler) => compiler,
None => return,
};
if compiler >= 80 {
println!("cargo:rustc-check-cfg=cfg(no_alloc_crate)");
println!("cargo:rustc-check-cfg=cfg(no_const_vec_new)");
println!("cargo:rustc-check-cfg=cfg(no_exhaustive_int_match)");
println!("cargo:rustc-check-cfg=cfg(no_non_exhaustive)");
println!("cargo:rustc-check-cfg=cfg(no_nonzero_bitscan)");
println!("cargo:rustc-check-cfg=cfg(no_str_strip_prefix)");
println!("cargo:rustc-check-cfg=cfg(no_track_caller)");
println!("cargo:rustc-check-cfg=cfg(no_unsafe_op_in_unsafe_fn_lint)");
println!("cargo:rustc-check-cfg=cfg(test_node_semver)");
}
if compiler < 33 {
// Exhaustive integer patterns. On older compilers, a final `_` arm is
// required even if every possible integer value is otherwise covered.
// https://github.com/rust-lang/rust/issues/50907
println!("cargo:rustc-cfg=no_exhaustive_int_match");
}
if compiler < 36 {
// extern crate alloc.
// https://blog.rust-lang.org/2019/07/04/Rust-1.36.0.html#the-alloc-crate-is-stable
println!("cargo:rustc-cfg=no_alloc_crate");
}
if compiler < 39 {
// const Vec::new.
// https://doc.rust-lang.org/std/vec/struct.Vec.html#method.new
println!("cargo:rustc-cfg=no_const_vec_new");
}
if compiler < 40 {
// #[non_exhaustive].
// https://blog.rust-lang.org/2019/12/19/Rust-1.40.0.html#non_exhaustive-structs-enums-and-variants
println!("cargo:rustc-cfg=no_non_exhaustive");
}
if compiler < 45 {
// String::strip_prefix.
// https://doc.rust-lang.org/std/primitive.str.html#method.strip_prefix
println!("cargo:rustc-cfg=no_str_strip_prefix");
}
if compiler < 46 {
// #[track_caller].
// https://blog.rust-lang.org/2020/08/27/Rust-1.46.0.html#track_caller
println!("cargo:rustc-cfg=no_track_caller");
}
if compiler < 52 {
// #![deny(unsafe_op_in_unsafe_fn)].
// https://github.com/rust-lang/rust/issues/71668
println!("cargo:rustc-cfg=no_unsafe_op_in_unsafe_fn_lint");
}
if compiler < 53 {
// Efficient intrinsics for count-leading-zeros and count-trailing-zeros
// on NonZero integers stabilized in 1.53.0. On many architectures these
// are more efficient than counting zeros on ordinary zeroable integers.
// https://doc.rust-lang.org/std/num/struct.NonZeroU64.html#method.leading_zeros
// https://doc.rust-lang.org/std/num/struct.NonZeroU64.html#method.trailing_zeros
println!("cargo:rustc-cfg=no_nonzero_bitscan");
}
}
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;
}
pieces.next()?.parse().ok()
}