# Starter pipeline
# Start with a minimal pipeline that you can customize to build and deploy your code.
# Add steps that build, run tests, deploy, and more:
# https://aka.ms/yaml

trigger:
  batch: true
  branches:
    include:
    - main
    - dev*
  tags:
    include:
    - v*

jobs:
- job:
  displayName: Windows 2022
  pool:
    vmImage:
      windows-2022
  strategy:
    matrix:
      Debug:
        BuildType: debug
        cmakeExtraArgs: -DCMAKE_BUILD_TYPE=Debug -DMI_DEBUG_FULL=ON
        MSBuildConfiguration: Debug
      Release:
        BuildType: release
        cmakeExtraArgs: -DCMAKE_BUILD_TYPE=Release
        MSBuildConfiguration: Release
      Release SIMD:
        BuildType: release-simd
        cmakeExtraArgs: -DCMAKE_BUILD_TYPE=Release -DMI_OPT_ARCH=ON -DMI_OPT_SIMD=ON -DMI_WIN_USE_FIXED_TLS=ON
        MSBuildConfiguration: Release
      Secure:
        BuildType: secure
        cmakeExtraArgs: -DCMAKE_BUILD_TYPE=Release -DMI_SECURE=ON
        MSBuildConfiguration: Release
      Debug x86:
        BuildType: debug
        cmakeExtraArgs: -DCMAKE_BUILD_TYPE=Debug -DMI_DEBUG_FULL=ON -A Win32
        MSBuildConfiguration: Debug
      Release x86:
        BuildType: release
        cmakeExtraArgs: -DCMAKE_BUILD_TYPE=Release -A Win32
        MSBuildConfiguration: Release
      Debug Fixed TLS:
        BuildType: debug
        cmakeExtraArgs: -DCMAKE_BUILD_TYPE=Debug -DMI_DEBUG_FULL=ON -DMI_WIN_USE_FIXED_TLS=ON
        MSBuildConfiguration: Debug
      Release Fixed TLS:
        BuildType: release
        cmakeExtraArgs: -DCMAKE_BUILD_TYPE=Release -DMI_WIN_USE_FIXED_TLS=ON
        MSBuildConfiguration: Release
  steps:
  - task: CMake@1
    inputs:
      workingDirectory: $(BuildType)
      cmakeArgs: .. $(cmakeExtraArgs)
  - task: MSBuild@1
    inputs:
      solution: $(BuildType)/libmimalloc.sln
      configuration: '$(MSBuildConfiguration)'
      msbuildArguments: -m
  - script: ctest --verbose --timeout 240 -C $(MSBuildConfiguration)
    workingDirectory: $(BuildType)
    displayName: CTest
  #- script: $(BuildType)\$(BuildType)\mimalloc-test-stress
  #  displayName: TestStress
  #- upload: $(Build.SourcesDirectory)/$(BuildType)
  #  artifact: mimalloc-windows-$(BuildType)

- job:
  displayName: Ubuntu 22.04
  pool:
    vmImage:
     ubuntu-22.04
  strategy:
    matrix:
      Debug:
        CC: gcc
        CXX: g++
        BuildType: debug
        cmakeExtraArgs: -DCMAKE_BUILD_TYPE=Debug -DMI_DEBUG_FULL=ON
      Release:
        CC: gcc
        CXX: g++
        BuildType: release
        cmakeExtraArgs: -DCMAKE_BUILD_TYPE=Release
      Secure:
        CC: gcc
        CXX: g++
        BuildType: secure
        cmakeExtraArgs: -DCMAKE_BUILD_TYPE=Release -DMI_SECURE=ON
      Debug++:
        CC: gcc
        CXX: g++
        BuildType: debug-cxx
        cmakeExtraArgs: -DCMAKE_BUILD_TYPE=Debug -DMI_DEBUG_FULL=ON -DMI_USE_CXX=ON
      Debug Clang:
        CC: clang
        CXX: clang++
        BuildType: debug-clang
        cmakeExtraArgs: -DCMAKE_BUILD_TYPE=Debug -DMI_DEBUG_FULL=ON
      Release Clang:
        CC: clang
        CXX: clang++
        BuildType: release-clang
        cmakeExtraArgs: -DCMAKE_BUILD_TYPE=Release
      Release SIMD Clang:
        CC: clang
        CXX: clang++
        BuildType: release-simd-clang
        cmakeExtraArgs: -DCMAKE_BUILD_TYPE=Release -DMI_OPT_ARCH=ON -DMI_OPT_SIMD=ON
      Secure Clang:
        CC: clang
        CXX: clang++
        BuildType: secure-clang
        cmakeExtraArgs: -DCMAKE_BUILD_TYPE=Release -DMI_SECURE=ON
      Debug++ Clang:
        CC: clang
        CXX: clang++
        BuildType: debug-clang-cxx
        cmakeExtraArgs: -DCMAKE_BUILD_TYPE=Debug -DMI_DEBUG_FULL=ON -DMI_USE_CXX=ON
      Debug ASAN Clang:
        CC: clang
        CXX: clang++
        BuildType: debug-asan-clang
        cmakeExtraArgs: -DCMAKE_BUILD_TYPE=Debug -DMI_DEBUG_FULL=ON -DMI_TRACK_ASAN=ON
      Debug UBSAN Clang:
        CC: clang
        CXX: clang++
        BuildType: debug-ubsan-clang
        cmakeExtraArgs: -DCMAKE_BUILD_TYPE=Debug -DMI_DEBUG_FULL=ON -DMI_DEBUG_UBSAN=ON
      Debug TSAN Clang++:
        CC: clang
        CXX: clang++
        BuildType: debug-tsan-clang-cxx
        cmakeExtraArgs: -DCMAKE_BUILD_TYPE=RelWithDebInfo -DMI_USE_CXX=ON -DMI_DEBUG_TSAN=ON
      Debug Guarded Clang:
        CC: clang
        CXX: clang
        BuildType: debug-guarded-clang
        cmakeExtraArgs: -DCMAKE_BUILD_TYPE=RelWithDebInfo -DMI_DEBUG_FULL=ON -DMI_GUARDED=ON

  steps:
  - task: CMake@1
    inputs:
      workingDirectory: $(BuildType)
      cmakeArgs: .. $(cmakeExtraArgs)
  - script: make -j$(nproc) -C $(BuildType)
    displayName: Make
  - script: ctest --verbose --timeout 240
    workingDirectory: $(BuildType)
    displayName: CTest
    env:
      MIMALLOC_GUARDED_SAMPLE_RATE: 1000
