diff --git a/.travis.yml b/.travis.yml index 937507439f9f9..2b392c798aced 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,4 +14,8 @@ matrix: script: - cargo test --all - cargo clean - - ./publish-wasm.sh + - ./init.sh + - ./build.sh + - if [ "$TRAVIS_PULL_REQUEST" != "true" ] && [ "$TRAVIS_BRANCH" == "master" ]; then + ./publish-wasm.sh; + fi diff --git a/build.sh b/build.sh index dd47753730759..8cac3c5e5c1af 100755 --- a/build.sh +++ b/build.sh @@ -1,13 +1,27 @@ -#!/bin/sh +#!/bin/bash -# NOTE `cargo install wasm-gc` before running this script. -# NOTE `cargo install --git https://github.com/pepyakin/wasm-export-table.git` +# This script assumes that all pre-requisites are installed. set -e + +source `dirname "$0"`/common.sh + export CARGO_INCREMENTAL=0 -cd demo/runtime/wasm && ./build.sh && cd ../../.. -cd substrate/executor/wasm && ./build.sh && cd ../../.. -cd substrate/test-runtime/wasm && ./build.sh && cd ../../.. -cd polkadot/runtime/wasm && ./build.sh && cd ../../.. -cd polkadot/parachain/test-chains && ./build.sh && cd ../../.. +# Save current directory. +pushd . + +cd $ROOT + +for SRC in "${SRCS[@]}" +do + echo "*** Building wasm binaries in $SRC" + cd $SRC + + ./build.sh + + cd - >> /dev/null +done + +# Restore initial directory. +popd diff --git a/common.sh b/common.sh new file mode 100644 index 0000000000000..ba131bd969b5e --- /dev/null +++ b/common.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +ROOT=`dirname "$0"` + +# A list of directories which contain wasm projects. +SRCS=( + "polkadot/runtime/wasm" + "substrate/executor/wasm" + "demo/runtime/wasm" + "substrate/test-runtime/wasm" + "polkadot/parachain/test-chains/basic_add" +) + +# Make pushd/popd silent. + +pushd () { + command pushd "$@" > /dev/null +} + +popd () { + command popd "$@" > /dev/null +} diff --git a/demo/runtime/wasm/build.sh b/demo/runtime/wasm/build.sh index 53ca2a0018ce5..093e8c1a8a21b 100755 --- a/demo/runtime/wasm/build.sh +++ b/demo/runtime/wasm/build.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash set -e cargo +nightly build --target=wasm32-unknown-unknown --release diff --git a/demo/runtime/wasm/init.sh b/demo/runtime/wasm/init.sh deleted file mode 100755 index e8b4387a2f998..0000000000000 --- a/demo/runtime/wasm/init.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/sh - -rustup update nightly -rustup target add wasm32-unknown-unknown --toolchain nightly -rustup update stable -cargo install --git https://github.com/alexcrichton/wasm-gc -cargo install --git https://github.com/pepyakin/wasm-export-table.git diff --git a/init.sh b/init.sh new file mode 100755 index 0000000000000..6e70b76d32712 --- /dev/null +++ b/init.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +set -e + +echo "*** Initilising WASM build environment" + +rustup update nightly +rustup target add wasm32-unknown-unknown --toolchain nightly +rustup update stable + +# Install wasm-gc. It's useful for stripping slimming down wasm binaries. +command -v wasm-gc || \ + cargo +nightly install --git https://github.com/alexcrichton/wasm-gc + +# At the moment of writing, rustc still uses LLD 6 which produces wasm binaries +# that don't export a table. Meanwhile, we are waiting for LLD 7 to come +# in rustc we could use this handy little tool. +command -v wasm-export-table || \ + cargo +nightly install --git https://github.com/pepyakin/wasm-export-table.git diff --git a/polkadot/parachain/test-chains/basic_add/build.sh b/polkadot/parachain/test-chains/basic_add/build.sh new file mode 100755 index 0000000000000..965913f4957ee --- /dev/null +++ b/polkadot/parachain/test-chains/basic_add/build.sh @@ -0,0 +1,12 @@ +#!/bin/bash +set -e + +# Make LLD produce a binary that imports memory from the outside environment. +export RUSTFLAGS="-C link-arg=--import-memory" + +cargo +nightly build --target=wasm32-unknown-unknown --release --no-default-features + +for i in basic_add +do + wasm-gc target/wasm32-unknown-unknown/release/$i.wasm target/wasm32-unknown-unknown/release/$i.compact.wasm +done diff --git a/polkadot/parachain/test-chains/build.sh b/polkadot/parachain/test-chains/build.sh index 2b876634e88c7..d46a63561363d 100755 --- a/polkadot/parachain/test-chains/build.sh +++ b/polkadot/parachain/test-chains/build.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash set -e rm -rf ./target diff --git a/polkadot/runtime/wasm/build.sh b/polkadot/runtime/wasm/build.sh index d48d10a062d38..8920ca8bbb35c 100755 --- a/polkadot/runtime/wasm/build.sh +++ b/polkadot/runtime/wasm/build.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash set -e cargo +nightly build --target=wasm32-unknown-unknown --release diff --git a/polkadot/runtime/wasm/init.sh b/polkadot/runtime/wasm/init.sh deleted file mode 100755 index 703207078c511..0000000000000 --- a/polkadot/runtime/wasm/init.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/sh - -rustup update nightly -rustup target add wasm32-unknown-unknown --toolchain nightly -rustup update stable -cargo +nightly install --git https://github.com/alexcrichton/wasm-gc -cargo +nightly install --git https://github.com/pepyakin/wasm-export-table.git diff --git a/publish-wasm.sh b/publish-wasm.sh index 2a42504eef6b9..de60ad69c54c9 100755 --- a/publish-wasm.sh +++ b/publish-wasm.sh @@ -1,35 +1,26 @@ #!/bin/bash +# Publish wasm binaries into the special repository. +# This script assumes that wasm binaries have already been built. +# Requires GH_TOKEN environment variable to be defined. + set -e +source `dirname "$0"`/common.sh + +if [ -z ${GH_TOKEN+x} ]; then + echo "GH_TOKEN environment variable is not set" + exit 1 +fi + REPO="github.com/paritytech/polkadot-wasm-bin.git" REPO_AUTH="${GH_TOKEN}:@${REPO}" -SRCS=( "polkadot/runtime/wasm" "substrate/executor/wasm" "demo/runtime/wasm" "substrate/test-runtime/wasm" "polkadot/parachain/test-chains" ) DST=".wasm-binaries" TARGET="wasm32-unknown-unknown" UTCDATE=`date -u "+%Y%m%d.%H%M%S.0"` pushd . -echo "*** Initilising WASM build environment" -cd polkadot/runtime/wasm -./init.sh || true -cd ../../.. - -for SRC in "${SRCS[@]}" -do - echo "*** Building wasm binaries in $SRC" - cd $SRC - ./build.sh - cd ../../.. -done - -if [ "$TRAVIS_PULL_REQUEST" != "false" -o "$TRAVIS_BRANCH" != "master" ]; then - popd - echo "*** Skipping wasm binary publish" - exit 0 -fi - echo "*** Cloning repo" rm -rf $DST git clone https://$REPO $DST diff --git a/substrate/executor/wasm/build.sh b/substrate/executor/wasm/build.sh index 83acc2700d37d..7dcb11af109bc 100755 --- a/substrate/executor/wasm/build.sh +++ b/substrate/executor/wasm/build.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash set -e cargo +nightly build --target=wasm32-unknown-unknown --release diff --git a/substrate/test-runtime/wasm/build.sh b/substrate/test-runtime/wasm/build.sh index e2d1faeb7312b..4cb6edb9c9caa 100755 --- a/substrate/test-runtime/wasm/build.sh +++ b/substrate/test-runtime/wasm/build.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash set -e cargo +nightly build --target=wasm32-unknown-unknown --release diff --git a/substrate/test-runtime/wasm/init.sh b/substrate/test-runtime/wasm/init.sh deleted file mode 100755 index e8b4387a2f998..0000000000000 --- a/substrate/test-runtime/wasm/init.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/sh - -rustup update nightly -rustup target add wasm32-unknown-unknown --toolchain nightly -rustup update stable -cargo install --git https://github.com/alexcrichton/wasm-gc -cargo install --git https://github.com/pepyakin/wasm-export-table.git