steps:
- bash: |
    source ${CONDA}/etc/profile.d/conda.sh
    sudo apt-get install -y clang-9
    sudo chown -R ${USER} ${CONDA}
    conda config --set always_yes yes --set changeps1 no
    conda update -q conda
    conda info -a
    conda create --name rdkit_build cmake \
        boost-cpp=$(boost_version) boost=$(boost_version) \
        py-boost=$(boost_version) libboost=$(boost_version) \
        cairo eigen
  displayName: Setup build environment
- bash: |
    source ${CONDA}/etc/profile.d/conda.sh
    conda activate rdkit_build

    export CC="clang-9"
    export CXX="clang++-9"
    export SANITIZER_FLAGS_address="-fsanitize=address -fsanitize-address-use-after-scope"
    export COVERAGE_FLAGS="-fsanitize=fuzzer-no-link"
    export CFLAGS="-O1 -fno-omit-frame-pointer -gline-tables-only -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION $COVERAGE_FLAGS $SANITIZER_FLAGS_address"
    export CXXFLAGS="$CFLAGS"
    export LIB_FUZZING_ENGINE="-fsanitize=fuzzer"

    mkdir build && cd build && \
    cmake .. \
    -DCMAKE_BUILD_TYPE=Release \
    -DRDK_INSTALL_INTREE=ON \
    -DRDK_BUILD_PYTHON_WRAPPERS=OFF \
    -DLIB_FUZZING_ENGINE=${LIB_FUZZING_ENGINE} \
    -DRDK_BUILD_FUZZ_TARGETS=ON \
    -DRDK_INSTALL_STATIC_LIBS=ON \
    -DBoost_USE_STATIC_LIBS=ON \
    -DRDK_BUILD_CPP_TESTS=OFF \
    -DBoost_NO_SYSTEM_PATHS=ON \
    -DCMAKE_INCLUDE_PATH="${CONDA_PREFIX}/include" \
    -DCMAKE_LIBRARY_PATH="${CONDA_PREFIX}/lib" \
    -DCMAKE_PREFIX_PATH=$CONDA_PREFIX
  displayName: Configure build (Run CMake)
- bash: |
    source ${CONDA}/etc/profile.d/conda.sh
    conda activate rdkit_build
    cd build
    make -j $( $(number_of_cores) ) install
  displayName: Build
- bash: |
    source ${CONDA}/etc/profile.d/conda.sh
    conda activate rdkit_build
    corpora=$(find . -type d -name "*_fuzzer")
    for corpus in $corpora; do
      corpus_basename=$(basename $corpus)
      fuzzer_target=$(find . -type f -name "${corpus_basename}" -print -quit)
      ${fuzzer_target} ${corpus}/*
    done
  displayName: Run fuzzer on existing corpora
