Skip to content

Commit

Permalink
Close #126
Browse files Browse the repository at this point in the history
  • Loading branch information
la10736 committed Dec 12, 2021
1 parent 93a6c8a commit 21112cf
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion build.rs
@@ -1,11 +1,28 @@
use rustc_version::{version, version_meta, Channel};

fn allow_features() -> Option<Vec<String>> {
std::env::var("CARGO_ENCODED_RUSTFLAGS").ok().map(|args| {
args.split('\u{001f}')
.filter(|arg| arg.starts_with("-Zallow-features="))
.map(|arg| arg.split('=').nth(1).unwrap())
.flat_map(|features| features.split(','))
.map(|f| f.to_owned())
.collect()
})
}

fn can_enable_proc_macro_diagnostic() -> bool {
allow_features()
.map(|f| f.iter().any(|f| dbg!(f) == "proc_macro_diagnostic"))
.unwrap_or(true)
}

fn main() {
let ver = version().unwrap();
assert!(ver.major >= 1);

match version_meta().unwrap().channel {
Channel::Nightly | Channel::Dev => {
Channel::Nightly | Channel::Dev if can_enable_proc_macro_diagnostic() => {
println!("cargo:rustc-cfg=use_proc_macro_diagnostic");
}
_ => {}
Expand Down

0 comments on commit 21112cf

Please sign in to comment.