forked from JelteF/derive_more
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.rs
53 lines (45 loc) · 1.38 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
#[cfg(feature = "testing-helpers")]
extern crate rustc_version;
#[cfg(feature = "generate-parsing-rs")]
extern crate peg;
#[cfg(not(feature = "generate-parsing-rs"))]
fn generate_peg() {}
#[cfg(feature = "generate-parsing-rs")]
fn generate_peg() {
let contents = match ::std::fs::read_to_string("src/parsing.rustpeg") {
Ok(contents) => contents,
Err(e) => panic!("{}", e),
};
let compiled = match ::peg::compile(&contents) {
Ok(compiled) => compiled,
Err(e) => panic!("{}", e),
};
if let Err(e) = ::std::fs::write("src/parsing.rs", compiled) {
panic!("{}", e);
}
}
#[cfg(not(feature = "testing-helpers"))]
fn detect_nightly() {}
#[cfg(feature = "testing-helpers")]
fn detect_nightly() {
use rustc_version::{version_meta, Channel};
if version_meta().unwrap().channel == Channel::Nightly {
println!("cargo:rustc-cfg=feature=\"nightly\"");
}
}
#[cfg(not(feature = "unwrap"))]
fn detect_track_caller() {}
/// Detect availability of the `#[track_caller]` attribute for
/// use in derived panicking methods like `.unwrap_*()`.
#[cfg(feature = "unwrap")]
fn detect_track_caller() {
use rustc_version::version_meta;
if version_meta().unwrap().semver.minor >= 46 {
println!("cargo:rustc-cfg=feature=\"track-caller\"");
}
}
fn main() {
detect_nightly();
detect_track_caller();
generate_peg();
}