bevy/crates/bevy_derive/src/bevy_main.rs
Jinlei Li b6066c30b6 Fix ndk-macro link (#7027)
# Objective

[ndk-glue](https://github.com/rust-mobile/ndk-glue)  has been split from `android-ndk-rs` into a separate repository.
2022-12-25 05:06:03 +00:00

30 lines
857 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! {
// use ndk-glue macro to create an activity: https://github.com/rust-mobile/ndk-glue/tree/main/ndk-macro
#[cfg(target_os = "android")]
#[cfg_attr(target_os = "android", bevy::ndk_glue::main(backtrace = "on", ndk_glue = "bevy::ndk_glue"))]
fn android_main() {
main()
}
#[no_mangle]
#[cfg(target_os = "ios")]
extern "C" fn main_rs() {
main();
}
#[allow(unused)]
#input
})
}