steps:
- bash: |
    export CONDA=/tmp/miniforge
    wget https://github.com/conda-forge/miniforge/releases/download/24.9.0-0/Miniforge3-24.9.0-0-MacOSX-x86_64.sh
    bash Miniforge3-24.9.0-0-MacOSX-x86_64.sh -b -p ${CONDA}
  displayName: install conda
- script: |
    echo "Removing homebrew from Azure to avoid conflicts."
    curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall > ~/uninstall_homebrew
    chmod +x ~/uninstall_homebrew
    ~/uninstall_homebrew -fq
    rm ~/uninstall_homebrew
  displayName: Remove homebrew
- bash: |
    export CONDA=/tmp/miniforge
    source ${CONDA}/etc/profile.d/conda.sh
    sudo chown -R ${USER} ${CONDA}
    mkdir -p $HOME/.matplotlib
    echo -e "backend: TkAgg\n" > $HOME/.matplotlib/matplotlibrc
    conda config --set always_yes yes --set changeps1 no
    conda update -q conda
    conda create --name rdkit_build  -c conda-forge --override-channels  $(compiler) \
        libcxx=$(compiler_version) cmake=3.26 \
        libboost=$(boost_version) \
        libboost-devel=$(boost_version) \
        cairo eigen swig=4.2 make
    conda activate rdkit_build
    conda config --env --add channels conda-forge
    conda config --env --set channel_priority strict
  displayName: Setup build environment
- bash: |
    export CONDA=/tmp/miniforge
    source ${CONDA}/etc/profile.d/conda.sh
    conda activate rdkit_build
    ls -l /Library
    ls -l /Library/Developer
    ls -l /Library/Developer/CommandLineTools
    ls -l /Library/Developer/CommandLineTools/SDKs
    export SDKROOT=/Library/Developer/CommandLineTools/SDKs/MacOSX$(target_platform).sdk
    export CONDA_BUILD_SYSROOT=${SDKROOT}
    mkdir build && cd build && \
    cmake .. \
    -DCMAKE_BUILD_TYPE=Release \
    -DRDK_INSTALL_INTREE=ON \
    -DRDK_INSTALL_STATIC_LIBS=ON \
    -DRDK_BUILD_CPP_TESTS=OFF \
    -DRDK_BUILD_PYTHON_WRAPPERS=OFF \
    -DRDK_BUILD_COORDGEN_SUPPORT=ON \
    -DRDK_BUILD_MAEPARSER_SUPPORT=ON \
    -DRDK_OPTIMIZE_POPCNT=ON \
    -DRDK_BUILD_TEST_GZIP=OFF \
    -DRDK_BUILD_FREESASA_SUPPORT=ON \
    -DRDK_BUILD_AVALON_SUPPORT=ON \
    -DRDK_BUILD_INCHI_SUPPORT=ON \
    -DRDK_BUILD_YAEHMOP_SUPPORT=ON \
    -DRDK_BUILD_XYZ2MOL_SUPPORT=ON \
    -DRDK_BUILD_SWIG_WRAPPERS=ON \
    -DRDK_SWIG_STATIC=ON \
    -DRDK_BUILD_THREADSAFE_SSS=ON \
    -DRDK_TEST_MULTITHREADED=ON
  displayName: Configure build (Run CMake)
- bash: |
    export CONDA=/tmp/miniforge
    source ${CONDA}/etc/profile.d/conda.sh
    conda activate rdkit_build
    export SDKROOT=/Library/Developer/CommandLineTools/SDKs/MacOSX$(target_platform).sdk
    export CONDA_BUILD_SYSROOT=${SDKROOT}
    cd build
    make -j $( $(number_of_cores) ) install
  displayName: Build
- bash: |
    export CONDA=/tmp/miniforge
    source ${CONDA}/etc/profile.d/conda.sh
    conda activate rdkit_build
    export RDBASE=`pwd`
    export PYTHONPATH=${RDBASE}:${PYTHONPATH}
    export DYLD_FALLBACK_LIBRARY_PATH=${RDBASE}/lib:${RDBASE}/rdkit:${CONDA_PREFIX}/lib:${DYLD_FALLBACK_LIBRARY_PATH}
    export SDKROOT=/Library/Developer/CommandLineTools/SDKs/MacOSX$(target_platform).sdk
    export CONDA_BUILD_SYSROOT=${SDKROOT}
    export QT_QPA_PLATFORM='offscreen'
    cd build
    ctest -j $( $(number_of_cores) ) --output-on-failure -T Test
  displayName: Run tests
- task: PublishTestResults@2
  inputs:
    testResultsFormat: 'CTest'
    testResultsFiles: 'build/Testing/*/Test.xml'
    testRunTitle: $(system.phasedisplayname) CTest Test Run