name: Build
on:
  - push
  - release
  - pull_request
  - workflow_dispatch

jobs:
  build:
    runs-on: windows-latest
    strategy:
      matrix:
        arch: [amd64, x86]
        include:
          - arch: x86
            platform: x86
          - arch: amd64
            platform: x64
    steps:
      - uses: actions/checkout@v3
      - name: setup MS dev commands
        uses: ilammy/msvc-dev-cmd@v1
        with:
          arch: ${{ matrix.arch }}

      - name: Cache fftw3
        id: cache-fftw3
        uses: actions/cache@v3
        with:
          path: ${{ github.workspace }}/vcpkg/installed/
          key:  ${{ runner.os }}-${{ matrix.arch }}-fftw3-v3
      - name: Run vcpkg
        uses: lukka/run-vcpkg@v7
        if: steps.cache-fftw3.outputs.cache-hit != 'true'
        with:
          vcpkgArguments: 'fftw3[avx2]:${{ matrix.platform }}-windows-static'
          vcpkgDirectory: '${{ github.workspace }}/vcpkg'
          vcpkgGitCommitId: 5568f110b509a9fd90711978a7cb76bae75bb092 # 2021.05.12 release

      - name: Setup Python
        uses: actions/setup-python@v4
        with:
          python-version: '3.x'
      - name: install meson and ninja
        run: pip install meson ninja
      - name: Install pkg-config lite
        shell: bash
        run: |
          curl -o pcl.zip -L https://github.com/AmusementClub/blobs/releases/download/blob-pkgconfiglite/pkg-config-lite-0.28-1_bin-win32.zip
          7z x pcl.zip
          echo "$(cygpath --absolute --long-name --windows $(pwd)/pkg-config-lite-0.28-1/bin)" >> $GITHUB_PATH
      - name: Meson setup
        run: meson setup builddir/ -Db_vscrt=mt -Dpkg_config_path=${{ github.workspace }}/vcpkg/installed/${{ matrix.platform }}-windows-static/lib/pkgconfig
      - name: Meson compile
        run: meson compile -C builddir/ -v
      - name: Build release
        shell: bash
        run: |
          mkdir release
          cp -a docs release
          cp builddir/*.dll release
      - name: Upload artifact
        uses: actions/upload-artifact@v3
        with:
          name: release-${{matrix.arch}}
          path: |
            release/*
