---
dist: trusty
language: rust
services: docker
sudo: required
rust: stable

env:
  global:
    - CRATE_NAME=bytes
    # Default job
    - TARGET=x86_64-unknown-linux-gnu
    - secure: "f17G5kb6uAQlAG9+GknFFYAmngGBqy9h+3FtNbp3mXTI0FOLltz00Ul5kGPysE4eagypm/dWOuvBkNjN01jhE6fCbekmInEsobIuanatrk6TvXT6caJqykxhPJC2cUoq8pKnMqEOuucEqPPUH6Qy6Hz4/2cRu5JV22Uv9dtS29Q="

matrix:
  include:
    # Run build on oldest supported rust version. Do not change the rust
    # version without a Github issue first.
    #
    # This job will also build and deploy the docs to gh-pages.
    - env: TARGET=x86_64-unknown-linux-gnu
      rust: 1.26.0
      after_success:
        - |
            pip install 'travis-cargo<0.2' --user &&
            export PATH=$HOME/.local/bin:$PATH
        - travis-cargo doc
        - travis-cargo doc-upload

    # Run tests on some extra platforms
    - env: TARGET=i686-unknown-linux-gnu
    - env: TARGET=armv7-unknown-linux-gnueabihf
    - env: RUST_TEST_THREADS=1 TARGET=powerpc-unknown-linux-gnu
    - env: RUST_TEST_THREADS=1 TARGET=powerpc64-unknown-linux-gnu

    # Serde implementation
    - env: EXTRA_ARGS="--features serde"

    # 128 bit numbers
    - env: EXTRA_ARGS="--features i128"

    # WASM support
    - rust: beta
      script:
        - rustup target add wasm32-unknown-unknown
        - cargo build --target=wasm32-unknown-unknown

    # Sanitizers
    - rust: nightly
      os: linux
      script:
        - |
          set -e

          export RUST_TEST_THREADS=1
          export ASAN_OPTIONS="detect_odr_violation=0 detect_leaks=0"
          export TSAN_OPTIONS="suppressions=`pwd`/ci/tsan"

          # Run address sanitizer
          RUSTFLAGS="-Z sanitizer=address" \
          cargo test --tests --target x86_64-unknown-linux-gnu

          # Run thread sanitizer
          RUSTFLAGS="-Z sanitizer=thread" \
          cargo test --tests --target x86_64-unknown-linux-gnu

before_install: set -e

install:
  - sh ci/install.sh
  - source ~/.cargo/env || true

script:
  - bash ci/script.sh

after_script: set +e

before_deploy:
  - sh ci/before_deploy.sh

cache: cargo
before_cache:
  # Travis can't cache files that are not readable by "others"
  - chmod -R a+r $HOME/.cargo

notifications:
  email:
    on_success: never
