Skip to content

Commit

Permalink
Panic if const-extern-fn is not used on nightly
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron1011 committed Oct 29, 2019
1 parent b0ba2de commit 476b675
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use std::process::Command;
use std::str;

fn main() {
let rustc_minor_ver =
rustc_minor_version().expect("Failed to get rustc version");
let (rustc_minor_ver, is_nightly) =
rustc_minor_nightly().expect("Failed to get rustc version");
let rustc_dep_of_std = env::var("CARGO_FEATURE_RUSTC_DEP_OF_STD").is_ok();
let align_cargo_feature = env::var("CARGO_FEATURE_ALIGN").is_ok();
let const_extern_fn_cargo_feature = env::var("CARGO_FEATURE_CONST_EXTERN_FN").is_ok();
Expand Down Expand Up @@ -75,11 +75,14 @@ fn main() {
}

if const_extern_fn_cargo_feature {
if !is_nightly || rustc_minor_ver < 40 {
panic!("const-extern-fn requires a nightly compiler >= 1.40")
}
println!("cargo:rustc-cfg=libc_const_extern_fn");
}
}

fn rustc_minor_version() -> Option<u32> {
fn rustc_minor_nightly() -> Option<(u32, bool)> {
macro_rules! otry {
($e:expr) => {
match $e {
Expand All @@ -98,7 +101,12 @@ fn rustc_minor_version() -> Option<u32> {
return None;
}

otry!(pieces.next()).parse().ok()
let minor = pieces.next();
let nightly_raw = otry!(otry!(pieces.next()).split('-').nth(1));
let nightly = nightly_raw.starts_with("dev") || nightly_raw.starts_with("nightly");
let minor = otry!(otry!(minor).parse().ok());

Some((minor, nightly))
}

fn which_freebsd() -> Option<i32> {
Expand Down

0 comments on commit 476b675

Please sign in to comment.