#  - upload: $(Build.SourcesDirectory)/$(BuildType)
#    artifact: mimalloc-ubuntu-$(BuildType)

- job:
  displayName: macOS 14 (Sonoma)
  pool:
    vmImage:
      macOS-14
  strategy:
    matrix:
      Debug:
        BuildType: debug
        cmakeExtraArgs: -DCMAKE_BUILD_TYPE=Debug -DMI_DEBUG_FULL=ON
      Release:
        BuildType: release
        cmakeExtraArgs: -DCMAKE_BUILD_TYPE=Release
      Release SIMD:
        BuildType: release-simd
        cmakeExtraArgs: -DCMAKE_BUILD_TYPE=Release -DMI_OPT_ARCH=ON -DMI_OPT_SIMD=ON
      Secure:
        BuildType: secure
        cmakeExtraArgs: -DCMAKE_BUILD_TYPE=Release -DMI_SECURE=ON
  steps:
  - task: CMake@1
    inputs:
      workingDirectory: $(BuildType)
      cmakeArgs: .. $(cmakeExtraArgs)
  - script: make -j$(sysctl -n hw.ncpu) -C $(BuildType)
    displayName: Make
  - script: ctest --verbose --timeout 240
    workingDirectory: $(BuildType)
    displayName: CTest
#  - upload: $(Build.SourcesDirectory)/$(BuildType)
#    artifact: mimalloc-macos-$(BuildType)

# ----------------------------------------------------------
# Other OS versions (just debug mode)
# ----------------------------------------------------------

- job:
  displayName: Ubuntu 24.04
  pool:
    vmImage:
      ubuntu-24.04
  strategy:
    matrix:
      Debug:
        CC: gcc
        CXX: g++
        BuildType: debug
        cmakeExtraArgs: -DCMAKE_BUILD_TYPE=Debug -DMI_DEBUG_FULL=ON
      Debug++:
        CC: gcc
        CXX: g++
        BuildType: debug-cxx
        cmakeExtraArgs: -DCMAKE_BUILD_TYPE=Debug -DMI_DEBUG_FULL=ON -DMI_USE_CXX=ON
      Debug Clang:
        CC: clang
        CXX: clang++
        BuildType: debug-clang
        cmakeExtraArgs: -DCMAKE_BUILD_TYPE=Debug -DMI_DEBUG_FULL=ON
      Debug++ Clang:
        CC: clang
        CXX: clang++
        BuildType: debug-clang-cxx
        cmakeExtraArgs: -DCMAKE_BUILD_TYPE=Debug -DMI_DEBUG_FULL=ON -DMI_USE_CXX=ON
      Release Clang:
        CC: clang
        CXX: clang++
        BuildType: release-clang
        cmakeExtraArgs: -DCMAKE_BUILD_TYPE=Release
  steps:
  - task: CMake@1
    inputs:
      workingDirectory: $(BuildType)
      cmakeArgs: .. $(cmakeExtraArgs)
  - script: make -j$(nproc) -C $(BuildType)
    displayName: Make
  - script: ctest --verbose --timeout 240
    workingDirectory: $(BuildType)
    displayName: CTest

- job:
  displayName: macOS 15 (Sequoia)
  pool:
    vmImage:
      macOS-15
  strategy:
    matrix:
      Debug:
        BuildType: debug
        cmakeExtraArgs: -DCMAKE_BUILD_TYPE=Debug -DMI_DEBUG_FULL=ON
      # Release:
      #   BuildType: release
      #   cmakeExtraArgs: -DCMAKE_BUILD_TYPE=Release
  steps:
  - task: CMake@1
    inputs:
      workingDirectory: $(BuildType)
      cmakeArgs: .. $(cmakeExtraArgs)
  - script: make -j$(sysctl -n hw.ncpu) -C $(BuildType)
    displayName: Make
  - script: ctest --verbose --timeout 240
    workingDirectory: $(BuildType)
    displayName: CTest
