parameters:
- name: componentName
  type: string
  default: rocm-core
- name: checkoutRepo
  type: string
  default: 'self'
- name: checkoutRef
  type: string
  default: ''
# monorepo related parameters
- name: sparseCheckoutDir
  type: string
  default: ''
- name: triggerDownstreamJobs
  type: boolean
  default: false
- name: downstreamAggregateNames
  type: string
  default: ''
- name: buildDependsOn
  type: object
  default: null
- name: unifiedBuild
  type: boolean
  default: false
# set to true if doing full build of ROCm stack
# and dependencies are pulled from same pipeline
- name: aggregatePipeline
  type: boolean
  default: false
- name: aptPackages
  type: object
  default:
    - cmake
    - ninja-build

- name: jobMatrix
  type: object
  default:
    buildJobs:
      - { os: ubuntu2204, packageManager: apt }
      - { os: ubuntu2404, packageManager: apt }
      - { os: almalinux8, packageManager: dnf }

jobs:
- ${{ each job in parameters.jobMatrix.buildJobs }}:
  - job: rocm_core_${{ job.os }}
    ${{ if parameters.buildDependsOn }}:
        dependsOn:
          - ${{ each build in parameters.buildDependsOn }}:
            - ${{ build }}_${{ job.os }}
    pool:
      ${{ if eq(job.os, 'ubuntu2404') }}:
        vmImage: 'ubuntu-24.04'
      ${{ else }}:
        vmImage: 'ubuntu-22.04'
    ${{ if eq(job.os, 'almalinux8') }}:
      container:
        image: rocmexternalcicd.azurecr.io/manylinux228:latest
        endpoint: ContainerService3
    variables:
    - group: common
    - template: /.azuredevops/variables-global.yml
    workspace:
      clean: all
    steps:
    - template: ${{ variables.CI_TEMPLATE_PATH }}/steps/dependencies-other.yml
      parameters:
        aptPackages: ${{ parameters.aptPackages }}
        packageManager: ${{ job.packageManager }}
    - template: ${{ variables.CI_TEMPLATE_PATH }}/steps/preamble.yml
    - template: ${{ variables.CI_TEMPLATE_PATH }}/steps/checkout.yml
      parameters:
        checkoutRepo: ${{ parameters.checkoutRepo }}
        sparseCheckoutDir: ${{ parameters.sparseCheckoutDir }}
    - template: ${{ variables.CI_TEMPLATE_PATH }}/steps/build-cmake.yml
      parameters:
        componentName: ${{ parameters.componentName }}
        os: ${{ job.os }}
        useAmdclang: false
        extraBuildFlags: >-
          -DCMAKE_CURRENT_BINARY_DIR=$PWD
          -DCMAKE_CURRENT_SOURCE_DIR=$PWD/../
          -DCMAKE_VERBOSE_MAKEFILE=1
          -DCPACK_GENERATOR=DEB
          -DCPACK_DEBIAN_PACKAGE_RELEASE="local.9999~99.99"
          -DCPACK_RPM_PACKAGE_RELEASE="local.9999"
          -DROCM_VERSION="$(NEXT_RELEASE_VERSION)"
          -GNinja
    - template: ${{ variables.CI_TEMPLATE_PATH }}/steps/manifest.yml
      parameters:
        componentName: ${{ parameters.componentName }}
        sparseCheckoutDir: ${{ parameters.sparseCheckoutDir }}
        os: ${{ job.os }}
    - template: ${{ variables.CI_TEMPLATE_PATH }}/steps/artifact-upload.yml
      parameters:
        componentName: ${{ parameters.componentName }}
        os: ${{ job.os }}
    - template: ${{ variables.CI_TEMPLATE_PATH }}/steps/artifact-links.yml
    # - template: ${{ variables.CI_TEMPLATE_PATH }}/steps/docker-container.yml
    #   parameters:
    #     aptPackages: ${{ parameters.aptPackages }}
