Detect and allow older nightlies

This commit is contained in:
Dániel Buga 2024-11-06 10:44:01 +01:00
parent e4f611b97c
commit 1e850ae791
No known key found for this signature in database
5 changed files with 76 additions and 1 deletions

View File

@ -57,6 +57,9 @@ avr-device = { version = "0.5.3", optional = true }
critical-section = { version = "1.1", features = ["std"] }
trybuild = "1.0"
[build-dependencies]
rustc_version = "0.4.1"
[features]
## Enable nightly-only features

View File

@ -96,4 +96,15 @@ fn main() {
let mut rustc_cfgs = common::CfgSet::new();
common::set_target_cfgs(&mut rustc_cfgs);
// Waker API changed on 2024-09-06
rustc_cfgs.declare("at_least_2024_09_06");
let Some(compiler) = common::compiler_info() else {
return;
};
if compiler.channel == rustc_version::Channel::Nightly
&& compiler.commit_date.map(|d| d >= "2024-09-06").unwrap_or(false)
{
rustc_cfgs.enable("at_least_2024_09_06");
}
}

View File

@ -92,3 +92,54 @@ pub fn set_target_cfgs(cfgs: &mut CfgSet) {
cfgs.set("has_fpu", target.ends_with("-eabihf"));
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub struct CompilerDate {
year: u16,
month: u8,
day: u8,
}
impl CompilerDate {
fn parse(date: &str) -> Option<Self> {
let mut parts = date.split('-');
let year = parts.next()?.parse().ok()?;
let month = parts.next()?.parse().ok()?;
let day = parts.next()?.parse().ok()?;
Some(Self { year, month, day })
}
}
impl PartialEq<&str> for CompilerDate {
fn eq(&self, other: &&str) -> bool {
let Some(other) = Self::parse(other) else {
return false;
};
self.eq(&other)
}
}
impl PartialOrd<&str> for CompilerDate {
fn partial_cmp(&self, other: &&str) -> Option<std::cmp::Ordering> {
Self::parse(other).map(|other| self.cmp(&other))
}
}
pub struct CompilerInfo {
#[allow(unused)]
pub version: rustc_version::Version,
pub channel: rustc_version::Channel,
pub commit_date: Option<CompilerDate>,
}
pub fn compiler_info() -> Option<CompilerInfo> {
let Ok(meta) = rustc_version::version_meta() else {
return None;
};
Some(CompilerInfo {
version: meta.semver,
channel: meta.channel,
commit_date: meta.commit_date.as_deref().and_then(CompilerDate::parse),
})
}

View File

@ -1,4 +1,5 @@
#![cfg_attr(not(any(feature = "arch-std", feature = "arch-wasm")), no_std)]
#![cfg_attr(all(feature = "nightly", not(at_least_2024_09_06)), feature(waker_getters))]
#![allow(clippy::new_without_default)]
#![doc = include_str!("../README.md")]
#![warn(missing_docs)]

View File

@ -50,7 +50,16 @@ pub fn task_from_waker(waker: &Waker) -> TaskRef {
#[cfg(feature = "nightly")]
{
(waker.vtable(), waker.data())
#[cfg(not(at_least_2024_09_06))]
{
let raw_waker = waker.as_raw();
(raw_waker.vtable(), raw_waker.data())
}
#[cfg(at_least_2024_09_06)]
{
(waker.vtable(), waker.data())
}
}
};