diff options
| author | Dániel Buga <[email protected]> | 2024-11-06 10:44:01 +0100 |
|---|---|---|
| committer | Dániel Buga <[email protected]> | 2024-11-06 10:48:59 +0100 |
| commit | 1e850ae79149e737c1ba39a383596eabcb0bb940 (patch) | |
| tree | a9b9c47c01b444f370ed8194653f3ef45c72cbc8 /embassy-executor | |
| parent | e4f611b97c886582dc99b03e93e8f8411f61c45a (diff) | |
Detect and allow older nightlies
Diffstat (limited to 'embassy-executor')
| -rw-r--r-- | embassy-executor/Cargo.toml | 3 | ||||
| -rw-r--r-- | embassy-executor/build.rs | 11 | ||||
| -rw-r--r-- | embassy-executor/build_common.rs | 51 | ||||
| -rw-r--r-- | embassy-executor/src/lib.rs | 1 | ||||
| -rw-r--r-- | embassy-executor/src/raw/waker.rs | 11 |
5 files changed, 76 insertions, 1 deletions
diff --git a/embassy-executor/Cargo.toml b/embassy-executor/Cargo.toml index 22a176621..6011d8663 100644 --- a/embassy-executor/Cargo.toml +++ b/embassy-executor/Cargo.toml | |||
| @@ -57,6 +57,9 @@ avr-device = { version = "0.5.3", optional = true } | |||
| 57 | critical-section = { version = "1.1", features = ["std"] } | 57 | critical-section = { version = "1.1", features = ["std"] } |
| 58 | trybuild = "1.0" | 58 | trybuild = "1.0" |
| 59 | 59 | ||
| 60 | [build-dependencies] | ||
| 61 | rustc_version = "0.4.1" | ||
| 62 | |||
| 60 | [features] | 63 | [features] |
| 61 | 64 | ||
| 62 | ## Enable nightly-only features | 65 | ## Enable nightly-only features |
diff --git a/embassy-executor/build.rs b/embassy-executor/build.rs index 8a41d7503..c4c86e1e2 100644 --- a/embassy-executor/build.rs +++ b/embassy-executor/build.rs | |||
| @@ -96,4 +96,15 @@ fn main() { | |||
| 96 | 96 | ||
| 97 | let mut rustc_cfgs = common::CfgSet::new(); | 97 | let mut rustc_cfgs = common::CfgSet::new(); |
| 98 | common::set_target_cfgs(&mut rustc_cfgs); | 98 | common::set_target_cfgs(&mut rustc_cfgs); |
| 99 | |||
| 100 | // Waker API changed on 2024-09-06 | ||
| 101 | rustc_cfgs.declare("at_least_2024_09_06"); | ||
| 102 | let Some(compiler) = common::compiler_info() else { | ||
| 103 | return; | ||
| 104 | }; | ||
| 105 | if compiler.channel == rustc_version::Channel::Nightly | ||
| 106 | && compiler.commit_date.map(|d| d >= "2024-09-06").unwrap_or(false) | ||
| 107 | { | ||
| 108 | rustc_cfgs.enable("at_least_2024_09_06"); | ||
| 109 | } | ||
| 99 | } | 110 | } |
diff --git a/embassy-executor/build_common.rs b/embassy-executor/build_common.rs index 4f24e6d37..af6bb0618 100644 --- a/embassy-executor/build_common.rs +++ b/embassy-executor/build_common.rs | |||
| @@ -92,3 +92,54 @@ pub fn set_target_cfgs(cfgs: &mut CfgSet) { | |||
| 92 | 92 | ||
| 93 | cfgs.set("has_fpu", target.ends_with("-eabihf")); | 93 | cfgs.set("has_fpu", target.ends_with("-eabihf")); |
| 94 | } | 94 | } |
| 95 | |||
| 96 | #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] | ||
| 97 | pub struct CompilerDate { | ||
| 98 | year: u16, | ||
| 99 | month: u8, | ||
| 100 | day: u8, | ||
| 101 | } | ||
| 102 | |||
| 103 | impl CompilerDate { | ||
| 104 | fn parse(date: &str) -> Option<Self> { | ||
| 105 | let mut parts = date.split('-'); | ||
| 106 | let year = parts.next()?.parse().ok()?; | ||
| 107 | let month = parts.next()?.parse().ok()?; | ||
| 108 | let day = parts.next()?.parse().ok()?; | ||
| 109 | Some(Self { year, month, day }) | ||
| 110 | } | ||
| 111 | } | ||
| 112 | |||
| 113 | impl PartialEq<&str> for CompilerDate { | ||
| 114 | fn eq(&self, other: &&str) -> bool { | ||
| 115 | let Some(other) = Self::parse(other) else { | ||
| 116 | return false; | ||
| 117 | }; | ||
| 118 | self.eq(&other) | ||
| 119 | } | ||
| 120 | } | ||
| 121 | |||
| 122 | impl PartialOrd<&str> for CompilerDate { | ||
| 123 | fn partial_cmp(&self, other: &&str) -> Option<std::cmp::Ordering> { | ||
| 124 | Self::parse(other).map(|other| self.cmp(&other)) | ||
| 125 | } | ||
| 126 | } | ||
| 127 | |||
| 128 | pub struct CompilerInfo { | ||
| 129 | #[allow(unused)] | ||
| 130 | pub version: rustc_version::Version, | ||
| 131 | pub channel: rustc_version::Channel, | ||
| 132 | pub commit_date: Option<CompilerDate>, | ||
| 133 | } | ||
| 134 | |||
| 135 | pub fn compiler_info() -> Option<CompilerInfo> { | ||
| 136 | let Ok(meta) = rustc_version::version_meta() else { | ||
| 137 | return None; | ||
| 138 | }; | ||
| 139 | |||
| 140 | Some(CompilerInfo { | ||
| 141 | version: meta.semver, | ||
| 142 | channel: meta.channel, | ||
| 143 | commit_date: meta.commit_date.as_deref().and_then(CompilerDate::parse), | ||
| 144 | }) | ||
| 145 | } | ||
diff --git a/embassy-executor/src/lib.rs b/embassy-executor/src/lib.rs index d816539ac..8e07a8b18 100644 --- a/embassy-executor/src/lib.rs +++ b/embassy-executor/src/lib.rs | |||
| @@ -1,4 +1,5 @@ | |||
| 1 | #![cfg_attr(not(any(feature = "arch-std", feature = "arch-wasm")), no_std)] | 1 | #![cfg_attr(not(any(feature = "arch-std", feature = "arch-wasm")), no_std)] |
| 2 | #![cfg_attr(all(feature = "nightly", not(at_least_2024_09_06)), feature(waker_getters))] | ||
| 2 | #![allow(clippy::new_without_default)] | 3 | #![allow(clippy::new_without_default)] |
| 3 | #![doc = include_str!("../README.md")] | 4 | #![doc = include_str!("../README.md")] |
| 4 | #![warn(missing_docs)] | 5 | #![warn(missing_docs)] |
diff --git a/embassy-executor/src/raw/waker.rs b/embassy-executor/src/raw/waker.rs index 8bb2cfd05..30b8cdd4c 100644 --- a/embassy-executor/src/raw/waker.rs +++ b/embassy-executor/src/raw/waker.rs | |||
| @@ -50,7 +50,16 @@ pub fn task_from_waker(waker: &Waker) -> TaskRef { | |||
| 50 | 50 | ||
| 51 | #[cfg(feature = "nightly")] | 51 | #[cfg(feature = "nightly")] |
| 52 | { | 52 | { |
| 53 | (waker.vtable(), waker.data()) | 53 | #[cfg(not(at_least_2024_09_06))] |
| 54 | { | ||
| 55 | let raw_waker = waker.as_raw(); | ||
| 56 | (raw_waker.vtable(), raw_waker.data()) | ||
| 57 | } | ||
| 58 | |||
| 59 | #[cfg(at_least_2024_09_06)] | ||
| 60 | { | ||
| 61 | (waker.vtable(), waker.data()) | ||
| 62 | } | ||
| 54 | } | 63 | } |
| 55 | }; | 64 | }; |
| 56 | 65 | ||
