8 stable releases

✓ Uses Rust 2018 edition

1.0.7 Sep 18, 2019
1.0.6 Sep 12, 2019
1.0.5 Aug 29, 2019
1.0.4 Jul 8, 2019

#34 in WebAssembly

Download history 226/week @ 2019-07-03 139/week @ 2019-07-10 73/week @ 2019-07-17 91/week @ 2019-07-24 80/week @ 2019-07-31 124/week @ 2019-08-07 171/week @ 2019-08-14 266/week @ 2019-08-21 340/week @ 2019-08-28 304/week @ 2019-09-04 456/week @ 2019-09-11

779 downloads per month

GPL-3.0 license

466 lines

WASM builder is a utility for building a project as a WASM binary

The WASM builder is a tool that integrates the process of building the WASM binary of your project into the main cargo build process.

Project setup

A project that should be compiled as a WASM binary needs to:

  1. Add a build.rs file.
  2. Add substrate-wasm-builder-runner as dependency into build-dependencies.

The build.rs file needs to contain the following code:

use wasm_builder_runner::{build_current_project, WasmBuilderSource};

fn main() {
		// The name of the file being generated in out-dir.
		// How to include wasm-builder, in this case from crates.io.

As the final step, you need to add the following to your project:

include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));

This will include the generated WASM binary as two constants WASM_BINARY and WASM_BINARY_BLOATY. The former is a compact WASM binary and the latter is not compacted.

Environment variables

By using environment variables, you can configure which WASM binaries are built and how:

  • SKIP_WASM_BUILD - Skips building any WASM binary. This is useful when only native should be recompiled.
  • BUILD_DUMMY_WASM_BINARY - Builds dummy WASM binaries. These dummy binaries are empty and useful for cargo check runs.
  • WASM_BUILD_TYPE - Sets the build type for building WASM binaries. Supported values are release or debug. By default the build type is equal to the build type used by the main build.
  • TRIGGER_WASM_BUILD - Can be set to trigger a WASM build. On subsequent calls the value of the variable needs to change. As WASM builder instructs cargo to watch for file changes this environment variable should only be required in certain circumstances.
  • WASM_BUILD_RUSTFLAGS - Extend RUSTFLAGS given to cargo build while building the WASM binary.

Each project can be skipped individually by using the environment variable SKIP_PROJECT_NAME_WASM_BUILD. Where PROJECT_NAME needs to be replaced by the name of the cargo project, e.g. node-runtime will be NODE_RUNTIME.


WASM builder requires the following prerequisities for building the WASM binary:

  • rust nightly + wasm32-unknown-unknown toolchain
  • wasm-gc

License: GPL-3.0


~56K SLoC