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!("runtime vtable insertion is not implemented") } #[doc(hidden)] #[no_mangle] unsafe extern "C" fn __get_plugin_vtable() -> &'static ::giterated_plugin::abi::vtable::VTable<::giterated_plugin::abi::vtable::plugin::Plugin> { unsafe extern "C" fn plugin_name() -> ::giterated_plugin::abi::FfiSliceRef { ::giterated_plugin::abi::FfiSliceRef::static_ref("plugin name") } unsafe extern "C" fn plugin_version() -> ::giterated_plugin::abi::FfiSliceRef { ::giterated_plugin::abi::FfiSliceRef::static_ref("0.0.1") } unsafe extern "C" fn type_metadata() -> ::giterated_plugin::abi::value_ex::FfiValueRefUntyped { todo!() } static PLUGIN_VTABLE: ::giterated_plugin::abi::vtable::plugin::PluginVTable = ::giterated_plugin::abi::vtable::plugin::PluginVTable { plugin_name, plugin_version, type_metadata }; ::giterated_plugin::abi::vtable::VTable::new(&PLUGIN_VTABLE) } } }