Allow for an optional user-defined entry macro when targeting RISC-V

This commit is contained in:
Jesse Braham
2023-05-16 09:34:38 -07:00
parent 56f2e0c9a0
commit 4e9ed223a9
2 changed files with 31 additions and 5 deletions

View File

@ -1,16 +1,30 @@
use darling::FromMeta;
use proc_macro2::TokenStream;
use quote::quote;
use syn::{ReturnType, Type};
use syn::{Expr, ReturnType, Type};
use crate::util::ctxt::Ctxt;
#[derive(Debug, FromMeta)]
struct Args {}
struct Args {
#[darling(default)]
entry: Option<String>,
}
pub fn riscv(args: syn::AttributeArgs) -> TokenStream {
let maybe_entry = match Args::from_list(&args) {
Ok(args) => args.entry,
Err(e) => return e.write_errors(),
};
let entry = maybe_entry.unwrap_or("riscv_rt::entry".into());
let entry = match Expr::from_string(&entry) {
Ok(expr) => expr,
Err(e) => return e.write_errors(),
};
pub fn riscv() -> TokenStream {
quote! {
#[riscv_rt::entry]
#[#entry]
fn main() -> ! {
let mut executor = ::embassy_executor::Executor::new();
let executor = unsafe { __make_static(&mut executor) };