2020-11-12 21:26:48 +00:00
|
|
|
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);
|
2022-02-13 22:33:55 +00:00
|
|
|
assert!(
|
|
|
|
input.sig.ident == "main",
|
|
|
|
"`bevy_main` can only be used on a function called 'main'.",
|
|
|
|
);
|
2020-11-12 21:26:48 +00:00
|
|
|
|
|
|
|
TokenStream::from(quote! {
|
2022-06-30 19:42:45 +00:00
|
|
|
// use ndk-glue macro to create an activity: https://github.com/rust-windowing/android-ndk-rs/tree/master/ndk-macro
|
2020-11-12 21:26:48 +00:00
|
|
|
#[cfg(target_os = "android")]
|
2022-06-30 19:42:45 +00:00
|
|
|
#[cfg_attr(target_os = "android", bevy::ndk_glue::main(backtrace = "on", ndk_glue = "bevy::ndk_glue"))]
|
|
|
|
fn android_main() {
|
|
|
|
main()
|
2020-11-12 21:26:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
#[cfg(target_os = "ios")]
|
|
|
|
extern "C" fn main_rs() {
|
|
|
|
main();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[allow(unused)]
|
|
|
|
#input
|
|
|
|
})
|
|
|
|
}
|