From 21112cf9d8aadab4d0fdcd2b1847a19bb7b631b3 Mon Sep 17 00:00:00 2001 From: michele Date: Sun, 12 Dec 2021 09:02:06 +0100 Subject: [PATCH] Close #126 --- build.rs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/build.rs b/build.rs index 357566e..580edcb 100644 --- a/build.rs +++ b/build.rs @@ -1,11 +1,28 @@ use rustc_version::{version, version_meta, Channel}; +fn allow_features() -> Option> { + 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"); } _ => {}