diff options
| author | Dario Nieuwenhuis <[email protected]> | 2024-11-12 16:28:26 +0100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2024-11-12 16:28:26 +0100 |
| commit | baeb59b5b8d63ef9bb6ecada518ea8b911d2dc30 (patch) | |
| tree | a27e2f99887c06f0c2279d385acbdebbe704a5c8 /embassy-executor | |
| parent | c66f83db702e95e010b944cdf1b0f4a9dfe771df (diff) | |
executor: use WakerHack unconditionally even if `nightly` feature is enabled. (#3528)
This ensures the executor compiles with all recent nightly versions,
including the stable-but-with-nightly-features-enabled xtensa rustc.
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 | 19 | ||||
| -rw-r--r-- | embassy-executor/src/lib.rs | 1 | ||||
| -rw-r--r-- | embassy-executor/src/raw/waker.rs | 42 |
5 files changed, 11 insertions, 65 deletions
diff --git a/embassy-executor/Cargo.toml b/embassy-executor/Cargo.toml index 2450ae61b..7141fe0f9 100644 --- a/embassy-executor/Cargo.toml +++ b/embassy-executor/Cargo.toml | |||
| @@ -57,9 +57,6 @@ 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 | |||
| 63 | [features] | 60 | [features] |
| 64 | 61 | ||
| 65 | ## Enable nightly-only features | 62 | ## Enable nightly-only features |
diff --git a/embassy-executor/build.rs b/embassy-executor/build.rs index c4c86e1e2..8a41d7503 100644 --- a/embassy-executor/build.rs +++ b/embassy-executor/build.rs | |||
| @@ -96,15 +96,4 @@ 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 | } | ||
| 110 | } | 99 | } |
diff --git a/embassy-executor/build_common.rs b/embassy-executor/build_common.rs index af6bb0618..b15a8369f 100644 --- a/embassy-executor/build_common.rs +++ b/embassy-executor/build_common.rs | |||
| @@ -124,22 +124,3 @@ impl PartialOrd<&str> for CompilerDate { | |||
| 124 | Self::parse(other).map(|other| self.cmp(&other)) | 124 | Self::parse(other).map(|other| self.cmp(&other)) |
| 125 | } | 125 | } |
| 126 | } | 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 8e07a8b18..d816539ac 100644 --- a/embassy-executor/src/lib.rs +++ b/embassy-executor/src/lib.rs | |||
| @@ -1,5 +1,4 @@ | |||
| 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))] | ||
| 3 | #![allow(clippy::new_without_default)] | 2 | #![allow(clippy::new_without_default)] |
| 4 | #![doc = include_str!("../README.md")] | 3 | #![doc = include_str!("../README.md")] |
| 5 | #![warn(missing_docs)] | 4 | #![warn(missing_docs)] |
diff --git a/embassy-executor/src/raw/waker.rs b/embassy-executor/src/raw/waker.rs index 30b8cdd4c..d2256adfa 100644 --- a/embassy-executor/src/raw/waker.rs +++ b/embassy-executor/src/raw/waker.rs | |||
| @@ -32,40 +32,20 @@ pub(crate) unsafe fn from_task(p: TaskRef) -> Waker { | |||
| 32 | /// | 32 | /// |
| 33 | /// Panics if the waker is not created by the Embassy executor. | 33 | /// Panics if the waker is not created by the Embassy executor. |
| 34 | pub fn task_from_waker(waker: &Waker) -> TaskRef { | 34 | pub fn task_from_waker(waker: &Waker) -> TaskRef { |
| 35 | let (vtable, data) = { | 35 | struct WakerHack { |
| 36 | #[cfg(not(feature = "nightly"))] | 36 | data: *const (), |
| 37 | { | 37 | vtable: &'static RawWakerVTable, |
| 38 | struct WakerHack { | 38 | } |
| 39 | data: *const (), | ||
| 40 | vtable: &'static RawWakerVTable, | ||
| 41 | } | ||
| 42 | |||
| 43 | // safety: OK because WakerHack has the same layout as Waker. | ||
| 44 | // This is not really guaranteed because the structs are `repr(Rust)`, it is | ||
| 45 | // indeed the case in the current implementation. | ||
| 46 | // TODO use waker_getters when stable. https://github.com/rust-lang/rust/issues/96992 | ||
| 47 | let hack: &WakerHack = unsafe { core::mem::transmute(waker) }; | ||
| 48 | (hack.vtable, hack.data) | ||
| 49 | } | ||
| 50 | |||
| 51 | #[cfg(feature = "nightly")] | ||
| 52 | { | ||
| 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 | 39 | ||
| 59 | #[cfg(at_least_2024_09_06)] | 40 | // safety: OK because WakerHack has the same layout as Waker. |
| 60 | { | 41 | // This is not really guaranteed because the structs are `repr(Rust)`, it is |
| 61 | (waker.vtable(), waker.data()) | 42 | // indeed the case in the current implementation. |
| 62 | } | 43 | // TODO use waker_getters when stable. https://github.com/rust-lang/rust/issues/96992 |
| 63 | } | 44 | let hack: &WakerHack = unsafe { core::mem::transmute(waker) }; |
| 64 | }; | ||
| 65 | 45 | ||
| 66 | if vtable != &VTABLE { | 46 | if hack.vtable != &VTABLE { |
| 67 | panic!("Found waker not created by the Embassy executor. `embassy_time::Timer` only works with the Embassy executor.") | 47 | panic!("Found waker not created by the Embassy executor. `embassy_time::Timer` only works with the Embassy executor.") |
| 68 | } | 48 | } |
| 69 | // safety: our wakers are always created with `TaskRef::as_ptr` | 49 | // safety: our wakers are always created with `TaskRef::as_ptr` |
| 70 | unsafe { TaskRef::from_ptr(data as *const TaskHeader) } | 50 | unsafe { TaskRef::from_ptr(hack.data as *const TaskHeader) } |
| 71 | } | 51 | } |
