mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-25 18:33:24 +00:00
Rename aster_main as ostd::main
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
59350a8578
commit
fe7251c413
35
ostd/libs/ostd-macros/src/lib.rs
Normal file
35
ostd/libs/ostd-macros/src/lib.rs
Normal file
@ -0,0 +1,35 @@
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
use proc_macro::TokenStream;
|
||||
use quote::quote;
|
||||
use syn::{parse_macro_input, ItemFn};
|
||||
|
||||
/// This macro is used to mark the kernel entry point.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```norun
|
||||
/// use ostd::prelude::*;
|
||||
///
|
||||
/// #[ostd::main]
|
||||
/// pub fn main() {
|
||||
/// println!("hello world");
|
||||
/// }
|
||||
/// ```
|
||||
#[proc_macro_attribute]
|
||||
pub fn main(_attr: TokenStream, item: TokenStream) -> TokenStream {
|
||||
let main_fn = parse_macro_input!(item as ItemFn);
|
||||
let main_fn_name = &main_fn.sig.ident;
|
||||
|
||||
quote!(
|
||||
#[no_mangle]
|
||||
pub fn __ostd_main() -> ! {
|
||||
ostd::init();
|
||||
#main_fn_name();
|
||||
ostd::prelude::abort();
|
||||
}
|
||||
|
||||
#main_fn
|
||||
)
|
||||
.into()
|
||||
}
|
Reference in New Issue
Block a user