parameters:
  name: 'BuildMac'
  vmImage: 'macOS-10.13'

jobs:
  - job: ${{ parameters.name }}
    pool:
      vmImage: ${{ parameters.vmImage }}
    variables:
      OPAMYES: 1
      ADD_REVISION: 1
    steps:
      - checkout: self
        submodules: recursive
      - script: |
          set -ex
          brew update
          brew bundle --file=tests/Brewfile --no-upgrade
        displayName: Install dependencies
      - template: install-neko-snapshot.yaml
        parameters:
          platform: mac
      - script: |
          set -ex
          opam init
          opam update
          opam pin add haxe . --no-action
          opam install haxe --deps-only
          opam list
          ocamlopt -v
        displayName: Install OCaml libraries
      - script: |
          set -ex
          opam config exec -- make -s STATICLINK=1 "LIB_PARAMS=/usr/local/opt/zlib/lib/libz.a /usr/local/lib/libpcre.a" libs
          opam config exec -- make -s STATICLINK=1 "LIB_PARAMS=/usr/local/opt/zlib/lib/libz.a /usr/local/lib/libpcre.a" prebuild
          opam config exec -- make -s -j`sysctl -n hw.ncpu` STATICLINK=1 "LIB_PARAMS=/usr/local/opt/zlib/lib/libz.a /usr/local/lib/libpcre.a" haxe
          opam config exec -- make -s haxelib
          make -s package_bin package_installer_mac
          ls -l out
          otool -L ./haxe
          otool -L ./haxelib
        displayName: Build Haxe
      - task: PublishPipelineArtifact@0
        inputs:
          artifactName: 'macBinaries'
          targetPath: out