From f043eacbfa5e18463bbf50f7f14885bb942c99e7 Mon Sep 17 00:00:00 2001 From: Trevor Spiteri Date: Mon, 13 Aug 2018 12:10:53 +0200 Subject: [PATCH] require rustc 1.28.0 --- README.md | 2 ++ build.rs | 30 ++++++++++++++++++++++++++---- src/lib.rs | 4 +++- 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index d3535e6..9cac721 100644 --- a/README.md +++ b/README.md @@ -107,6 +107,8 @@ You also need to declare it by adding this to your crate root (usually extern crate fixed; ``` +The *fixed* crate requires rustc version 1.28.0 or later. + ## License This crate is free software: you can redistribute it and/or modify it diff --git a/build.rs b/build.rs index 0c0d619..3c8c0d6 100644 --- a/build.rs +++ b/build.rs @@ -24,22 +24,39 @@ fn main() { }; env.check_feature( "repr_transparent", + Optional(false), TRY_REPR_TRANSPARENT, Some("repr_transparent"), ); } +#[derive(PartialEq)] +struct Optional(bool); + impl Environment { - fn check_feature(&self, name: &str, contents: &str, nightly_features: Option<&str>) { + // 1. If optional feature is availble (both with and without flag), output: + // cargo:rustc-cfg= + // 2. If feature is available with flag (both optional and not), output: + // cargo:rustc-cfg_nightly= + // 3. If non-optional feature is not available, panic. + fn check_feature( + &self, + name: &str, + optional: Optional, + contents: &str, + nightly_features: Option<&str>, + ) { let try_dir = self.out_dir.join(format!("try_{}", name)); let filename = format!("try_{}.rs", name); create_dir_or_panic(&try_dir); println!("$ cd {:?}", try_dir); + #[derive(PartialEq)] enum Iteration { Stable, Unstable, } + let mut found = false; for i in &[Iteration::Stable, Iteration::Unstable] { let s; let file_contents = match *i { @@ -61,15 +78,20 @@ impl Environment { .status() .unwrap_or_else(|_| panic!("Unable to execute: {:?}", cmd)); if status.success() { - println!("cargo:rustc-cfg={}", name); - if let Iteration::Unstable = *i { + if !optional.0 { + println!("cargo:rustc-cfg={}", name); + } + if *i == Iteration::Unstable { println!("cargo:rustc-cfg=nightly_{}", name); } + found = true; break; } } - remove_dir_or_panic(&try_dir); + if !found && !optional.0 { + panic!("essential feature not supported by compiler: {}", name); + } } } diff --git a/src/lib.rs b/src/lib.rs index cf3a7ef..96a64bb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -75,6 +75,8 @@ You also need to declare it by adding this to your crate root (usually extern crate fixed; ``` +The *fixed* crate requires rustc version 1.28.0 or later. + ## License This crate is free software: you can redistribute it and/or modify it @@ -306,7 +308,7 @@ macro_rules! fixed { "[const generics]: https://github.com/rust-lang/rust/issues/44580\n", "[typenum crate]: https://crates.io/crates/typenum\n" ), - #[cfg_attr(repr_transparent, repr(transparent))] + #[repr(transparent)] pub struct $Fixed(($Inner, PhantomData)); }