ori_macro/
entry.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#[allow(unused_imports)]
use quote::{quote, ToTokens};

use crate::find_shell;

pub fn main(
    _args: proc_macro::TokenStream,
    input: proc_macro::TokenStream,
) -> manyhow::Result<proc_macro::TokenStream> {
    let input = syn::parse::<syn::ItemFn>(input)?;

    let output = match input.sig.output {
        syn::ReturnType::Default => quote! { () },
        syn::ReturnType::Type(_, ref ty) => quote! { #ty },
    };

    let name = &input.sig.ident;
    let shell = find_shell();

    let expanded = quote! {
        #[no_mangle]
        #[cfg(target_os = "android")]
        fn android_main(android_app: #shell::platform::android::AndroidApp) -> #output {
            #shell::platform::android::ANDROID_APP.set(android_app).expect("Android app not set");

            self::#name()
        }

        #input
    };

    Ok(expanded.into())
}