use proc_macro::TokenStream; use quote::quote; use syn::{parse_macro_input, ItemFn}; extern crate proc_macro; #[proc_macro] pub fn plugin(metadata: TokenStream) -> TokenStream { emit_plugin_api().into() } #[proc_macro_attribute] pub fn plugin_init(attribute: TokenStream, item: TokenStream) -> TokenStream { let input = parse_macro_input!(item as ItemFn); let func = input.sig.ident.clone(); quote! { #[doc(hidden)] #[no_mangle] unsafe extern "C" fn __plugin_init() { #func(&mut ::giterated_plugin::local::PluginStackBuilder::new()).unwrap() } #input } .into() } fn emit_plugin_api() -> impl Into { quote! { #[doc(hidden)] #[no_mangle] unsafe extern "C" fn __load_runtime_vtable(vtable: &'static ::giterated_plugin::abi::vtable::VTable<::giterated_plugin::abi::vtable::runtime::RuntimeHandle>) { todo!() } #[doc(hidden)] #[no_mangle] unsafe extern "C" fn __get_plugin_vtable() -> &'static ::giterated_plugin::abi::vtable::VTable<::giterated_plugin::abi::vtable::plugin::Plugin> { todo!() } } }