From c6989dfbca51787146f50270c671af9db434f577 Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Wed, 29 Nov 2023 17:23:48 +0100 Subject: Remove nightly and unstable-traits features in preparation for 1.75. --- embassy-time/Cargo.toml | 17 +++----- embassy-time/build.rs | 19 ++++++++- embassy-time/src/delay.rs | 100 +++++++++++++++++++--------------------------- embassy-time/src/lib.rs | 5 ++- 4 files changed, 67 insertions(+), 74 deletions(-) (limited to 'embassy-time') diff --git a/embassy-time/Cargo.toml b/embassy-time/Cargo.toml index 570e0efa7..5cbb44b33 100644 --- a/embassy-time/Cargo.toml +++ b/embassy-time/Cargo.toml @@ -22,23 +22,16 @@ links = "embassy-time" [package.metadata.embassy_docs] src_base = "https://github.com/embassy-rs/embassy/blob/embassy-time-v$VERSION/embassy-time/src/" src_base_git = "https://github.com/embassy-rs/embassy/blob/$COMMIT/embassy-time/src/" -features = ["nightly", "defmt", "unstable-traits", "std"] +features = ["defmt", "std"] target = "x86_64-unknown-linux-gnu" [package.metadata.docs.rs] -features = ["nightly", "defmt", "unstable-traits", "std"] +features = ["defmt", "std"] [features] std = ["tick-hz-1_000_000", "critical-section/std"] wasm = ["dep:wasm-bindgen", "dep:js-sys", "dep:wasm-timer", "tick-hz-1_000_000"] -# Enable nightly-only features -nightly = ["embedded-hal-async"] - -# Implement embedded-hal 1.0 alpha and embedded-hal-async traits. -# Implement embedded-hal-async traits if `nightly` is set as well. -unstable-traits = ["embedded-hal-1"] - # Display a timestamp of the number of seconds since startup next to defmt log messages # To use this you must have a time driver provided. defmt-timestamp-uptime = ["defmt"] @@ -242,8 +235,8 @@ defmt = { version = "0.3", optional = true } log = { version = "0.4.14", optional = true } embedded-hal-02 = { package = "embedded-hal", version = "0.2.6" } -embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.2", optional = true} -embedded-hal-async = { version = "=1.0.0-rc.2", optional = true} +embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.2" } +embedded-hal-async = { version = "=1.0.0-rc.2" } futures-util = { version = "0.3.17", default-features = false } critical-section = "1.1" @@ -258,4 +251,4 @@ wasm-timer = { version = "0.2.5", optional = true } [dev-dependencies] serial_test = "0.9" critical-section = { version = "1.1", features = ["std"] } -embassy-executor = { version = "0.3.3", path = "../embassy-executor", features = ["nightly"] } +embassy-executor = { version = "0.3.3", path = "../embassy-executor" } diff --git a/embassy-time/build.rs b/embassy-time/build.rs index 5b0095661..78bd27ec7 100644 --- a/embassy-time/build.rs +++ b/embassy-time/build.rs @@ -1,3 +1,18 @@ -// empty, needed to be able to use `links` in Cargo.toml. +use std::env; +use std::ffi::OsString; +use std::process::Command; -fn main() {} +fn main() { + println!("cargo:rerun-if-changed=build.rs"); + + let rustc = env::var_os("RUSTC").unwrap_or_else(|| OsString::from("rustc")); + + let output = Command::new(rustc) + .arg("--version") + .output() + .expect("failed to run `rustc --version`"); + + if String::from_utf8_lossy(&output.stdout).contains("nightly") { + println!("cargo:rustc-cfg=nightly"); + } +} diff --git a/embassy-time/src/delay.rs b/embassy-time/src/delay.rs index aab56b1f1..7ef5961f0 100644 --- a/embassy-time/src/delay.rs +++ b/embassy-time/src/delay.rs @@ -1,4 +1,5 @@ use super::{Duration, Instant}; +use crate::Timer; /// Blocks for at least `duration`. pub fn block_for(duration: Duration) { @@ -14,83 +15,66 @@ pub fn block_for(duration: Duration) { /// active driver. pub struct Delay; -#[cfg(feature = "unstable-traits")] -mod eh1 { - use super::*; - - impl embedded_hal_1::delay::DelayNs for Delay { - fn delay_ns(&mut self, ns: u32) { - block_for(Duration::from_nanos(ns as u64)) - } +impl embedded_hal_1::delay::DelayNs for Delay { + fn delay_ns(&mut self, ns: u32) { + block_for(Duration::from_nanos(ns as u64)) + } - fn delay_us(&mut self, us: u32) { - block_for(Duration::from_micros(us as u64)) - } + fn delay_us(&mut self, us: u32) { + block_for(Duration::from_micros(us as u64)) + } - fn delay_ms(&mut self, ms: u32) { - block_for(Duration::from_millis(ms as u64)) - } + fn delay_ms(&mut self, ms: u32) { + block_for(Duration::from_millis(ms as u64)) } } -#[cfg(all(feature = "unstable-traits", feature = "nightly"))] -mod eha { - use super::*; - use crate::Timer; - - impl embedded_hal_async::delay::DelayNs for Delay { - async fn delay_ns(&mut self, ns: u32) { - Timer::after_nanos(ns as _).await - } +impl embedded_hal_async::delay::DelayNs for Delay { + async fn delay_ns(&mut self, ns: u32) { + Timer::after_nanos(ns as _).await + } - async fn delay_us(&mut self, us: u32) { - Timer::after_micros(us as _).await - } + async fn delay_us(&mut self, us: u32) { + Timer::after_micros(us as _).await + } - async fn delay_ms(&mut self, ms: u32) { - Timer::after_millis(ms as _).await - } + async fn delay_ms(&mut self, ms: u32) { + Timer::after_millis(ms as _).await } } -mod eh02 { - use embedded_hal_02::blocking::delay::{DelayMs, DelayUs}; - - use super::*; - - impl DelayMs for Delay { - fn delay_ms(&mut self, ms: u8) { - block_for(Duration::from_millis(ms as u64)) - } +impl embedded_hal_02::blocking::delay::DelayMs for Delay { + fn delay_ms(&mut self, ms: u8) { + block_for(Duration::from_millis(ms as u64)) } +} - impl DelayMs for Delay { - fn delay_ms(&mut self, ms: u16) { - block_for(Duration::from_millis(ms as u64)) - } +impl embedded_hal_02::blocking::delay::DelayMs for Delay { + fn delay_ms(&mut self, ms: u16) { + block_for(Duration::from_millis(ms as u64)) } +} - impl DelayMs for Delay { - fn delay_ms(&mut self, ms: u32) { - block_for(Duration::from_millis(ms as u64)) - } +impl embedded_hal_02::blocking::delay::DelayMs for Delay { + fn delay_ms(&mut self, ms: u32) { + block_for(Duration::from_millis(ms as u64)) } +} - impl DelayUs for Delay { - fn delay_us(&mut self, us: u8) { - block_for(Duration::from_micros(us as u64)) - } +impl embedded_hal_02::blocking::delay::DelayUs for Delay { + fn delay_us(&mut self, us: u8) { + block_for(Duration::from_micros(us as u64)) } +} - impl DelayUs for Delay { - fn delay_us(&mut self, us: u16) { - block_for(Duration::from_micros(us as u64)) - } +impl embedded_hal_02::blocking::delay::DelayUs for Delay { + fn delay_us(&mut self, us: u16) { + block_for(Duration::from_micros(us as u64)) } +} - impl DelayUs for Delay { - fn delay_us(&mut self, us: u32) { - block_for(Duration::from_micros(us as u64)) - } +impl embedded_hal_02::blocking::delay::DelayUs for Delay { + fn delay_us(&mut self, us: u32) { + block_for(Duration::from_micros(us as u64)) } } diff --git a/embassy-time/src/lib.rs b/embassy-time/src/lib.rs index a0f6e3824..82a7ee0df 100644 --- a/embassy-time/src/lib.rs +++ b/embassy-time/src/lib.rs @@ -1,6 +1,7 @@ #![cfg_attr(not(any(feature = "std", feature = "wasm", test)), no_std)] -#![cfg_attr(feature = "nightly", feature(async_fn_in_trait))] -#![cfg_attr(feature = "nightly", allow(stable_features, unknown_lints, async_fn_in_trait))] +#![cfg_attr(nightly, feature(async_fn_in_trait, impl_trait_projections))] +#![cfg_attr(nightly, allow(stable_features, unknown_lints))] +#![allow(async_fn_in_trait)] #![doc = include_str!("../README.md")] #![allow(clippy::new_without_default)] #![warn(missing_docs)] -- cgit