env:
  BUILD: check
  HOST:
  MAKEFLAGS: -j4
  BENCH: yes
  TESTRUNS:
  EXEC_CMD:
  ENABLE_FIELDS:

cat_logs_snippet: &CAT_LOGS
  on_failure:
    cat_test_log_script:
      - cat test-suite.log || true
    cat_config_log_script:
      - cat config.log || true
    cat_test_env_script:
      - cat test_env.log || true
    cat_ci_env_script:
      - env

merge_base_script_snippet: &MERGE_BASE
  merge_base_script:
    - if [ "$CIRRUS_PR" = "" ]; then exit 0; fi
    - git fetch $CIRRUS_REPO_CLONE_URL $CIRRUS_BASE_BRANCH
    - git config --global user.email "ci@ci.ci"
    - git config --global user.name "ci"
    - git merge FETCH_HEAD  # Merge base to detect silent merge conflicts

env_matrix_snippet: &ENV_MATRIX_VALGRIND
  - env:
      ENABLE_FIELDS: "7,32,58"
  - env:
      BUILD: distcheck
  - env:
      EXEC_CMD: valgrind --error-exitcode=42
      TESTRUNS: 1
      BUILD:

env_matrix_snippet: &ENV_MATRIX_SAN_VALGRIND
  - env:
      ENABLE_FIELDS: "11,64,37"
  - env:
      BUILD: distcheck
  - env:
      EXEC_CMD: valgrind --error-exitcode=42
      TESTRUNS: 1
      BUILD:
  - env:
      CXXFLAGS:  "-fsanitize=undefined -fno-omit-frame-pointer"
      LDFLAGS: "-fsanitize=undefined -fno-omit-frame-pointer"
      UBSAN_OPTIONS: "print_stacktrace=1:halt_on_error=1"
      BENCH: no

task:
  name: "x86_64: Linux (Debian stable)"
  container:
    dockerfile: ci/linux-debian.Dockerfile
    memory: 2G
    cpu: 4
  matrix:
    << : *ENV_MATRIX_SAN_VALGRIND
  matrix:
    - env:
        CXX: g++
    - env:
        CXX: clang++ -gdwarf-4
  << : *MERGE_BASE
  test_script:
    - ./ci/cirrus.sh
  << : *CAT_LOGS

task:
  name: "i686: Linux (Debian stable)"
  container:
    dockerfile: ci/linux-debian.Dockerfile
    memory: 2G
    cpu: 4
  env:
    HOST: i686-linux-gnu
  matrix:
    << : *ENV_MATRIX_VALGRIND
  matrix:
    - env:
        CXX: i686-linux-gnu-g++
    - env:
        CXX: clang++ --target=i686-linux-gnu -gdwarf-4
        CXXFLAGS: -g -O2 -isystem /usr/i686-linux-gnu/include -isystem /usr/i686-linux-gnu/include/c++/10/i686-linux-gnu
  test_script:
    - ./ci/cirrus.sh
  << : *CAT_LOGS

task:
  name: "arm64: macOS Monterey"
  macos_instance:
    image: ghcr.io/cirruslabs/macos-monterey-base:latest
  env:
    # Cirrus gives us a fixed number of 4 virtual CPUs.
    MAKEFLAGS: -j5
  matrix:
    - env:
        CXX: g++-11
      # Homebrew's gcc for arm64 has no libubsan.
      matrix:
        - env:
            ENABLE_FIELDS: 28
        - env:
            BUILD: distcheck
    - env:
        CXX: clang++
      matrix:
        - env:
            ENABLE_FIELDS: 28
        - env:
            BUILD: distcheck
        - env:
            CXXFLAGS:  "-fsanitize=undefined -fno-omit-frame-pointer"
            LDFLAGS: "-fsanitize=undefined -fno-omit-frame-pointer"
            UBSAN_OPTIONS: "print_stacktrace=1:halt_on_error=1"
            BENCH: no
  brew_script:
    - brew update
    - brew install automake libtool gcc@11
  << : *MERGE_BASE
  test_script:
    - ./ci/cirrus.sh
  << : *CAT_LOGS

task:
  name: "s390x (big-endian): Linux (Debian stable, QEMU)"
  container:
    dockerfile: ci/linux-debian.Dockerfile
    cpu: 4
    memory: 2G
  env:
    EXEC_CMD: qemu-s390x
    HOST: s390x-linux-gnu
    BUILD:
  << : *MERGE_BASE
  test_script:
    - ./ci/cirrus.sh
  << : *CAT_LOGS

task:
  name: "x86_64-w64-mingw32: Linux (Debian stable, Wine)"
  container:
    dockerfile: ci/linux-debian.Dockerfile
    cpu: 4
    memory: 2G
  env:
    EXEC_CMD: wine
    EXEC_EXT: .exe
    HOST: x86_64-w64-mingw32
    BUILD:
  << : *MERGE_BASE
  test_script:
    - ./ci/cirrus.sh
  << : *CAT_LOGS
