parameters:
- name: build_single
  type: string
  default: ''
- name: targets
  type: object
  default:
  - agent_image: agent-aziotedge-ubuntu-22.04-msmoby
    arch: amd64
    pool: $(pool.linux.name)
  - agent_image: agent-aziotedge-ubuntu-22.04-arm64-msmoby
    arch: arm32v7
    pool: $(pool.linux.arm.name)
  - agent_image: agent-aziotedge-ubuntu-22.04-arm64-msmoby
    arch: arm64v8
    pool: $(pool.linux.arm.name)

jobs:
- ${{ each target in parameters.targets }}:
  - ${{ if or(not(parameters.build_single), endsWith(parameters.build_single, target.arch)) }}:
    - job: build_rocksdb_${{ target.arch }}
      displayName: Build RocksDB ${{ target.arch }}
      pool:
          name: ${{ target.pool }}
          demands:
          - ImageOverride -equals ${{ target.agent_image }}
      steps:
      - checkout: self
        fetchDepth: 0
      - script: |
          /usr/bin/newgrp docker <<EONG
          scripts/linux/buildRocksDb.sh \
            --output-dir $(Build.ArtifactStagingDirectory) \
            --build-number $(Build.BuildNumber) \
            --arch ${{ target.arch }}
          EONG
        displayName: Build and copy out rocksdb lib
      - task: PublishBuildArtifacts@1
        displayName: Publish artifacts
        inputs:
          PathtoPublish: '$(Build.ArtifactStagingDirectory)/librocksdb'
          artifactName: 'librocksdb'
