language: cpp

dist: bionic

arch:
  - ppc64le

cache:
  directories:
    - $HOME/.dep_cache

env:
  global:
    - simdjson_DEPENDENCY_CACHE_DIR=$HOME/.dep_cache

matrix:
  include:
    - os: linux
      addons:
        apt:
          sources:
            - ubuntu-toolchain-r-test
          packages:
            - g++-8
      env:
        - COMPILER="CC=gcc-8 && CXX=g++-8"
      compiler: gcc-8

    - os: linux
      addons:
        apt:
          sources:
            - ubuntu-toolchain-r-test
          packages:
            - g++-9
      env:
        - COMPILER="CC=gcc-9 && CXX=g++-9"
      compiler: gcc-9

    - os: linux
      addons:
        apt:
          sources:
            - ubuntu-toolchain-r-test
          packages:
            - g++-10
      env:
        - COMPILER="CC=gcc-10 && CXX=g++-10"
      compiler: gcc-10

# The sanitizer runs fail systematically
#    - os: linux
#      addons:
#        apt:
#          sources:
#            - ubuntu-toolchain-r-test
#          packages:
#            - g++-10
#      env:
#        - COMPILER="CC=gcc-10 && CXX=g++-10"
#        - SANITIZE="on"
#      compiler: gcc-10-sanitize

    - os: linux
      addons:
        apt:
          sources:
            - ubuntu-toolchain-r-test
          packages:
            - g++-10
      env:
        - COMPILER="CC=gcc-10 && CXX=g++-10"
        - STATIC="on"
      compiler: gcc-10-static

    - os: linux
      addons:
        apt:
          sources:
            - llvm-toolchain-bionic-6.0
          packages:
            - clang-6.0
      env:
        - COMPILER="CC=clang-6.0 && CXX=clang++-6.0"
      compiler: clang-6

    - os: linux
      addons:
        apt:
          sources:
            - llvm-toolchain-bionic-7
          packages:
            - clang-7
      env:
        - COMPILER="CC=clang-7 && CXX=clang++-7"
      compiler: clang-7

    - os: linux
      addons:
        apt:
          sources:
            - llvm-toolchain-bionic-8
          packages:
            - clang-8
      env:
        - COMPILER="CC=clang-8 && CXX=clang++-8"
      compiler: clang-8

    - os: linux
      addons:
        apt:
          sources:
            - llvm-toolchain-bionic-9
          packages:
            - clang-9
      env:
        - COMPILER="CC=clang-9 && CXX=clang++-9"
      compiler: clang-9

    - os: linux
      addons:
        apt:
          packages:
            - clang-10
          sources:
            - ubuntu-toolchain-r-test
            - sourceline: 'deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-10 main'
              key_url: 'https://apt.llvm.org/llvm-snapshot.gpg.key'
      env:
        - COMPILER="CC=clang-10 && CXX=clang++-10"
      compiler: clang-10

    - os: linux
      addons:
        apt:
          packages:
            - clang-10
          sources:
            - ubuntu-toolchain-r-test
            - sourceline: 'deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-10 main'
              key_url: 'https://apt.llvm.org/llvm-snapshot.gpg.key'
      env:
        - COMPILER="CC=clang-10 && CXX=clang++-10"
        - STATIC="on"
      compiler: clang-10-static

# The clang sanitizer runs fail frequently at setup time
#    - os: linux
#      addons:
#        apt:
#          packages:
#            - clang-10
#          sources:
#            - ubuntu-toolchain-r-test
#            - sourceline: 'deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-10 main'
#              key_url: 'https://apt.llvm.org/llvm-snapshot.gpg.key'
#      env:
#        - COMPILER="CC=clang-10 && CXX=clang++-10"
#        - SANITIZE="on"
#      compiler: clang-10-sanitize

before_install:
  - eval "${COMPILER}"

install:
  - wget -q -O - "https://raw.githubusercontent.com/simdjson/debian-ppa/master/key.gpg" | sudo apt-key add -
  - sudo apt-add-repository "deb https://raw.githubusercontent.com/simdjson/debian-ppa/master simdjson main"
  - sudo apt-get -qq update
  - sudo apt-get purge cmake cmake-data
  - sudo apt-get -t simdjson -y install cmake
  - export CMAKE_CXX_FLAGS="-maltivec -mcpu=power9 -mtune=power9"
  - export CMAKE_C_FLAGS="${CMAKE_CXX_FLAGS}"
  - export CMAKE_FLAGS="-DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS} -DCMAKE_C_FLAGS=${CMAKE_C_FLAGS} -DSIMDJSON_IMPLEMENTATION=ppc64;fallback";
  - if [[ "${SANITIZE}" == "on" ]]; then
      export CMAKE_FLAGS="${CMAKE_FLAGS} -DSIMDJSON_SANITIZE=ON";
      export ASAN_OPTIONS="detect_leaks=0";
    fi
  - if [[ "${STATIC}" == "on" ]]; then
      export CMAKE_FLAGS="${CMAKE_FLAGS} -DBUILD_SHARED_LIBS=OFF";
    fi
  - export CTEST_FLAGS="-j4 --output-on-failure -LE explicitonly"

script:
  - mkdir build
  - cd build
  - cmake $CMAKE_FLAGS ..
  - cmake --build . -- -j2
  - SIMDJSON_FORCE_IMPLEMENTATION=ppc64 ctest $CTEST_FLAGS -L per_implementation
  - SIMDJSON_FORCE_IMPLEMENTATION=fallback ctest $CTEST_FLAGS -L per_implementation
  - ctest $CTEST_FLAGS -LE "acceptance|per_implementation"
