bevy/crates/bevy_derive/src/bevy_main.rs
danieleades d8974e7c3d small and mostly pointless refactoring (#2934)
What is says on the tin.

This has got more to do with making `clippy` slightly more *quiet* than it does with changing anything that might greatly impact readability or performance.

that said, deriving `Default` for a couple of structs is a nice easy win
2022-02-13 22:33:55 +00:00

38 lines
986 B
Rust

use proc_macro::TokenStream;
use quote::quote;
use syn::{parse_macro_input, ItemFn};
pub fn bevy_main(_attr: TokenStream, item: TokenStream) -> TokenStream {
let input = parse_macro_input!(item as ItemFn);
assert!(
input.sig.ident == "main",
"`bevy_main` can only be used on a function called 'main'.",
);
TokenStream::from(quote! {
#[no_mangle]
#[cfg(target_os = "android")]
unsafe extern "C" fn ANativeActivity_onCreate(
activity: *mut std::os::raw::c_void,
saved_state: *mut std::os::raw::c_void,
saved_state_size: usize,
) {
bevy::ndk_glue::init(
activity as _,
saved_state as _,
saved_state_size as _,
main,
);
}
#[no_mangle]
#[cfg(target_os = "ios")]
extern "C" fn main_rs() {
main();
}
#[allow(unused)]
#input
})
}