Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 30 additions & 11 deletions esp-hal-procmacros/src/rtos_main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use proc_macro::TokenStream;
use proc_macro2::TokenStream as TokenStream2;
use quote::{ToTokens, quote};
use syn::{
Attribute,
Meta,
ReturnType,
Token,
Expand Down Expand Up @@ -75,24 +76,42 @@ pub fn run(
ctxt.error_spanned_by(&f.sig, "main function must have 1 argument: the spawner.");
}

let fattrs = f.attrs;
let lint_attrs: Vec<Attribute> = fattrs
.clone()
.into_iter()
.filter(|item| {
item.path().is_ident("deny")
|| item.path().is_ident("allow")
|| item.path().is_ident("warn")
})
.collect();

ctxt.check()?;

let f_body = f.block;
let out = &f.sig.output;

let result = quote! {
#[doc(hidden)]
#[::embassy_executor::task()]
async fn __embassy_main(#fargs) #out {
#f_body
#(#lint_attrs)*
pub(crate) mod __main {
Copy link
Contributor

@bugadani bugadani Oct 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This module means the main function no longer shows up in rustdoc, right? Why is it necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we'd need to PR a change in https://github.com/embassy-rs/embassy/blob/main/embassy-executor-macros/src/macros/task.rs for that to work

I have never seen the main function showing up in docs 🤔 it's all doc-hidden AFAICS - so this looked like an straight forward solution without obvious drawbacks

use super::*;

#[doc(hidden)]
#(#fattrs)*
#[::embassy_executor::task()]
async fn __embassy_main(#fargs) #out {
#f_body
}

#[doc(hidden)]
unsafe fn __make_static<T>(t: &mut T) -> &'static mut T {
::core::mem::transmute(t)
}

#(#fattrs)*
#main
}

#[doc(hidden)]
unsafe fn __make_static<T>(t: &mut T) -> &'static mut T {
::core::mem::transmute(t)
}

#main
};

Ok(result)
Expand Down
Loading