parameters:
- name: build_single
  type: string
  default: ''
- name: targets
  type: object
  default:
  - arch: x86_64
    alt_arch: amd64
  - arch: armv7l
    alt_arch: arm32v7
  - arch: aarch64
    alt_arch: arm64v8

jobs:
- ${{ each target in parameters.targets }}:
  - ${{ if or(not(parameters.build_single), endsWith(parameters.build_single, target.alt_arch)) }}:
    - job: build_api_proxy_${{ target.arch }}
      displayName: Build API Proxy ${{ target.arch }}
      steps:
      - script: |
          scripts/linux/buildAPIProxy.sh \
            --project 'api-proxy-module' \
            --configuration 'release' \
            --target-arch ${{ target.arch }} \
            --bin-dir '$(Build.BinariesDirectory)'
        displayName: Build
      - task: PublishBuildArtifacts@1
        displayName: Publish artifacts
        inputs:
          pathtoPublish: '$(Build.BinariesDirectory)/publish'
          artifactName: api_proxy_${{ target.arch }}
          storeAsTar: true
