2

Normally, when you run cargo build, both the native and Wasm runtime, along with the whole client is generated as part of the build process.

How would you compile just the Wasm runtime, so that you can easily create new Wasm to upload / upgrade your blockchain with?

1 Answer 1

2

You can find a script to do that in the Substrate repository here ./maintain/build-only-wasm.sh:

https://github.com/paritytech/substrate/blob/master/.maintain/build-only-wasm.sh

For posterity, the script contents at the time of writing this post is:

#!/usr/bin/env sh

# Script for building only the WASM binary of the given project.

set -e

PROJECT_ROOT=`git rev-parse --show-toplevel`

if [ "$#" -lt 1 ]; then
  echo "You need to pass the name of the crate you want to compile!"
  exit 1
fi

WASM_BUILDER_RUNNER="$PROJECT_ROOT/target/release/wbuild-runner/$1"

if [ -z "$2" ]; then
  export WASM_TARGET_DIRECTORY=$(pwd)
else
  export WASM_TARGET_DIRECTORY=$2
fi

if [ -d $WASM_BUILDER_RUNNER ]; then
  export DEBUG=false
  export OUT_DIR="$PROJECT_ROOT/target/release/build"
  cargo run --release --manifest-path="$WASM_BUILDER_RUNNER/Cargo.toml" \
    | grep -vE "cargo:rerun-if-|Executing build command"
else
  cargo build --release -p $1
fi
1
  • I tried it, but the WASM_TARGET_DIRECTORY was darwinia/target/release/wbuild-runner/darwinia-runtime. I haven't seen wbuild-runner folder before in any Substrate projects. Any it simply goes to the else condiction cargo build --release -p darwinia-runtime. IIUC, should this script be called build-runtime-only? Mar 23, 2023 at 9:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.