From 5f04d6e6c51fd5f13c04aa122ba9811d97d8a116 Mon Sep 17 00:00:00 2001 From: Ulf Lilleengen Date: Thu, 2 Sep 2021 14:45:20 +0200 Subject: [PATCH] Fix embassy::main macros for std target --- embassy-macros/src/lib.rs | 4 +--- embassy/Cargo.toml | 2 +- examples/std/src/bin/tick.rs | 13 ++++--------- 3 files changed, 6 insertions(+), 13 deletions(-) diff --git a/embassy-macros/src/lib.rs b/embassy-macros/src/lib.rs index 54cf6fb8..ab327ace 100644 --- a/embassy-macros/src/lib.rs +++ b/embassy-macros/src/lib.rs @@ -386,7 +386,6 @@ pub fn main(args: TokenStream, item: TokenStream) -> TokenStream { }; let embassy_path = macro_args.embassy_prefix.append("embassy"); - let embassy_std_path = macro_args.embassy_prefix.append("embassy_std"); let mut fail = false; if task_fn.sig.asyncness.is_none() { @@ -427,7 +426,6 @@ pub fn main(args: TokenStream, item: TokenStream) -> TokenStream { let task_fn_body = task_fn.block.clone(); let embassy_path = embassy_path.path(); - let embassy_std_path = embassy_std_path.path(); let embassy_prefix_lit = macro_args.embassy_prefix.literal(); let result = quote! { @@ -441,7 +439,7 @@ pub fn main(args: TokenStream, item: TokenStream) -> TokenStream { ::core::mem::transmute(t) } - let mut executor = #embassy_std_path::Executor::new(); + let mut executor = #embassy_path::executor::Executor::new(); let executor = unsafe { make_static(&mut executor) }; executor.run(|spawner| { diff --git a/embassy/Cargo.toml b/embassy/Cargo.toml index 0ff71ce1..ecb53325 100644 --- a/embassy/Cargo.toml +++ b/embassy/Cargo.toml @@ -7,7 +7,7 @@ resolver = "2" [features] default = [] -std = ["futures/std", "embassy-traits/std", "time", "time-tick-1mhz"] +std = ["futures/std", "embassy-traits/std", "time", "time-tick-1mhz", "embassy-macros/std"] # Enable `embassy::time` module. # NOTE: This feature is only intended to be enabled by crates providing the time driver implementation. diff --git a/examples/std/src/bin/tick.rs b/examples/std/src/bin/tick.rs index 385b317d..7de78040 100644 --- a/examples/std/src/bin/tick.rs +++ b/examples/std/src/bin/tick.rs @@ -1,9 +1,8 @@ #![feature(type_alias_impl_trait)] #![allow(incomplete_features)] -use embassy::executor::Executor; +use embassy::executor::Spawner; use embassy::time::{Duration, Timer}; -use embassy::util::Forever; use log::*; #[embassy::task] @@ -14,16 +13,12 @@ async fn run() { } } -static EXECUTOR: Forever = Forever::new(); - -fn main() { +#[embassy::main] +async fn main(spawner: Spawner) { env_logger::builder() .filter_level(log::LevelFilter::Debug) .format_timestamp_nanos() .init(); - let executor = EXECUTOR.put(Executor::new()); - executor.run(|spawner| { - spawner.spawn(run()).unwrap(); - }); + spawner.spawn(run()).unwrap(); }