Files
pezkuwi-subxt/substrate/utils/wasm-builder/README.md
T
Benjamin Kampmann 60e5011c72 Reorganising the repository - external renames and moves (#4074)
* Adding first rough ouline of the repository structure

* Remove old CI stuff

* add title

* formatting fixes

* move node-exits job's script to scripts dir

* Move docs into subdir

* move to bin

* move maintainence scripts, configs and helpers into its own dir

* add .local to ignore

* move core->client

* start up 'test' area

* move test client

* move test runtime

* make test move compile

* Add dependencies rule enforcement.

* Fix indexing.

* Update docs to reflect latest changes

* Moving /srml->/paint

* update docs

* move client/sr-* -> primitives/

* clean old readme

* remove old broken code in rhd

* update lock

* Step 1.

* starting to untangle client

* Fix after merge.

* start splitting out client interfaces

* move children and blockchain interfaces

* Move trie and state-machine to primitives.

* Fix WASM builds.

* fixing broken imports

* more interface moves

* move backend and light to interfaces

* move CallExecutor

* move cli off client

* moving around more interfaces

* re-add consensus crates into the mix

* fix subkey path

* relieve client from executor

* starting to pull out client from grandpa

* move is_decendent_of out of client

* grandpa still depends on client directly

* lemme tests pass

* rename srml->paint

* Make it compile.

* rename interfaces->client-api

* Move keyring to primitives.

* fixup libp2p dep

* fix broken use

* allow dependency enforcement to fail

* move fork-tree

* Moving wasm-builder

* make env

* move build-script-utils

* fixup broken crate depdencies and names

* fix imports for authority discovery

* fix typo

* update cargo.lock

* fixing imports

* Fix paths and add missing crates

* re-add missing crates
2019-11-14 21:51:17 +01:00

66 lines
2.6 KiB
Markdown

# 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` as dependency into `build-dependencies`.
The `build.rs` file needs to contain the following code:
```rust
use wasm_builder_runner::{build_current_project, WasmBuilderSource};
fn main() {
build_current_project(
// The name of the file being generated in out-dir.
"wasm_binary.rs",
// How to include wasm-builder, in this case from crates.io.
WasmBuilderSource::Crates("1.0.0"),
);
}
```
As the final step, you need to add the following to your project:
```rust
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.
- `WASM_BUILD_NO_COLOR` - Disable color output of the wasm build.
- `WASM_TARGET_DIRECTORY` - Will copy any build wasm binary to the given directory. The path needs
to be absolute.
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`.
## Prerequisites:
WASM builder requires the following prerequisities for building the WASM binary:
- rust nightly + `wasm32-unknown-unknown` toolchain
License: GPL-3.0