Emit wasm sections only when compiling to wasm (#8845)

This commit is contained in:
Sergei Shulepov
2021-05-18 14:06:35 +02:00
committed by GitHub
parent 2b8be8cf1e
commit bee5c2dd71
3 changed files with 16 additions and 0 deletions
@@ -675,6 +675,7 @@ fn generate_runtime_api_versions(impls: &[ItemImpl]) -> Result<TokenStream> {
#( #attrs )*
const _: () = {
// All sections with the same name are going to be merged by concatenation.
#[cfg(not(feature = "std"))]
#[link_section = "runtime_apis"]
static SECTION_CONTENTS: [u8; 12] = #c::serialize_runtime_api_info(#id, #version);
};
@@ -238,6 +238,7 @@ fn generate_emit_link_section_decl(contents: &[u8], section_name: &str) -> Token
let len = contents.len();
quote! {
const _: () = {
#[cfg(not(feature = "std"))]
#[link_section = #section_name]
static SECTION_CONTENTS: [u8; #len] = [#(#contents),*];
};
+14
View File
@@ -45,6 +45,8 @@ use sp_runtime::{traits::Block as BlockT, generic::BlockId};
/// A shortcoming of this macro is that it is unable to embed information regarding supported APIs.
/// This is supported by the `construct_runtime!` macro.
///
/// # Usage
///
/// This macro accepts a const item like the following:
///
/// ```rust
@@ -78,6 +80,18 @@ use sp_runtime::{traits::Block as BlockT, generic::BlockId};
/// - `apis` doesn't have any specific constraints. This is because this information doesn't get into
/// the custom section and is not parsed.
///
/// # Compilation Target & "std" feature
///
/// This macro assumes it will be used within a runtime. By convention, a runtime crate defines a
/// feature named "std". This feature is enabled when the runtime is compiled to native code and
/// disabled when it is compiled to the wasm code.
///
/// The custom section can only be emitted while compiling to wasm. In order to detect the compilation
/// target we use the "std" feature. This macro will emit the custom section only if the "std" feature
/// is **not** enabled.
///
/// Including this macro in the context where there is no "std" feature and the code is not compiled
/// to wasm can lead to cryptic linking errors.
pub use sp_version_proc_macro::runtime_version;
/// The identity of a particular API interface that the runtime might provide.