jobs:
- job: Linux
  pool:
    vmImage: ubuntu-16.04
  steps:
  - script: azure-pipelines/build-linux
    displayName: 'Generate, build, and test'
  - task: PublishBuildArtifacts@1
    inputs:
      pathtoPublish: '$(System.DefaultWorkingDirectory)/distfiles.zip'
      artifactName: distfiles
    displayName: 'Upload extra distribution files'
    condition: eq(variables['System.PullRequest.IsFork'], 'False')
  - task: PublishBuildArtifacts@1
    inputs:
      pathtoPublish: '$(System.DefaultWorkingDirectory)/distribution'
      artifactName: distribution
    displayName: 'Upload source distribution'
    condition: eq(variables['System.PullRequest.IsFork'], 'False')
  - task: PublishTestResults@2
    inputs:
      testRunTitle: Linux
      buildPlatform: Linux
- job: Windows
  pool:
    # If updating this, see note in TODO about MSVC wildcard expansion.
    vmImage: windows-2019
  strategy:
    matrix:
      msvc32:
        wordsize: 32
        tool: msvc
      msvc64:
        wordsize: 64
        tool: msvc
      mingw32:
        wordsize: 32
        tool: mingw
      mingw64:
        wordsize: 64
        tool: mingw
    maxParallel: 4
  steps:
  - bash: git config --global core.autocrlf input
    displayName: 'Disable git autocrlf'
  - checkout: self
    displayName: 'Get sources'
  - task: DownloadBuildArtifacts@0
    displayName: 'Download distribution files'
    inputs:
      artifactName: distfiles
      downloadPath: $(System.DefaultWorkingDirectory)
    condition: eq(variables['System.PullRequest.IsFork'], 'False')
  - script: azure-pipelines/build-windows.bat $(wordsize) $(tool)
    displayName: 'Build, test, generate binary distributions'
  - task: PublishBuildArtifacts@1
    inputs:
      pathtoPublish: '$(System.DefaultWorkingDirectory)/distribution'
      artifactName: distribution
    displayName: 'Upload binary distributions'
    condition: eq(variables['System.PullRequest.IsFork'], 'False')
  - task: PublishTestResults@2
    inputs:
      testRunTitle: Windows-$(wordsize)$(tool)
      buildPlatform: Windows-$(wordsize)$(tool)
  dependsOn: Linux
  condition: succeeded()
- job: macOS
  pool:
    vmImage: macOS-10.14
  steps:
  - task: DownloadBuildArtifacts@0
    displayName: 'Download distribution files'
    inputs:
      artifactName: distfiles
      downloadPath: $(System.DefaultWorkingDirectory)
    condition: eq(variables['System.PullRequest.IsFork'], 'False')
  - script: azure-pipelines/build-mac
    displayName: 'Mac build and test'
  - task: PublishTestResults@2
    inputs:
      testRunTitle: MacOS
      buildPlatform: MacOS
  dependsOn: Linux
  condition: succeeded()
- job: AppImage
  pool:
    vmImage: ubuntu-16.04
  steps:
  - script: azure-pipelines/build-appimage
    displayName: 'Build AppImage'
  - task: PublishBuildArtifacts@1
    inputs:
      pathtoPublish: '$(System.DefaultWorkingDirectory)/distribution'
      artifactName: distribution
    displayName: 'Upload AppImage'
    condition: eq(variables['System.PullRequest.IsFork'], 'False')
  - task: PublishTestResults@2
    inputs:
      testRunTitle: AppImage
      buildPlatform: AppImage
  dependsOn: Linux
  condition: succeeded()
- job: Linux32
  pool:
    vmImage: ubuntu-16.04
  steps:
  - script: azure-pipelines/build-linux32
    displayName: 'Linux 32-bit'
  - task: PublishTestResults@2
    inputs:
      testRunTitle: Linux32
      buildPlatform: Linux32
  dependsOn: Linux
  condition: succeeded()
- job: Fuzzers
  pool:
    vmImage: ubuntu-16.04
  steps:
  - script: azure-pipelines/build-fuzzer
    displayName: 'Build Fuzzer'
  dependsOn: Linux
  condition: succeeded()
- job: Sanitizers
  pool:
    vmImage: ubuntu-16.04
  steps:
  - script: azure-pipelines/test-sanitizers
    displayName: 'Sanitizer Tests'
  - task: PublishTestResults@2
    inputs:
      testRunTitle: Sanitizers
      buildPlatform: Sanitizers
  dependsOn: Linux
  condition: succeeded()
