diff --git a/.travis.yml b/.travis.yml index 092ffab73..85923d0a8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,20 +5,21 @@ sudo: false addons: chrome: stable +cache: + cargo: true + directories: + - /home/travis/.local/share/cargo-web/emscripten + rust: + - nightly - stable - beta - - nightly matrix: allow_failures: - rust: nightly -env: - - TARGET=wasm32-unknown-unknown - - TARGET=asmjs-unknown-emscripten - - TARGET=wasm32-unknown-emscripten - script: - nvm install 9 - - ./ci.sh + - ./ci/install_cargo_web.sh + - ./ci/run_tests.sh diff --git a/ci.sh b/ci.sh deleted file mode 100755 index a5545d45f..000000000 --- a/ci.sh +++ /dev/null @@ -1,59 +0,0 @@ -#!/bin/bash - -# Originally this ci script borrowed from https://github.com/koute/stdweb -# because both use `cargo-web` tool to check the compilation. - -set -euo pipefail -IFS=$'\n\t' - -set +e -echo "$(rustc --version)" | grep -q "nightly" -if [ "$?" = "0" ]; then - export IS_NIGHTLY=1 -else - export IS_NIGHTLY=0 -fi -set -e - -echo "Is Rust from nightly: $IS_NIGHTLY" - -if [ "$IS_NIGHTLY" = "0" ]; then - if [ "$TARGET" = "wasm32-unknown-unknown" ]; then - echo "Skipping tests; wasm32-unknown-unknown is only supported on nightly" - exit 0 - fi -fi - -cargo install cargo-web -f - -if [ "$TARGET" = "asmjs-unknown-emscripten" ]; then - rustup target add asmjs-unknown-emscripten - export CARGO_WEB_ARGS="--target-asmjs-emscripten" - cargo web test --features web_test $CARGO_WEB_ARGS -fi - -if [ "$TARGET" = "wasm32-unknown-emscripten" ]; then - rustup target add wasm32-unknown-emscripten - export CARGO_WEB_ARGS="--target-webasm-emscripten" - cargo web test --features web_test $CARGO_WEB_ARGS -fi - -if [ "$TARGET" = "wasm32-unknown-unknown" ]; then - rustup target add wasm32-unknown-unknown - export CARGO_WEB_ARGS="--target-webasm" - cargo web test --nodejs $CARGO_WEB_ARGS -fi - -check_example() { - echo "Checking example [$1]" - cd $1 - cargo web build $CARGO_WEB_ARGS - # TODO Can't build some demos with release, need fix - # cargo web build --release $CARGO_WEB_ARGS -} - -for EXAMPLE in $(pwd)/examples/*; do - if [ -d "$EXAMPLE" ]; then - check_example $EXAMPLE - fi -done diff --git a/ci/install_cargo_web.sh b/ci/install_cargo_web.sh new file mode 100755 index 000000000..b35f06919 --- /dev/null +++ b/ci/install_cargo_web.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +set -euo pipefail +IFS=$'\n\t' + +CARGO_WEB_RELEASE=$(curl -L -s -H 'Accept: application/json' https://github.com/koute/cargo-web/releases/latest) +CARGO_WEB_VERSION=$(echo $CARGO_WEB_RELEASE | sed -e 's/.*"tag_name":"\([^"]*\)".*/\1/') +CARGO_WEB_URL="https://github.com/koute/cargo-web/releases/download/$CARGO_WEB_VERSION/cargo-web-x86_64-unknown-linux-gnu.gz" + +echo "Downloading cargo-web from: $CARGO_WEB_URL" +curl -L $CARGO_WEB_URL | gzip -d > cargo-web +chmod +x cargo-web + +mkdir -p ~/.cargo/bin +mv cargo-web ~/.cargo/bin diff --git a/ci/run_tests.sh b/ci/run_tests.sh new file mode 100755 index 000000000..e5b8c5046 --- /dev/null +++ b/ci/run_tests.sh @@ -0,0 +1,67 @@ +#!/bin/bash + +# Originally this ci script borrowed from https://github.com/koute/stdweb +# because both use `cargo-web` tool to check the compilation. + +set -euo pipefail +IFS=$'\n\t' + +set +e +echo "$(rustc --version)" | grep -q "nightly" +if [ "$?" = "0" ]; then + export IS_NIGHTLY=1 +else + export IS_NIGHTLY=0 +fi +set -e + +echo "Is Rust from nightly: $IS_NIGHTLY" + +echo "Testing for asmjs-unknown-emscripten..." +cargo web test --features web_test --target=asmjs-unknown-emscripten + +echo "Testing for wasm32-unknown-emscripten..." +cargo web test --features web_test --target=wasm32-unknown-emscripten + +if [ "$IS_NIGHTLY" = "1" ]; then + echo "Testing for wasm32-unknown-unknown..." + cargo web test --nodejs --target=wasm32-unknown-unknown +fi + +check_example() { + echo "Checking example [$2]" + pushd $2 > /dev/null + cargo web build --target=$1 + popd > /dev/null + + # TODO Can't build some demos with release, need fix + # cargo web build --release $CARGO_WEB_ARGS +} + +check_all_examples() { + echo "Checking examples on $1..." + for EXAMPLE in $(pwd)/examples/*; do + if [ "$1" == "wasm32-unknown-unknown" ]; then + # The counter example doesn't yet build here. + case $(basename $EXAMPLE) in + "counter") + continue + ;; + *) + ;; + esac + fi + + if [ -d "$EXAMPLE" ]; then + check_example $1 $EXAMPLE + fi + done +} + + +check_all_examples asmjs-unknown-emscripten +check_all_examples wasm32-unknown-emscripten + +if [ "$IS_NIGHTLY" = "1" ]; then + check_all_examples wasm32-unknown-unknown +fi