From bd0aaec6242c86d126fdb3784ae603cbf329957b Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Wed, 17 Aug 2022 15:03:12 +0200 Subject: [PATCH] macros: remove embassy_prefix attr. This was used in the past for reexporting the macros from drogue-device, which is no longer using it. Also, it is a pain to support, so we don't want it. --- embassy-macros/src/macros/main.rs | 57 +++++++++++++------------------ embassy-macros/src/macros/task.rs | 10 ++---- embassy-macros/src/util/mod.rs | 1 - embassy-macros/src/util/path.rs | 41 ---------------------- 4 files changed, 26 insertions(+), 83 deletions(-) delete mode 100644 embassy-macros/src/util/path.rs diff --git a/embassy-macros/src/macros/main.rs b/embassy-macros/src/macros/main.rs index a8c8bb0d..b040edc5 100644 --- a/embassy-macros/src/macros/main.rs +++ b/embassy-macros/src/macros/main.rs @@ -3,28 +3,16 @@ use proc_macro2::TokenStream; use quote::quote; use crate::util::ctxt::Ctxt; -use crate::util::path::ModulePrefix; - -#[cfg(feature = "stm32")] -const HAL: Option<&str> = Some("embassy_stm32"); -#[cfg(feature = "nrf")] -const HAL: Option<&str> = Some("embassy_nrf"); -#[cfg(feature = "rp")] -const HAL: Option<&str> = Some("embassy_rp"); -#[cfg(not(any(feature = "stm32", feature = "nrf", feature = "rp")))] -const HAL: Option<&str> = None; #[derive(Debug, FromMeta)] struct Args { - #[darling(default)] - embassy_prefix: ModulePrefix, - #[allow(unused)] #[darling(default)] config: Option, } pub fn run(args: syn::AttributeArgs, f: syn::ItemFn) -> Result { + #[allow(unused_variables)] let args = Args::from_list(&args).map_err(|e| e.write_errors())?; let fargs = f.sig.inputs.clone(); @@ -38,26 +26,32 @@ pub fn run(args: syn::AttributeArgs, f: syn::ItemFn) -> Result = None; + + if hal.is_some() && fargs.len() != 2 { ctxt.error_spanned_by(&f.sig, "main function must have 2 arguments"); } - if HAL.is_none() && fargs.len() != 1 { + if hal.is_none() && fargs.len() != 1 { ctxt.error_spanned_by(&f.sig, "main function must have 1 argument"); } ctxt.check()?; - let embassy_prefix = args.embassy_prefix; - let embassy_prefix_lit = embassy_prefix.literal(); - let embassy_path = embassy_prefix.append("embassy_executor").path(); let f_body = f.block; #[cfg(feature = "wasm")] let main = quote! { #[wasm_bindgen::prelude::wasm_bindgen(start)] pub fn main() -> Result<(), wasm_bindgen::JsValue> { - static EXECUTOR: ::embassy_util::Forever<#embassy_path::executor::Executor> = ::embassy_util::Forever::new(); - let executor = EXECUTOR.put(#embassy_path::executor::Executor::new()); + static EXECUTOR: ::embassy_util::Forever<::embassy_executor::executor::Executor> = ::embassy_util::Forever::new(); + let executor = EXECUTOR.put(::embassy_executor::executor::Executor::new()); executor.start(|spawner| { spawner.spawn(__embassy_main(spawner)).unwrap(); @@ -70,7 +64,7 @@ pub fn run(args: syn::AttributeArgs, f: syn::ItemFn) -> Result ! { - let mut executor = #embassy_path::executor::Executor::new(); + let mut executor = ::embassy_executor::executor::Executor::new(); let executor = unsafe { __make_static(&mut executor) }; executor.run(|spawner| { @@ -87,16 +81,13 @@ pub fn run(args: syn::AttributeArgs, f: syn::ItemFn) -> Result { - let embassy_hal_path = embassy_prefix.append(hal).path(); - ( - quote!( - let p = #embassy_hal_path::init(#config); - ), - quote!(p), - ) - } + let (hal_setup, peris_arg) = match hal { + Some(hal) => ( + quote!( + let p = #hal::init(#config); + ), + quote!(p), + ), None => (quote!(), quote!()), }; @@ -105,7 +96,7 @@ pub fn run(args: syn::AttributeArgs, f: syn::ItemFn) -> Result ! { #hal_setup - let mut executor = #embassy_path::executor::Executor::new(); + let mut executor = ::embassy_executor::executor::Executor::new(); let executor = unsafe { __make_static(&mut executor) }; executor.run(|spawner| { @@ -116,7 +107,7 @@ pub fn run(args: syn::AttributeArgs, f: syn::ItemFn) -> Result, - #[darling(default)] - embassy_prefix: ModulePrefix, } pub fn run(args: syn::AttributeArgs, f: syn::ItemFn) -> Result { let args = Args::from_list(&args).map_err(|e| e.write_errors())?; - let embassy_prefix = args.embassy_prefix.append("embassy_executor"); - let embassy_path = embassy_prefix.path(); - let pool_size: usize = args.pool_size.unwrap_or(1); let ctxt = Ctxt::new(); @@ -70,9 +64,9 @@ pub fn run(args: syn::AttributeArgs, f: syn::ItemFn) -> Result #embassy_path::executor::SpawnToken { + #visibility fn #task_ident(#fargs) -> ::embassy_executor::executor::SpawnToken { type Fut = impl ::core::future::Future + 'static; - static POOL: #embassy_path::executor::raw::TaskPool = #embassy_path::executor::raw::TaskPool::new(); + static POOL: ::embassy_executor::executor::raw::TaskPool = ::embassy_executor::executor::raw::TaskPool::new(); unsafe { POOL._spawn_async_fn(move || #task_inner_ident(#(#arg_names,)*)) } } }; diff --git a/embassy-macros/src/util/mod.rs b/embassy-macros/src/util/mod.rs index c2f2dfd6..28702809 100644 --- a/embassy-macros/src/util/mod.rs +++ b/embassy-macros/src/util/mod.rs @@ -1,2 +1 @@ pub mod ctxt; -pub mod path; diff --git a/embassy-macros/src/util/path.rs b/embassy-macros/src/util/path.rs deleted file mode 100644 index 00fca7bd..00000000 --- a/embassy-macros/src/util/path.rs +++ /dev/null @@ -1,41 +0,0 @@ -use darling::{FromMeta, Result}; -use proc_macro2::Span; -use syn::{LitStr, Path}; - -#[derive(Debug)] -pub struct ModulePrefix { - literal: LitStr, -} - -impl ModulePrefix { - pub fn new(path: &str) -> Self { - let literal = LitStr::new(path, Span::call_site()); - Self { literal } - } - - pub fn append(&self, component: &str) -> ModulePrefix { - let mut lit = self.literal().value(); - lit.push_str(component); - Self::new(lit.as_str()) - } - - pub fn path(&self) -> Path { - self.literal.parse().unwrap() - } - - pub fn literal(&self) -> &LitStr { - &self.literal - } -} - -impl FromMeta for ModulePrefix { - fn from_string(value: &str) -> Result { - Ok(ModulePrefix::new(value)) - } -} - -impl Default for ModulePrefix { - fn default() -> ModulePrefix { - ModulePrefix::new("::") - } -}