Struct substrate_wasm_builder::WasmBuilder

source ·
pub struct WasmBuilder { /* private fields */ }
Expand description

The builder for building a wasm binary.

The builder itself is separated into multiple structs to make the setup type safe.

Building a wasm binary:

  1. Call WasmBuilder::new to create a new builder.
  2. Select the project to build using the methods of WasmBuilderSelectProject.
  3. Set additional RUST_FLAGS or a different name for the file containing the WASM code using methods of WasmBuilder.
  4. Build the WASM binary using Self::build.

Implementations§

source§

impl WasmBuilder

source

pub fn new() -> WasmBuilderSelectProject

Create a new instance of the builder.

source

pub fn build_using_defaults()

Build the WASM binary using the recommended default values.

This is the same as calling:

substrate_wasm_builder::WasmBuilder::new()
   .with_current_project()
   .import_memory()
   .export_heap_base()
   .build();
source

pub fn init_with_defaults() -> Self

Init the wasm builder with the recommended default values.

In contrast to Self::build_using_defaults it does not build the WASM binary directly.

This is the same as calling:

substrate_wasm_builder::WasmBuilder::new()
   .with_current_project()
   .import_memory()
   .export_heap_base();
source

pub fn export_heap_base(self) -> Self

Enable exporting __heap_base as global variable in the WASM binary.

This adds -Clink-arg=--export=__heap_base to RUST_FLAGS.

source

pub fn set_file_name(self, file_name: impl Into<String>) -> Self

Set the name of the file that will be generated in OUT_DIR.

This file needs to be included to get access to the build WASM binary.

If this function is not called, file_name defaults to wasm_binary.rs

source

pub fn import_memory(self) -> Self

Instruct the linker to import the memory into the WASM binary.

This adds -C link-arg=--import-memory to RUST_FLAGS.

source

pub fn append_to_rust_flags(self, flag: impl Into<String>) -> Self

Append the given flag to RUST_FLAGS.

flag is appended as is, so it needs to be a valid flag.

source

pub fn enable_feature(self, feature: impl Into<String>) -> Self

Enable the given feature when building the wasm binary.

feature needs to be a valid feature that is defined in the project Cargo.toml.

source

pub fn disable_runtime_version_section_check(self) -> Self

Disable the check for the runtime_version wasm section.

By default the wasm-builder will ensure that the runtime_version section will exists in the build wasm binary. This runtime_version section is used to get the RuntimeVersion without needing to call into the wasm binary. However, for some use cases (like tests) you may want to disable this check.

source

pub fn build(self)

Build the WASM binary.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.