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.
This commit is contained in:
parent
ef9e373ec4
commit
bd0aaec624
4 changed files with 26 additions and 83 deletions
|
@ -3,28 +3,16 @@ use proc_macro2::TokenStream;
|
||||||
use quote::quote;
|
use quote::quote;
|
||||||
|
|
||||||
use crate::util::ctxt::Ctxt;
|
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)]
|
#[derive(Debug, FromMeta)]
|
||||||
struct Args {
|
struct Args {
|
||||||
#[darling(default)]
|
|
||||||
embassy_prefix: ModulePrefix,
|
|
||||||
|
|
||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
#[darling(default)]
|
#[darling(default)]
|
||||||
config: Option<syn::LitStr>,
|
config: Option<syn::LitStr>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn run(args: syn::AttributeArgs, f: syn::ItemFn) -> Result<TokenStream, TokenStream> {
|
pub fn run(args: syn::AttributeArgs, f: syn::ItemFn) -> Result<TokenStream, TokenStream> {
|
||||||
|
#[allow(unused_variables)]
|
||||||
let args = Args::from_list(&args).map_err(|e| e.write_errors())?;
|
let args = Args::from_list(&args).map_err(|e| e.write_errors())?;
|
||||||
|
|
||||||
let fargs = f.sig.inputs.clone();
|
let fargs = f.sig.inputs.clone();
|
||||||
|
@ -38,26 +26,32 @@ pub fn run(args: syn::AttributeArgs, f: syn::ItemFn) -> Result<TokenStream, Toke
|
||||||
ctxt.error_spanned_by(&f.sig, "task functions must not be generic");
|
ctxt.error_spanned_by(&f.sig, "task functions must not be generic");
|
||||||
}
|
}
|
||||||
|
|
||||||
if HAL.is_some() && fargs.len() != 2 {
|
#[cfg(feature = "stm32")]
|
||||||
|
let hal = Some(quote!(::embassy_stm32));
|
||||||
|
#[cfg(feature = "nrf")]
|
||||||
|
let hal = Some(quote!(::embassy_nrf));
|
||||||
|
#[cfg(feature = "rp")]
|
||||||
|
let hal = Some(quote!(::embassy_rp));
|
||||||
|
#[cfg(not(any(feature = "stm32", feature = "nrf", feature = "rp")))]
|
||||||
|
let hal: Option<TokenStream> = None;
|
||||||
|
|
||||||
|
if hal.is_some() && fargs.len() != 2 {
|
||||||
ctxt.error_spanned_by(&f.sig, "main function must have 2 arguments");
|
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.error_spanned_by(&f.sig, "main function must have 1 argument");
|
||||||
}
|
}
|
||||||
|
|
||||||
ctxt.check()?;
|
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;
|
let f_body = f.block;
|
||||||
|
|
||||||
#[cfg(feature = "wasm")]
|
#[cfg(feature = "wasm")]
|
||||||
let main = quote! {
|
let main = quote! {
|
||||||
#[wasm_bindgen::prelude::wasm_bindgen(start)]
|
#[wasm_bindgen::prelude::wasm_bindgen(start)]
|
||||||
pub fn main() -> Result<(), wasm_bindgen::JsValue> {
|
pub fn main() -> Result<(), wasm_bindgen::JsValue> {
|
||||||
static EXECUTOR: ::embassy_util::Forever<#embassy_path::executor::Executor> = ::embassy_util::Forever::new();
|
static EXECUTOR: ::embassy_util::Forever<::embassy_executor::executor::Executor> = ::embassy_util::Forever::new();
|
||||||
let executor = EXECUTOR.put(#embassy_path::executor::Executor::new());
|
let executor = EXECUTOR.put(::embassy_executor::executor::Executor::new());
|
||||||
|
|
||||||
executor.start(|spawner| {
|
executor.start(|spawner| {
|
||||||
spawner.spawn(__embassy_main(spawner)).unwrap();
|
spawner.spawn(__embassy_main(spawner)).unwrap();
|
||||||
|
@ -70,7 +64,7 @@ pub fn run(args: syn::AttributeArgs, f: syn::ItemFn) -> Result<TokenStream, Toke
|
||||||
#[cfg(all(feature = "std", not(feature = "wasm")))]
|
#[cfg(all(feature = "std", not(feature = "wasm")))]
|
||||||
let main = quote! {
|
let main = quote! {
|
||||||
fn main() -> ! {
|
fn main() -> ! {
|
||||||
let mut executor = #embassy_path::executor::Executor::new();
|
let mut executor = ::embassy_executor::executor::Executor::new();
|
||||||
let executor = unsafe { __make_static(&mut executor) };
|
let executor = unsafe { __make_static(&mut executor) };
|
||||||
|
|
||||||
executor.run(|spawner| {
|
executor.run(|spawner| {
|
||||||
|
@ -87,16 +81,13 @@ pub fn run(args: syn::AttributeArgs, f: syn::ItemFn) -> Result<TokenStream, Toke
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
let (hal_setup, peris_arg) = match HAL {
|
let (hal_setup, peris_arg) = match hal {
|
||||||
Some(hal) => {
|
Some(hal) => (
|
||||||
let embassy_hal_path = embassy_prefix.append(hal).path();
|
quote!(
|
||||||
(
|
let p = #hal::init(#config);
|
||||||
quote!(
|
),
|
||||||
let p = #embassy_hal_path::init(#config);
|
quote!(p),
|
||||||
),
|
),
|
||||||
quote!(p),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
None => (quote!(), quote!()),
|
None => (quote!(), quote!()),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -105,7 +96,7 @@ pub fn run(args: syn::AttributeArgs, f: syn::ItemFn) -> Result<TokenStream, Toke
|
||||||
fn main() -> ! {
|
fn main() -> ! {
|
||||||
#hal_setup
|
#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) };
|
let executor = unsafe { __make_static(&mut executor) };
|
||||||
|
|
||||||
executor.run(|spawner| {
|
executor.run(|spawner| {
|
||||||
|
@ -116,7 +107,7 @@ pub fn run(args: syn::AttributeArgs, f: syn::ItemFn) -> Result<TokenStream, Toke
|
||||||
};
|
};
|
||||||
|
|
||||||
let result = quote! {
|
let result = quote! {
|
||||||
#[#embassy_path::task(embassy_prefix = #embassy_prefix_lit)]
|
#[::embassy_executor::task()]
|
||||||
async fn __embassy_main(#fargs) {
|
async fn __embassy_main(#fargs) {
|
||||||
#f_body
|
#f_body
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,22 +3,16 @@ use proc_macro2::TokenStream;
|
||||||
use quote::{format_ident, quote};
|
use quote::{format_ident, quote};
|
||||||
|
|
||||||
use crate::util::ctxt::Ctxt;
|
use crate::util::ctxt::Ctxt;
|
||||||
use crate::util::path::ModulePrefix;
|
|
||||||
|
|
||||||
#[derive(Debug, FromMeta)]
|
#[derive(Debug, FromMeta)]
|
||||||
struct Args {
|
struct Args {
|
||||||
#[darling(default)]
|
#[darling(default)]
|
||||||
pool_size: Option<usize>,
|
pool_size: Option<usize>,
|
||||||
#[darling(default)]
|
|
||||||
embassy_prefix: ModulePrefix,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn run(args: syn::AttributeArgs, f: syn::ItemFn) -> Result<TokenStream, TokenStream> {
|
pub fn run(args: syn::AttributeArgs, f: syn::ItemFn) -> Result<TokenStream, TokenStream> {
|
||||||
let args = Args::from_list(&args).map_err(|e| e.write_errors())?;
|
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 pool_size: usize = args.pool_size.unwrap_or(1);
|
||||||
|
|
||||||
let ctxt = Ctxt::new();
|
let ctxt = Ctxt::new();
|
||||||
|
@ -70,9 +64,9 @@ pub fn run(args: syn::AttributeArgs, f: syn::ItemFn) -> Result<TokenStream, Toke
|
||||||
// in the user's code.
|
// in the user's code.
|
||||||
#task_inner
|
#task_inner
|
||||||
|
|
||||||
#visibility fn #task_ident(#fargs) -> #embassy_path::executor::SpawnToken<impl Sized> {
|
#visibility fn #task_ident(#fargs) -> ::embassy_executor::executor::SpawnToken<impl Sized> {
|
||||||
type Fut = impl ::core::future::Future + 'static;
|
type Fut = impl ::core::future::Future + 'static;
|
||||||
static POOL: #embassy_path::executor::raw::TaskPool<Fut, #pool_size> = #embassy_path::executor::raw::TaskPool::new();
|
static POOL: ::embassy_executor::executor::raw::TaskPool<Fut, #pool_size> = ::embassy_executor::executor::raw::TaskPool::new();
|
||||||
unsafe { POOL._spawn_async_fn(move || #task_inner_ident(#(#arg_names,)*)) }
|
unsafe { POOL._spawn_async_fn(move || #task_inner_ident(#(#arg_names,)*)) }
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,2 +1 @@
|
||||||
pub mod ctxt;
|
pub mod ctxt;
|
||||||
pub mod path;
|
|
||||||
|
|
|
@ -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<Self> {
|
|
||||||
Ok(ModulePrefix::new(value))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for ModulePrefix {
|
|
||||||
fn default() -> ModulePrefix {
|
|
||||||
ModulePrefix::new("::")
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in a new issue