language: rust
sudo: true # Required for functional IPv6 (forces VM instead of Docker).
dist: xenial
rust:
  - stable
  - nightly
  - beta
matrix:
  allow_failures:
    rust: nightly
  fast_finish: true

cache: cargo

before_script:
  # Add an IPv6 config - see the corresponding Travis issue
  # https://github.com/travis-ci/travis-ci/issues/8361
  - if [ "${TRAVIS_OS_NAME}" == "linux" ]; then
      sudo sh -c 'echo 0 > /proc/sys/net/ipv6/conf/all/disable_ipv6';
    fi

script:
  - cargo build --verbose --all
  - cargo test --verbose --all
  - 'if [ $TRAVIS_RUST_VERSION = nightly ]; then for f in ./benches/*.rs; do cargo test --bench $(basename $f .rs) $FEATURES; done; fi'

addons:
  apt:
    packages:
      - libcurl4-openssl-dev
      - libelf-dev
      - libdw-dev
      - cmake
      - gcc
      - binutils-dev
      - libiberty-dev

after_success: |
  wget https://github.com/SimonKagstrom/kcov/archive/master.tar.gz &&
  tar xzf master.tar.gz &&
  cd kcov-master &&
  mkdir build &&
  cd build &&
  cmake .. &&
  make &&
  make install DESTDIR=../../kcov-build &&
  cd ../.. &&
  rm -rf kcov-master &&
  for file in target/debug/civil-*[^\.d]; do mkdir -p "target/cov/$(basename $file)"; ./kcov-build/usr/local/bin/kcov --exclude-pattern=/.cargo,/usr/lib --verify "target/cov/$(basename $file)" "$file"; done &&
  bash <(curl -s https://codecov.io/bash) &&
  echo "Uploaded code coverage"
