Skip to content

Commit

Permalink
Better support for nightly
Browse files Browse the repository at this point in the history
By treating nightly as the then-beta, time no longer relies on a feature
that may still be unstable.
  • Loading branch information
jhpratt committed Oct 2, 2020
1 parent 1a4b1a0 commit 97e45ea
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::env;
use version_check as rustc;

const MSRV: &str = "1.32.0";
const NO_STD_MSRV: &str = "1.36.0";
const MSRV: u16 = 32;
const NO_STD_MSRV: u16 = 36;

macro_rules! cfg_emit {
($s:ident) => {
Expand All @@ -24,16 +24,34 @@ fn main() {
cfg_emit!(__time_02_cargo_web);
}

// Treat nightly & dev compilers as the equivalent of the then-beta.
// As features are never stabilized in patch versions, we can safely ignore it.
let (effective_compiler_version, channel) = match rustc::triple() {
Some((version, channel, _)) if channel.is_dev() => (version.to_mmp().1 - 2, channel),
Some((version, channel, _)) if channel.is_nightly() => (version.to_mmp().1 - 1, channel),
Some((version, channel, _)) => (version.to_mmp().1, channel),
None => {
warning!(
"Unable to determine rustc version. Assuming rustc 1.{}.0.",
MSRV
);
(
MSRV,
rustc::Channel::parse("1.0.0").expect("This is a generic stable version."),
)
}
};

// Warn if the version is below MSRV.
if !rustc::is_min_version(MSRV).unwrap_or(false) {
if effective_compiler_version < MSRV {
warning!(
"The time crate has a minimum supported rust version of {}.",
MSRV
);
}

// Warn if the version is below `#![no_std]` MSRV.
if !rustc::is_min_version(NO_STD_MSRV).unwrap_or(false) {
if effective_compiler_version < NO_STD_MSRV {
#[cfg(not(feature = "std"))]
warning!(
"Using the time crate without the standard library enabled requires a global \
Expand All @@ -44,7 +62,7 @@ fn main() {
}

// Warn if the `__doc` feature is used on stable or beta.
if !rustc::Channel::read().map_or(false, |channel| channel.supports_features()) {
if !channel.supports_features() {
#[cfg(__time_02_docs)]
warning!(
"`--cfg __time_02_docs` requires a nightly compiler, and is intended for internal \
Expand All @@ -55,19 +73,19 @@ fn main() {
// ==== features that affect runtime directly ====

// `#[non_exhaustive]` was stabilized in 1.40.0.
if rustc::is_min_version("1.40.0").unwrap_or(false) {
if effective_compiler_version >= 40 {
cfg_emit!(__time_02_supports_non_exhaustive);
}

// `Instant::checked_add` and `Instant::checked_sub` were added in 1.34.0.
// `NonZeroI*` was stabilized in 1.34.0.
if rustc::is_min_version("1.34.0").unwrap_or(false) {
if effective_compiler_version >= 34 {
cfg_emit!(__time_02_instant_checked_ops);
cfg_emit!(__time_02_nonzero_signed);
}

// `use <trait> as _;` was stabilized in 1.33.0.
if rustc::is_min_version("1.33.0").unwrap_or(false) {
if effective_compiler_version >= 33 {
cfg_emit!(__time_02_use_trait_as_underscore);
}
}

0 comments on commit 97e45ea

Please sign in to comment.