mirror of
https://github.com/embassy-rs/embassy.git
synced 2024-11-21 14:22:33 +00:00
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.
This commit is contained in:
parent
c66f83db70
commit
baeb59b5b8
@ -57,9 +57,6 @@ 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
|
||||
|
@ -96,15 +96,4 @@ 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");
|
||||
}
|
||||
}
|
||||
|
@ -124,22 +124,3 @@ impl PartialOrd<&str> for CompilerDate {
|
||||
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),
|
||||
})
|
||||
}
|
||||
|
@ -1,5 +1,4 @@
|
||||
#![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)]
|
||||
|
@ -32,40 +32,20 @@ pub(crate) unsafe fn from_task(p: TaskRef) -> Waker {
|
||||
///
|
||||
/// Panics if the waker is not created by the Embassy executor.
|
||||
pub fn task_from_waker(waker: &Waker) -> TaskRef {
|
||||
let (vtable, data) = {
|
||||
#[cfg(not(feature = "nightly"))]
|
||||
{
|
||||
struct WakerHack {
|
||||
data: *const (),
|
||||
vtable: &'static RawWakerVTable,
|
||||
}
|
||||
struct WakerHack {
|
||||
data: *const (),
|
||||
vtable: &'static RawWakerVTable,
|
||||
}
|
||||
|
||||
// safety: OK because WakerHack has the same layout as Waker.
|
||||
// This is not really guaranteed because the structs are `repr(Rust)`, it is
|
||||
// indeed the case in the current implementation.
|
||||
// TODO use waker_getters when stable. https://github.com/rust-lang/rust/issues/96992
|
||||
let hack: &WakerHack = unsafe { core::mem::transmute(waker) };
|
||||
(hack.vtable, hack.data)
|
||||
}
|
||||
// safety: OK because WakerHack has the same layout as Waker.
|
||||
// This is not really guaranteed because the structs are `repr(Rust)`, it is
|
||||
// indeed the case in the current implementation.
|
||||
// TODO use waker_getters when stable. https://github.com/rust-lang/rust/issues/96992
|
||||
let hack: &WakerHack = unsafe { core::mem::transmute(waker) };
|
||||
|
||||
#[cfg(feature = "nightly")]
|
||||
{
|
||||
#[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())
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
if vtable != &VTABLE {
|
||||
if hack.vtable != &VTABLE {
|
||||
panic!("Found waker not created by the Embassy executor. `embassy_time::Timer` only works with the Embassy executor.")
|
||||
}
|
||||
// safety: our wakers are always created with `TaskRef::as_ptr`
|
||||
unsafe { TaskRef::from_ptr(data as *const TaskHeader) }
|
||||
unsafe { TaskRef::from_ptr(hack.data as *const TaskHeader) }
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user