Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

sp-api: Make the generated code act based on std in sp-api #14267

Merged
merged 3 commits into from
Jun 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions frame/executive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ std = [
"codec/std",
"frame-support/std",
"frame-system/std",
"frame-try-runtime/std",
"scale-info/std",
"sp-core/std",
"sp-io/std",
Expand Down
21 changes: 12 additions & 9 deletions primitives/api/proc-macro/src/decl_runtime_apis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -539,8 +539,6 @@ impl<'a> Fold for ToClientSideDecl<'a> {
input.supertraits.push(parse_quote!( #crate_::Core<#block_ident> ));
}

// The client side trait is only required when compiling with the feature `std` or `test`.
input.attrs.push(parse_quote!( #[cfg(any(feature = "std", test))] ));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removal of test is intentional?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it was basically done to ensure that someone may not declares the std feature for their crate. However, this was not really working as otherwise this pr would not have been required.

input.items = self.fold_item_trait_items(input.items, input.generics.params.len());

fold::fold_item_trait(self, input)
Expand Down Expand Up @@ -584,12 +582,13 @@ fn generate_runtime_info_impl(trait_: &ItemTrait, version: u64) -> TokenStream {
});

quote!(
#[cfg(any(feature = "std", test))]
impl < #( #impl_generics, )* > #crate_::RuntimeApiInfo
for dyn #trait_name < #( #ty_generics, )* >
{
#id
#version
#crate_::std_enabled! {
impl < #( #impl_generics, )* > #crate_::RuntimeApiInfo
for dyn #trait_name < #( #ty_generics, )* >
{
#id
#version
}
}
)
}
Expand Down Expand Up @@ -636,7 +635,11 @@ fn generate_client_side_decls(decls: &[ItemTrait]) -> Result<TokenStream> {

let runtime_info = api_version.map(|v| generate_runtime_info_impl(&decl, v))?;

result.push(quote!( #decl #runtime_info #( #errors )* ));
result.push(quote!(
#crate_::std_enabled! { #decl }
#runtime_info
#( #errors )*
));
}

Ok(quote!( #( #result )* ))
Expand Down
Loading