Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Merge pull request #210 from paritytech/ser-refactor-build
Browse files Browse the repository at this point in the history
Refactor build scripts.
  • Loading branch information
pepyakin authored Jun 11, 2018
2 parents 5576d55 + 301d44d commit a123687
Show file tree
Hide file tree
Showing 14 changed files with 96 additions and 55 deletions.
6 changes: 5 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
30 changes: 22 additions & 8 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
#!/bin/sh
#!/bin/bash

# NOTE `cargo install wasm-gc` before running this script.
# NOTE `cargo install --git https:/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
22 changes: 22 additions & 0 deletions common.sh
Original file line number Diff line number Diff line change
@@ -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
}
2 changes: 1 addition & 1 deletion demo/runtime/wasm/build.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash
set -e

cargo +nightly build --target=wasm32-unknown-unknown --release
Expand Down
7 changes: 0 additions & 7 deletions demo/runtime/wasm/init.sh

This file was deleted.

19 changes: 19 additions & 0 deletions init.sh
Original file line number Diff line number Diff line change
@@ -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:/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:/pepyakin/wasm-export-table.git
12 changes: 12 additions & 0 deletions polkadot/parachain/test-chains/basic_add/build.sh
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion polkadot/parachain/test-chains/build.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash
set -e

rm -rf ./target
Expand Down
2 changes: 1 addition & 1 deletion polkadot/runtime/wasm/build.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash
set -e

cargo +nightly build --target=wasm32-unknown-unknown --release
Expand Down
7 changes: 0 additions & 7 deletions polkadot/runtime/wasm/init.sh

This file was deleted.

31 changes: 11 additions & 20 deletions publish-wasm.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion substrate/executor/wasm/build.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash
set -e

cargo +nightly build --target=wasm32-unknown-unknown --release
Expand Down
2 changes: 1 addition & 1 deletion substrate/test-runtime/wasm/build.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash
set -e

cargo +nightly build --target=wasm32-unknown-unknown --release
Expand Down
7 changes: 0 additions & 7 deletions substrate/test-runtime/wasm/init.sh

This file was deleted.

0 comments on commit a123687

Please sign in to comment.