sp-api: Use macro to detect if frame-metadata is enabled (#4117)

While `sp-api-proc-macro` isn't used directly and thus, it should have
the same features enabled as `sp-api`. However, I have seen issues
around `frame-metadata` not being enabled for `sp-api`, but for
`sp-api-proc-macro`. This can be prevented by using the
`frame_metadata_enabled` macro from `sp-api` that ensures we have the
same feature set between both crates.
This commit is contained in:
Bastian Köcher
2024-04-15 10:11:51 +02:00
committed by GitHub
parent 6acf4787e1
commit d1b0ef76a8
8 changed files with 22 additions and 27 deletions
@@ -164,15 +164,17 @@ pub fn generate_decl_runtime_metadata(decl: &ItemTrait) -> TokenStream2 {
let (impl_generics, _, where_clause) = generics.split_for_impl();
quote!(
#( #attrs )*
#[inline(always)]
pub fn runtime_metadata #impl_generics () -> #crate_::metadata_ir::RuntimeApiMetadataIR
#where_clause
{
#crate_::metadata_ir::RuntimeApiMetadataIR {
name: #trait_name,
methods: #crate_::vec![ #( #methods, )* ],
docs: #docs,
#crate_::frame_metadata_enabled! {
#( #attrs )*
#[inline(always)]
pub fn runtime_metadata #impl_generics () -> #crate_::metadata_ir::RuntimeApiMetadataIR
#where_clause
{
#crate_::metadata_ir::RuntimeApiMetadataIR {
name: #trait_name,
methods: #crate_::vec![ #( #methods, )* ],
docs: #docs,
}
}
}
)
@@ -255,14 +257,16 @@ pub fn generate_impl_runtime_metadata(impls: &[ItemImpl]) -> Result<TokenStream2
// `construct_runtime!` is called.
Ok(quote!(
#[doc(hidden)]
trait InternalImplRuntimeApis {
#[inline(always)]
fn runtime_metadata(&self) -> #crate_::vec::Vec<#crate_::metadata_ir::RuntimeApiMetadataIR> {
#crate_::vec![ #( #metadata, )* ]
#crate_::frame_metadata_enabled! {
#[doc(hidden)]
trait InternalImplRuntimeApis {
#[inline(always)]
fn runtime_metadata(&self) -> #crate_::vec::Vec<#crate_::metadata_ir::RuntimeApiMetadataIR> {
#crate_::vec![ #( #metadata, )* ]
}
}
#[doc(hidden)]
impl InternalImplRuntimeApis for #runtime_name {}
}
#[doc(hidden)]
impl InternalImplRuntimeApis for #runtime_name {}
))
}