variables:
  CCACHE_DIR: $(Pipeline.Workspace)/ccache
  # cpython versions to build wheels for.
  PYTHON_VERSIONS: cp36 cp37 cp38 cp39 cp310 cp311 cp312

jobs:
- job: Linux
  pool:
   vmImage: 'ubuntu-latest'
  strategy:
    matrix:
      production:
        btorConfig: ''
        btorConfigEnv: ''
      production_clang:
        btorConfig: ''
        btorConfigEnv: 'CC=clang CXX=clang++'
      debug:
        btorConfig: '-g'
        btorConfigEnv: ''
      debug_gmp:
        btorConfig: '-g --gmp'
        btorConfigEnv: ''
      python3:
        needCython: true
        btorConfig: '--python --py3'
        btorConfigEnv: ''
  steps:
  - bash: |
      sudo apt-get install ccache -y
      echo "##vso[task.prependpath]/usr/lib/ccache"
    displayName: 'Install ccache'

  - task: CacheBeta@0
    inputs:
        key: $(Agent.OS)
        path: $(CCACHE_DIR)
    displayName: ccache

  - script: sudo pip install -U cython
    condition: eq(variables.needCython, true)
    displayName: 'Install Cython'

  - script: |
      ./contrib/setup-btor2tools.sh
      ./contrib/setup-cadical.sh
      ./contrib/setup-lingeling.sh
      ./contrib/setup-cms.sh
    displayName: 'Setup dependencies'

  - script: $(btorConfigEnv) ./configure.sh $(btorConfig)
    displayName: 'Configure Boolector'

  - script: make -j $(nproc)
    workingDirectory: 'build'
    displayName: 'Build Boolector'

  - script: ctest -j$(nproc) --output-on-failure
    workingDirectory: 'build'
    displayName: 'Run CTest'

- job: macOS
  pool:
   vmImage: 'macos-latest'
  strategy:
    matrix:
      production:
        btorConfig: ''
        btorConfigEnv: ''
      production_clang:
        btorConfig: ''
        btorConfigEnv: 'CC=clang CXX=clang++'
      debug:
        btorConfig: '-g'
        btorConfigEnv: ''
      debug_gmp:
        btorConfig: '-g --gmp'
        btorConfigEnv: ''
      #python3:
      #  needCython: true
      #  btorConfig: '--python --py3'
      #  btorConfigEnv: ''
  steps:
  - script: echo "##vso[task.setvariable variable=ncpus]$(sysctl -n hw.logicalcpu)"
    displayName: 'Determine number of CPUs'

  - bash: |
      brew install ccache
      echo "##vso[task.prependpath]/usr/local/opt/ccache/libexec"
    displayName: 'Install ccache'

  - task: CacheBeta@0
    inputs:
        key: $(Agent.OS)
        path: $(CCACHE_DIR)
    displayName: ccache

  - script: sudo pip3 install cython
    condition: eq(variables.needCython, true)
    displayName: 'Install Cython'

  - script: |
      brew remove boost
      ./contrib/setup-btor2tools.sh
      ./contrib/setup-cadical.sh
      ./contrib/setup-lingeling.sh
      ./contrib/setup-cms.sh
    displayName: 'Setup dependencies'

  - script: $(btorConfigEnv) ./configure.sh $(btorConfig)
    displayName: 'Configure Boolector'

  - script: make -j $(ncpus)
    workingDirectory: 'build'
    displayName: 'Build Boolector'

  - script: ctest -j$(ncpus) --output-on-failure
    workingDirectory: 'build'
    displayName: 'Run CTest'

- template: pypi/azure-pipelines-pypi.yml

