#===----------------------------------------------------------------------===##
#
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#
#===----------------------------------------------------------------------===##

#
# This file describes the various pre-commit CI bots used to test libc++.
#
# This file should never contain logic -- all the logic must be offloaded
# into scripts. This is critical to being able to reproduce CI issues outside
# of the CI environment, which is important for debugging.
#
# It is also worth noting that this script is split into several sections, the
# goal being to reduce the load on testers when a commit is known to fail.
#

env:
    # LLVM POST-BRANCH bump version
    # LLVM POST-BRANCH add compiler test for ToT - 1, e.g. "Clang 17"
    # LLVM RELEASE bump remove compiler ToT - 3, e.g. "Clang 15"
    LLVM_HEAD_VERSION: "18"   # Used compiler, update POST-BRANCH.
    GCC_STABLE_VERSION: "13"

definitions:
  _common: &common
    timeout_in_minutes: 120
    retry:
      automatic:
        - exit_status: -1  # Agent was lost
          limit: 2
    artifact_paths:
      - "**/test-results.xml"
      - "**/*.abilist"
      - "**/crash_diagnostics/*"

steps:
- group: ':mac: Apple'
  steps:
  - label: MacOS x86_64
    command: libcxx/utils/ci/run-buildbot generic-cxx23
    agents:
      queue: libcxx-builders
      os: macos
      arch: x86_64
    <<: *common

  - label: MacOS arm64
    command: libcxx/utils/ci/run-buildbot generic-cxx23
    agents:
      queue: libcxx-builders
      os: macos
      arch: arm64
    <<: *common

  - label: MacOS with Modules
    command: libcxx/utils/ci/run-buildbot generic-modules
    agents:
      queue: libcxx-builders
      os: macos
    <<: *common

  - label: MacOS with C++03
    command: libcxx/utils/ci/run-buildbot generic-cxx03
    agents:
      queue: libcxx-builders
      os: macos
    <<: *common

    # Build with the configuration we use to generate libc++.dylib on Apple platforms
  - label: Apple system configuration
    command: libcxx/utils/ci/run-buildbot apple-configuration
    agents:
      queue: libcxx-builders
      os: macos
      arch: arm64 # This can technically run on any architecture, but we have more resources on arm64 so we pin this job to arm64
    <<: *common

  - label: Apple back-deployment macosx10.13
    command: libcxx/utils/ci/run-buildbot apple-system-backdeployment-10.13
    agents:
      queue: libcxx-builders
      os: macos
      arch: x86_64 # We need to use x86_64 for back-deployment CI on this target since macOS didn't support arm64 back then
    <<: *common

  - label: Apple back-deployment macosx10.15
    command: libcxx/utils/ci/run-buildbot apple-system-backdeployment-10.15
    agents:
      queue: libcxx-builders
      os: macos
      arch: x86_64 # We need to use x86_64 for back-deployment CI on this target since macOS didn't support arm64 back then
    <<: *common

  - label: Apple back-deployment with hardening enabled
    command: libcxx/utils/ci/run-buildbot apple-system-backdeployment-hardened-11.0
    agents:
      queue: libcxx-builders
      os: macos
      arch: x86_64 # TODO: Remove this once we are able to run back-deployment on arm64 again, since this isn't x86_64 specific
    <<: *common

- group: ARM
  steps:
  - label: AArch64
    command: libcxx/utils/ci/run-buildbot aarch64
    agents:
      queue: libcxx-builders-linaro-arm
      arch: aarch64
    <<: *common

  - label: AArch64 -fno-exceptions
    command: libcxx/utils/ci/run-buildbot aarch64-no-exceptions
    agents:
      queue: libcxx-builders-linaro-arm
      arch: aarch64
    <<: *common

  - label: Armv8
    command: libcxx/utils/ci/run-buildbot armv8
    agents:
      queue: libcxx-builders-linaro-arm
      arch: armv8l
    <<: *common

  - label: Armv8 -fno-exceptions
    command: libcxx/utils/ci/run-buildbot armv8-no-exceptions
    agents:
      queue: libcxx-builders-linaro-arm
      arch: armv8l
    <<: *common

  - label: Armv7
    command: libcxx/utils/ci/run-buildbot armv7
    agents:
      queue: libcxx-builders-linaro-arm
      arch: armv8l
    <<: *common

  - label: Armv7 -fno-exceptions
    command: libcxx/utils/ci/run-buildbot armv7-no-exceptions
    agents:
      queue: libcxx-builders-linaro-arm
      arch: armv8l
    <<: *common

  - label: Armv7-M picolibc
    command: libcxx/utils/ci/run-buildbot armv7m-picolibc
    agents:
      queue: libcxx-builders-linaro-arm
      arch: aarch64
    <<: *common

  - label: Armv7-M picolibc -fno-exceptions
    command: libcxx/utils/ci/run-buildbot armv7m-picolibc-no-exceptions
    agents:
      queue: libcxx-builders-linaro-arm
      arch: aarch64
    <<: *common

- group: AIX
  steps:
  - label: AIX (32-bit)
    command: libcxx/utils/ci/run-buildbot aix
    env:
      CC: clang
      CXX: clang++
      OBJECT_MODE: '32'
    agents:
      queue: libcxx-builders
      os: aix
    <<: *common

  - label: AIX (64-bit)
    command: libcxx/utils/ci/run-buildbot aix
    env:
      CC: clang
      CXX: clang++
      OBJECT_MODE: '64'
    agents:
      queue: libcxx-builders
      os: aix
    <<: *common

- group: ':freebsd: FreeBSD'
  steps:
  - label: FreeBSD 13 amd64
    command: libcxx/utils/ci/run-buildbot generic-cxx26
    env:
      CC: clang17
      CXX: clang++17
    agents:
      queue: libcxx-builders
      os: freebsd
    <<: *common

- group: ':android: Android'
  steps:
  - label: Android 5.0, x86 NDK
    command: libcxx/utils/ci/run-buildbot android-ndk-21-def-x86
    agents:
      queue: libcxx-builders
      os: android
    <<: *common

  - label: Android 13, x86_64 NDK
    command: libcxx/utils/ci/run-buildbot android-ndk-33-goog-x86_64
    agents:
      queue: libcxx-builders
      os: android
    <<: *common


    # TODO: Re-enable this once we've figured out how to run back-deployment testing on arm64 on recent OSes
    # - label: "Apple back-deployment macosx11.0 arm64"
    #   command: "libcxx/utils/ci/run-buildbot apple-system-backdeployment-11.0"
    #   artifact_paths:
    #     - "**/test-results.xml"
    #     - "**/*.abilist"
    #   agents:
    #     queue: "libcxx-builders"
    #     os: "macos"
    #     arch: "arm64"
    #   retry:
    #     automatic:
    #       - exit_status: -1  # Agent was lost
    #         limit: 2
    #   timeout_in_minutes: 120
