name: build

on:
  push:

env:
  CACHE_VERSION: 39
  CARDINAL_UNDER_WINE: 1
  EMSCRIPTEN_VERSION: 3.1.27
  DEBIAN_FRONTEND: noninteractive
  HOMEBREW_NO_AUTO_UPDATE: 1
  LIBGL_ALWAYS_SOFTWARE: 'true'
  WITH_LTO: 'true'

jobs:
  linux-arm64:
    runs-on: ubuntu-20.04
    steps:
      - uses: actions/checkout@v3
        with:
          submodules: recursive
      - name: Set up cache
        id: cache
        uses: actions/cache@v3
        with:
          path: |
            ~/PawPawBuilds
            src/Rack/dep/bin
            src/Rack/dep/include
            src/Rack/dep/lib
            src/Rack/dep/share
            src/Rack/dep/jansson-2.12
            src/Rack/dep/libarchive-3.4.3
            src/Rack/dep/libsamplerate-0.1.9
            src/Rack/dep/speexdsp-SpeexDSP-1.2rc3
            src/Rack/dep/zstd-1.4.5
          key: linux-arm64-v${{ env.CACHE_VERSION }}-${{ env.WITH_LTO }}
      - name: Fix GitHub's mess
        run: |
          sudo rm -f /etc/apt/sources.list.d/microsoft-prod.list
          sudo apt-get update -qq
          sudo apt-get install -yqq --allow-downgrades libpcre2-8-0/focal libpcre2-16-0/focal libpcre2-32-0/focal libpcre2-posix2/focal
          sudo apt-get clean
      - name: Set up dependencies
        run: |
          sudo dpkg --add-architecture arm64
          sudo sed -i "s/deb http/deb [arch=amd64] http/" /etc/apt/sources.list
          echo "deb [arch=arm64] http://ports.ubuntu.com/ubuntu-ports focal main restricted universe multiverse" | sudo tee /etc/apt/sources.list.d/ports-arm64.list
          echo "deb [arch=arm64] http://ports.ubuntu.com/ubuntu-ports focal-updates main restricted universe multiverse" | sudo tee -a /etc/apt/sources.list.d/ports-arm64.list
          echo "deb [arch=arm64] http://ports.ubuntu.com/ubuntu-ports focal-backports main restricted universe multiverse" | sudo tee -a /etc/apt/sources.list.d/ports-arm64.list
          sudo apt-get update -qq
          sudo apt-get install -yqq g++-aarch64-linux-gnu libasound2-dev:arm64 libdbus-1-dev:arm64 libgl1-mesa-dev:arm64 libglib2.0-dev:arm64 libsdl2-dev:arm64 libx11-dev:arm64 libxcursor-dev:arm64 libxext-dev:arm64 libxrandr-dev:arm64 gperf qemu-user-static
          sudo apt-get clean
      - name: Set up ccache
        uses: hendrikmuhs/ccache-action@v1.2
        with:
          key: ccache-linux-arm64-v${{ env.CACHE_VERSION }}-${{ env.WITH_LTO }}
      - name: Build extra dependencies
        env:
          PKG_CONFIG_PATH: /usr/lib/aarch64-linux-gnu/pkgconfig
        run: |
          if [ "${{ env.WITH_LTO }}" != "true" ]; then export PAWPAW_SKIP_LTO=1; fi
          ./deps/PawPaw/bootstrap-cardinal.sh linux-aarch64 && ./deps/PawPaw/.cleanup.sh linux-aarch64
      - name: Build linux arm64 cross-compiled
        run: |
          if [ "${{ env.WITH_LTO }}" != "true" ]; then export PAWPAW_SKIP_LTO=1; fi
          pushd deps/PawPaw; source local.env linux-aarch64; popd
          export PATH="/usr/lib/ccache:${PATH}"
          export PKG_CONFIG_PATH+=:/usr/lib/aarch64-linux-gnu/pkgconfig
          make features
          make CIBUILD=true HAVE_PULSEAUDIO=false NOOPT=true WITH_LTO=${{ env.WITH_LTO }} -j $(nproc)
          make unzipfx
      - name: Set sha8 (non-release)
        if: startsWith(github.ref, 'refs/tags/') != true
        run: echo "SHA8=$(echo ${{ github.sha }} | cut -c1-8)" >> $GITHUB_ENV
      - name: Set sha8 (release)
        if: startsWith(github.ref, 'refs/tags/')
        run: echo "SHA8=$(echo ${{ github.ref_name }})" >> $GITHUB_ENV
      - name: Pack binaries
        run: |
          tar -c -h --hard-dereference -z -f ${{ github.event.repository.name }}-linux-arm64-${{ github.event.pull_request.number || env.SHA8 }}.tar.gz -C bin $(ls bin | grep -e lv2 -e vst -e clap) ../CardinalJACK ../CardinalNative ../LICENSE ../README.md ../docs
      - uses: actions/upload-artifact@v3
        with:
          name: ${{ github.event.repository.name }}-linux-arm64-${{ github.event.pull_request.number || env.SHA8 }}
          path: |
            *.tar.gz
      - uses: softprops/action-gh-release@v1
        if: startsWith(github.ref, 'refs/tags/')
        with:
          tag_name: ${{ github.ref_name }}
          name: ${{ github.ref_name }}
          draft: false
          prerelease: false
          files: |
            *.tar.gz

  linux-armhf:
    runs-on: ubuntu-20.04
    steps:
      - uses: actions/checkout@v3
        with:
          submodules: recursive
      - name: Set up cache
        id: cache
        uses: actions/cache@v3
        with:
          path: |
            ~/PawPawBuilds
            src/Rack/dep/bin
            src/Rack/dep/include
            src/Rack/dep/lib
            src/Rack/dep/share
            src/Rack/dep/jansson-2.12
            src/Rack/dep/libarchive-3.4.3
            src/Rack/dep/libsamplerate-0.1.9
            src/Rack/dep/speexdsp-SpeexDSP-1.2rc3
            src/Rack/dep/zstd-1.4.5
          key: linux-armhf-v${{ env.CACHE_VERSION }}-${{ env.WITH_LTO }}
      - name: Fix GitHub's mess
        run: |
          sudo rm -f /etc/apt/sources.list.d/microsoft-prod.list
          sudo apt-get update -qq
          sudo apt-get install -yqq --allow-downgrades libpcre2-8-0/focal libpcre2-16-0/focal libpcre2-32-0/focal libpcre2-posix2/focal
          sudo apt-get clean
      - name: Set up dependencies
        run: |
          sudo dpkg --add-architecture armhf
          sudo sed -i "s/deb http/deb [arch=amd64] http/" /etc/apt/sources.list
          echo "deb [arch=armhf] http://ports.ubuntu.com/ubuntu-ports focal main restricted universe multiverse" | sudo tee /etc/apt/sources.list.d/ports-armhf.list
          echo "deb [arch=armhf] http://ports.ubuntu.com/ubuntu-ports focal-updates main restricted universe multiverse" | sudo tee -a /etc/apt/sources.list.d/ports-armhf.list
          echo "deb [arch=armhf] http://ports.ubuntu.com/ubuntu-ports focal-backports main restricted universe multiverse" | sudo tee -a /etc/apt/sources.list.d/ports-armhf.list
          sudo apt-get update -qq
          sudo apt-get install -yqq g++-arm-linux-gnueabihf libasound2-dev:armhf libdbus-1-dev:armhf libgl1-mesa-dev:armhf libglib2.0-dev:armhf libsdl2-dev:armhf libx11-dev:armhf libxcursor-dev:armhf libxext-dev:armhf libxrandr-dev:armhf gperf qemu-user-static
          sudo apt-get clean
      - name: Set up ccache
        uses: hendrikmuhs/ccache-action@v1.2
        with:
          key: ccache-linux-armhf-v${{ env.CACHE_VERSION }}-${{ env.WITH_LTO }}
      - name: Build extra dependencies
        env:
          PKG_CONFIG_PATH: /usr/lib/arm-linux-gnueabihf/pkgconfig
        run: |
          if [ "${{ env.WITH_LTO }}" != "true" ]; then export PAWPAW_SKIP_LTO=1; fi
          ./deps/PawPaw/bootstrap-cardinal.sh linux-armhf && ./deps/PawPaw/.cleanup.sh linux-armhf
      - name: Build linux armhf cross-compiled
        run: |
          if [ "${{ env.WITH_LTO }}" != "true" ]; then export PAWPAW_SKIP_LTO=1; fi
          pushd deps/PawPaw; source local.env linux-armhf; popd
          export PATH="/usr/lib/ccache:${PATH}"
          export PKG_CONFIG_PATH+=:/usr/lib/arm-linux-gnueabihf/pkgconfig
          make features
          make CIBUILD=true HAVE_PULSEAUDIO=false NOOPT=true WITH_LTO=${{ env.WITH_LTO }} -j $(nproc)
          make unzipfx
      - name: Set sha8 (non-release)
        if: startsWith(github.ref, 'refs/tags/') != true
        run: echo "SHA8=$(echo ${{ github.sha }} | cut -c1-8)" >> $GITHUB_ENV
      - name: Set sha8 (release)
        if: startsWith(github.ref, 'refs/tags/')
        run: echo "SHA8=$(echo ${{ github.ref_name }})" >> $GITHUB_ENV
      - name: Pack binaries
        run: |
          tar -c -h --hard-dereference -z -f ${{ github.event.repository.name }}-linux-armhf-${{ github.event.pull_request.number || env.SHA8 }}.tar.gz -C bin $(ls bin | grep -e lv2 -e vst -e clap) ../CardinalJACK ../CardinalNative ../LICENSE ../README.md ../docs
      - uses: actions/upload-artifact@v3
        with:
          name: ${{ github.event.repository.name }}-linux-armhf-${{ github.event.pull_request.number || env.SHA8 }}
          path: |
            *.tar.gz
      - uses: softprops/action-gh-release@v1
        if: startsWith(github.ref, 'refs/tags/')
        with:
          tag_name: ${{ github.ref_name }}
          name: ${{ github.ref_name }}
          draft: false
          prerelease: false
          files: |
            *.tar.gz

  linux-i686:
    runs-on: ubuntu-20.04
    steps:
      - uses: actions/checkout@v3
        with:
          submodules: recursive
      - name: Set up cache
        id: cache
        uses: actions/cache@v3
        with:
          path: |
            ~/PawPawBuilds
            src/Rack/dep/bin
            src/Rack/dep/include
            src/Rack/dep/lib
            src/Rack/dep/share
            src/Rack/dep/jansson-2.12
            src/Rack/dep/libarchive-3.4.3
            src/Rack/dep/libsamplerate-0.1.9
            src/Rack/dep/speexdsp-SpeexDSP-1.2rc3
            src/Rack/dep/zstd-1.4.5
          key: linux-i686-v${{ env.CACHE_VERSION }}-${{ env.WITH_LTO }}
      - name: Fix GitHub's mess
        run: |
          sudo rm -f /etc/apt/sources.list.d/microsoft-prod.list
          sudo apt-get update -qq
          sudo apt-get install -yqq --allow-downgrades libpcre2-8-0/focal libpcre2-16-0/focal libpcre2-32-0/focal libpcre2-posix2/focal
          sudo apt-get clean
      - name: Set up dependencies
        run: |
          sudo dpkg --add-architecture i386
          sudo apt-get update -qq
          sudo apt-get install -yqq g++-i686-linux-gnu libasound2-dev:i386 libdbus-1-dev:i386 libgl1-mesa-dev:i386 libglib2.0-dev:i386 libsdl2-dev:i386 libx11-dev:i386 libxcursor-dev:i386 libxext-dev:i386 libxrandr-dev:i386 gperf
          sudo apt-get clean
      - name: Set up ccache
        uses: hendrikmuhs/ccache-action@v1.2
        with:
          key: ccache-linux-i686-v${{ env.CACHE_VERSION }}-${{ env.WITH_LTO }}
      - name: Build extra dependencies
        env:
          PKG_CONFIG_PATH: /usr/lib/i386-linux-gnu/pkgconfig
        run: |
          if [ "${{ env.WITH_LTO }}" != "true" ]; then export PAWPAW_SKIP_LTO=1; fi
          ./deps/PawPaw/bootstrap-cardinal.sh linux-i686 && ./deps/PawPaw/.cleanup.sh linux-i686
      - name: Build linux i686
        run: |
          if [ "${{ env.WITH_LTO }}" != "true" ]; then export PAWPAW_SKIP_LTO=1; fi
          pushd deps/PawPaw; source local.env linux-i686; popd
          export PATH="/usr/lib/ccache:${PATH}"
          export PKG_CONFIG_PATH+=:/usr/lib/i386-linux-gnu/pkgconfig
          make features
          make CIBUILD=true HAVE_PULSEAUDIO=false NOOPT=true WITH_LTO=${{ env.WITH_LTO }} -j $(nproc)
          make unzipfx
      - name: Set sha8 (non-release)
        if: startsWith(github.ref, 'refs/tags/') != true
        run: echo "SHA8=$(echo ${{ github.sha }} | cut -c1-8)" >> $GITHUB_ENV
      - name: Set sha8 (release)
        if: startsWith(github.ref, 'refs/tags/')
        run: echo "SHA8=$(echo ${{ github.ref_name }})" >> $GITHUB_ENV
      - name: Pack binaries
        run: |
          tar -c -h --hard-dereference -z -f ${{ github.event.repository.name }}-linux-i686-${{ github.event.pull_request.number || env.SHA8 }}.tar.gz -C bin $(ls bin | grep -e lv2 -e vst -e clap) ../CardinalJACK ../CardinalNative ../LICENSE ../README.md ../docs
      - uses: actions/upload-artifact@v3
        with:
          name: ${{ github.event.repository.name }}-linux-i686-${{ github.event.pull_request.number || env.SHA8 }}
          path: |
            *.tar.gz
      - uses: softprops/action-gh-release@v1
        if: startsWith(github.ref, 'refs/tags/')
        with:
          tag_name: ${{ github.ref_name }}
          name: ${{ github.ref_name }}
          draft: false
          prerelease: false
          files: |
            *.tar.gz

  linux-riscv64:
    runs-on: ubuntu-20.04
    steps:
      - uses: actions/checkout@v3
        with:
          submodules: recursive
      - name: Set up cache
        id: cache
        uses: actions/cache@v3
        with:
          path: |
            ~/PawPawBuilds
            src/Rack/dep/bin
            src/Rack/dep/include
            src/Rack/dep/lib
            src/Rack/dep/share
            src/Rack/dep/jansson-2.12
            src/Rack/dep/libarchive-3.4.3
            src/Rack/dep/libsamplerate-0.1.9
            src/Rack/dep/speexdsp-SpeexDSP-1.2rc3
            src/Rack/dep/zstd-1.4.5
          key: linux-riscv64-v${{ env.CACHE_VERSION }}-${{ env.WITH_LTO }}
      - name: Fix GitHub's mess
        run: |
          sudo rm -f /etc/apt/sources.list.d/microsoft-prod.list
          sudo apt-get update -qq
          sudo apt-get install -yqq --allow-downgrades libgd3/focal libpcre2-8-0/focal libpcre2-16-0/focal libpcre2-32-0/focal libpcre2-posix2/focal
          sudo apt-get purge -yqq libclang* libgbm* libllvm* libmono* moby* mono* php* libgdiplus libpcre2-posix3 libzip4
          sudo apt-get clean
      - name: Set up dependencies
        run: |
          sudo dpkg --add-architecture riscv64
          sudo sed -i "s/deb http/deb [arch=amd64] http/" /etc/apt/sources.list
          echo "deb [arch=riscv64] http://ports.ubuntu.com/ubuntu-ports focal main restricted universe multiverse" | sudo tee /etc/apt/sources.list.d/ports-riscv64.list
          echo "deb [arch=riscv64] http://ports.ubuntu.com/ubuntu-ports focal-updates main restricted universe multiverse" | sudo tee -a /etc/apt/sources.list.d/ports-riscv64.list
          echo "deb [arch=riscv64] http://ports.ubuntu.com/ubuntu-ports focal-backports main restricted universe multiverse" | sudo tee -a /etc/apt/sources.list.d/ports-riscv64.list
          sudo apt-get update -qq
          sudo apt-get install -yqq g++-riscv64-linux-gnu libasound2-dev:riscv64 libdbus-1-dev:riscv64 libgl1-mesa-dev:riscv64 libglapi-mesa:riscv64 libglvnd0:riscv64 libglib2.0-dev:riscv64 libsdl2-dev:riscv64 libx11-dev:riscv64 libxcursor-dev:riscv64 libxext-dev:riscv64 libxrandr-dev:riscv64 gperf qemu-user-static
          sudo apt-get clean
      - name: Set up ccache
        uses: hendrikmuhs/ccache-action@v1.2
        with:
          key: ccache-linux-riscv64-v${{ env.CACHE_VERSION }}-${{ env.WITH_LTO }}
      - name: Build extra dependencies
        env:
          PKG_CONFIG_PATH: /usr/lib/riscv64-linux-gnu/pkgconfig
        run: |
          if [ "${{ env.WITH_LTO }}" != "true" ]; then export PAWPAW_SKIP_LTO=1; fi
          ./deps/PawPaw/bootstrap-cardinal.sh linux-riscv64 && ./deps/PawPaw/.cleanup.sh linux-riscv64
      - name: Build linux riscv64 cross-compiled
        run: |
          if [ "${{ env.WITH_LTO }}" != "true" ]; then export PAWPAW_SKIP_LTO=1; fi
          pushd deps/PawPaw; source local.env linux-riscv64; popd
          export PATH="/usr/lib/ccache:${PATH}"
          export PKG_CONFIG_PATH+=:/usr/lib/riscv64-linux-gnu/pkgconfig
          make features
          make CIBUILD=true HAVE_PULSEAUDIO=false NOOPT=true WITH_LTO=${{ env.WITH_LTO }} -j $(nproc)
          make unzipfx
      - name: Set sha8 (non-release)
        if: startsWith(github.ref, 'refs/tags/') != true
        run: echo "SHA8=$(echo ${{ github.sha }} | cut -c1-8)" >> $GITHUB_ENV
      - name: Set sha8 (release)
        if: startsWith(github.ref, 'refs/tags/')
        run: echo "SHA8=$(echo ${{ github.ref_name }})" >> $GITHUB_ENV
      - name: Pack binaries
        run: |
          tar -c -h --hard-dereference -z -f ${{ github.event.repository.name }}-linux-riscv64-${{ github.event.pull_request.number || env.SHA8 }}.tar.gz -C bin $(ls bin | grep -e lv2 -e vst -e clap) ../CardinalJACK ../CardinalNative ../LICENSE ../README.md ../docs
      - uses: actions/upload-artifact@v3
        with:
          name: ${{ github.event.repository.name }}-linux-riscv64-${{ github.event.pull_request.number || env.SHA8 }}
          path: |
            *.tar.gz
      - uses: softprops/action-gh-release@v1
        if: startsWith(github.ref, 'refs/tags/')
        with:
          tag_name: ${{ github.ref_name }}
          name: ${{ github.ref_name }}
          draft: false
          prerelease: false
          files: |
            *.tar.gz

  linux-x86_64:
    runs-on: ubuntu-20.04
    steps:
      - uses: actions/checkout@v3
        with:
          submodules: recursive
      - name: Set up cache
        id: cache
        uses: actions/cache@v3
        with:
          path: |
            ~/PawPawBuilds
            src/Rack/dep/bin
            src/Rack/dep/include
            src/Rack/dep/lib
            src/Rack/dep/share
            src/Rack/dep/jansson-2.12
            src/Rack/dep/libarchive-3.4.3
            src/Rack/dep/libsamplerate-0.1.9
            src/Rack/dep/speexdsp-SpeexDSP-1.2rc3
            src/Rack/dep/zstd-1.4.5
          key: linux-x86_64-v${{ env.CACHE_VERSION }}-${{ env.WITH_LTO }}
      - name: Set up dependencies
        run: |
          sudo apt-get update -qq
          sudo apt-get install -yqq libasound2-dev libdbus-1-dev libgl1-mesa-dev libglib2.0-dev libsdl2-dev libx11-dev libxcursor-dev libxext-dev libxrandr-dev gperf
          sudo apt-get clean
      - name: Set up ccache
        uses: hendrikmuhs/ccache-action@v1.2
        with:
          key: ccache-linux-x86_64-v${{ env.CACHE_VERSION }}-${{ env.WITH_LTO }}
      - name: Build extra dependencies
        run: |
          if [ "${{ env.WITH_LTO }}" != "true" ]; then export PAWPAW_SKIP_LTO=1; fi
          ./deps/PawPaw/bootstrap-cardinal.sh linux && ./deps/PawPaw/.cleanup.sh linux
      - name: Build linux x86_64
        run: |
          if [ "${{ env.WITH_LTO }}" != "true" ]; then export PAWPAW_SKIP_LTO=1; fi
          pushd deps/PawPaw; source local.env linux; popd
          export PATH="/usr/lib/ccache:${PATH}"
          export PKG_CONFIG_PATH+=:/usr/lib/x86_64-linux-gnu/pkgconfig
          make features
          make CIBUILD=true HAVE_PULSEAUDIO=false NOOPT=true WITH_LTO=${{ env.WITH_LTO }} -j $(nproc)
          make unzipfx
      - name: Set sha8 (non-release)
        if: startsWith(github.ref, 'refs/tags/') != true
        run: echo "SHA8=$(echo ${{ github.sha }} | cut -c1-8)" >> $GITHUB_ENV
      - name: Set sha8 (release)
        if: startsWith(github.ref, 'refs/tags/')
        run: echo "SHA8=$(echo ${{ github.ref_name }})" >> $GITHUB_ENV
      - name: Pack binaries
        run: |
          tar -c -h --hard-dereference -z -f ${{ github.event.repository.name }}-linux-x86_64-${{ github.event.pull_request.number || env.SHA8 }}.tar.gz -C bin $(ls bin | grep -e lv2 -e vst -e clap) ../CardinalJACK ../CardinalNative ../LICENSE ../README.md ../docs
      - uses: actions/upload-artifact@v3
        with:
          name: ${{ github.event.repository.name }}-linux-x86_64-${{ github.event.pull_request.number || env.SHA8 }}
          path: |
            *.tar.gz
      - uses: softprops/action-gh-release@v1
        if: startsWith(github.ref, 'refs/tags/')
        with:
          tag_name: ${{ github.ref_name }}
          name: ${{ github.ref_name }}
          draft: false
          prerelease: false
          files: |
            *.tar.gz

  linux-x86_64-debug:
    runs-on: ubuntu-20.04
    steps:
      - uses: actions/checkout@v3
        with:
          submodules: recursive
      - name: Set up dependencies
        run: |
          sudo apt-get update -qq
          sudo apt-get install -yqq libasound2-dev libdbus-1-dev libgl1-mesa-dev liblo-dev libsdl2-dev libx11-dev libxcursor-dev libxext-dev libxrandr-dev gperf
          sudo apt-get clean
      - name: Build linux x86_64 (debug)
        env:
          LDFLAGS: -static-libgcc -static-libstdc++
        run: |
          make features
          # multiple jobs for building carla, deps and plugins
          make DEBUG=true carla deps dgl plugins resources -j $(nproc)
          # single job for final build stage, otherwise we might killed due to OOM
          make DEBUG=true HAVE_PULSEAUDIO=false -j 1
      - name: Set sha8
        id: slug
        run: echo "SHA8=$(echo ${{ github.sha }} | cut -c1-8)" >> $GITHUB_ENV
      - name: Pack binaries
        run: |
          tar -c -h --hard-dereference -z -f ${{ github.event.repository.name }}-linux-x86_64-debug-${{ github.event.pull_request.number || env.SHA8 }}.tar.gz -C bin $(ls bin | grep -e lv2 -e vst -e clap) ../LICENSE ../README.md ../docs
      - uses: actions/upload-artifact@v3
        with:
          name: ${{ github.event.repository.name }}-linux-x86_64-debug-${{ github.event.pull_request.number || env.SHA8 }}
          path: |
            *.tar.gz

  linux-x86_64-headless:
    runs-on: ubuntu-20.04
    steps:
      - uses: actions/checkout@v3
        with:
          submodules: recursive
      - name: Set up dependencies
        run: |
          sudo apt-get update -qq
          sudo apt-get remove -yqq libcairo2-dev libx11-dev libx11-dev libxext-dev
          sudo apt-get install -yqq liblo-dev
          sudo apt-get clean
      - name: Build linux x86_64 (headless)
        run: |
          make HEADLESS=true features
          make HEADLESS=true -j $(nproc)

  linux-x86_64-sysdeps:
    runs-on: ubuntu-20.04
    steps:
      - uses: actions/checkout@v3
        with:
          submodules: recursive
      - name: Set up dependencies
        run: |
          sudo apt-get update -qq
          sudo apt-get install -yqq libdbus-1-dev libgl1-mesa-dev liblo-dev libx11-dev libxcursor-dev libxext-dev libxrandr-dev libarchive-dev libfftw3-dev libjansson-dev libsamplerate0-dev libsndfile1-dev libspeexdsp-dev
          sudo apt-get clean
      - name: Build linux x86_64 (sysdeps)
        run: |
          make features
          make SYSDEPS=true -j $(nproc)

  macos-intel:
    runs-on: macos-11
    steps:
      - uses: actions/checkout@v3
        with:
          submodules: recursive
      - name: Set up cache
        id: cache
        uses: actions/cache@v3
        with:
          path: |
            ~/PawPawBuilds
            src/Rack/dep/bin
            src/Rack/dep/include
            src/Rack/dep/lib
            src/Rack/dep/share
            src/Rack/dep/jansson-2.12
            src/Rack/dep/libarchive-3.4.3
            src/Rack/dep/libsamplerate-0.1.9
            src/Rack/dep/speexdsp-SpeexDSP-1.2rc3
            src/Rack/dep/zstd-1.4.5
          key: macos-intel-v${{ env.CACHE_VERSION }}-${{ env.WITH_LTO }}
      - name: Build extra dependencies
        run: |
          if [ "${{ env.WITH_LTO }}" != "true" ]; then export PAWPAW_SKIP_LTO=1; fi
          export PATH="/usr/local/opt/ccache/libexec:${PATH}"
          ./deps/PawPaw/bootstrap-cardinal.sh macos && ./deps/PawPaw/.cleanup.sh macos
      - name: Set up ccache
        if: steps.cache.outputs.cache-hit == 'true'
        uses: hendrikmuhs/ccache-action@v1.2
        with:
          key: ccache-macos-intel-v${{ env.CACHE_VERSION }}-${{ env.WITH_LTO }}
      - name: Build macOS intel (base)
        if: steps.cache.outputs.cache-hit == 'true'
        run: |
          if [ "${{ env.WITH_LTO }}" != "true" ]; then export PAWPAW_SKIP_LTO=1; fi
          export PATH="/usr/local/opt/ccache/libexec:${PATH}"
          pushd deps/PawPaw; source local.env macos; popd
          make features
          make CIBUILD=true NOOPT=true WITH_LTO=${{ env.WITH_LTO }} -j $(sysctl -n hw.logicalcpu)
      - name: Build macOS intel (AU using juce)
        if: steps.cache.outputs.cache-hit == 'true'
        run: |
          if [ "${{ env.WITH_LTO }}" != "true" ]; then export PAWPAW_SKIP_LTO=1; fi
          pushd deps/PawPaw; source local.env macos; popd
          git clone --depth=1 -b 6.1.6 https://github.com/juce-framework/JUCE.git jucewrapper/JUCE
          sed -i -e 's/kAudioUnitProperty_SupportsMPE/kAudioUnitProperty_ignore_SupportsMPE/' jucewrapper/JUCE/modules/juce_audio_processors/format_types/juce_AudioUnitPluginFormat.h
          mkdir -p jucewrapper/build
          pushd jucewrapper/build; cmake -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_OSX_ARCHITECTURES=x86_64 -DCMAKE_OSX_DEPLOYMENT_TARGET=10.8 -DCMAKE_OSX_SYSROOT="macosx" -DCMAKE_BUILD_TYPE=Release .. && make VERBOSE=1 -j $(sysctl -n hw.logicalcpu); popd
          mv jucewrapper/build/*_artefacts/Release/AU/*.component bin/
      - name: Build macOS intel (packaging)
        if: steps.cache.outputs.cache-hit == 'true'
        env:
          MACOS_ARCHS: 'x86_64'
        run: |
          pushd deps/PawPaw; source local.env macos; popd
          ./utils/create-macos-installer.sh
      - name: Set sha8 (non-release)
        if: startsWith(github.ref, 'refs/tags/') != true
        run: echo "SHA8=$(echo ${{ github.sha }} | cut -c1-8)" >> $GITHUB_ENV
      - name: Set sha8 (release)
        if: startsWith(github.ref, 'refs/tags/')
        run: echo "SHA8=$(echo ${{ github.ref_name }})" >> $GITHUB_ENV
      - name: Rename macOS bundle
        if: steps.cache.outputs.cache-hit == 'true'
        run: |
          mv ${{ github.event.repository.name }}-macOS.pkg ${{ github.event.repository.name }}-macOS-intel-${{ github.event.pull_request.number || env.SHA8 }}.pkg
      - uses: actions/upload-artifact@v3
        with:
          name: ${{ github.event.repository.name }}-macOS-intel-${{ github.event.pull_request.number || env.SHA8 }}
          path: |
            ${{ github.event.repository.name }}-*.pkg
      - uses: softprops/action-gh-release@v1
        if: startsWith(github.ref, 'refs/tags/')
        with:
          tag_name: ${{ github.ref_name }}
          name: ${{ github.ref_name }}
          draft: false
          prerelease: false
          files: |
            ${{ github.event.repository.name }}-*.pkg

  macos-universal:
    runs-on: macos-11
    steps:
      - uses: actions/checkout@v3
        with:
          submodules: recursive
      - name: Set up cache
        id: cache
        uses: actions/cache@v3
        with:
          path: |
            ~/PawPawBuilds
            src/Rack/dep/bin
            src/Rack/dep/include
            src/Rack/dep/lib
            src/Rack/dep/share
            src/Rack/dep/jansson-2.12
            src/Rack/dep/libarchive-3.4.3
            src/Rack/dep/libsamplerate-0.1.9
            src/Rack/dep/speexdsp-SpeexDSP-1.2rc3
            src/Rack/dep/zstd-1.4.5
          key: macos-universal-v${{ env.CACHE_VERSION }}
      - name: Build extra dependencies
        run: |
          export PAWPAW_SKIP_LTO=1
          export PATH="/usr/local/opt/ccache/libexec:${PATH}"
          ./deps/PawPaw/bootstrap-cardinal.sh macos-universal && ./deps/PawPaw/.cleanup.sh macos-universal
      - name: Set up ccache
        if: steps.cache.outputs.cache-hit == 'true'
        uses: hendrikmuhs/ccache-action@v1.2
        with:
          key: ccache-macos-universal-v${{ env.CACHE_VERSION }}
      - name: Build macOS universal (base)
        if: steps.cache.outputs.cache-hit == 'true'
        env:
          WITH_LTO: 'false'
        run: |
          export PAWPAW_SKIP_LTO=1
          export PATH="/usr/local/opt/ccache/libexec:${PATH}"
          pushd deps/PawPaw; source local.env macos-universal; popd
          make features
          make CIBUILD=true NOOPT=true -j $(sysctl -n hw.logicalcpu)
      - name: Build macOS universal (AU using juce)
        if: steps.cache.outputs.cache-hit == 'true'
        run: |
          export PAWPAW_SKIP_LTO=1
          pushd deps/PawPaw; source local.env macos-universal; popd
          git clone --depth=1 -b 6.1.6 https://github.com/juce-framework/JUCE.git jucewrapper/JUCE
          mkdir -p jucewrapper/build
          pushd jucewrapper/build; cmake -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_OSX_ARCHITECTURES='arm64;x86_64' -DCMAKE_OSX_DEPLOYMENT_TARGET=10.12 -DCMAKE_OSX_SYSROOT="macosx" -DCMAKE_BUILD_TYPE=Release .. && make VERBOSE=1 -j $(sysctl -n hw.logicalcpu); popd
          mv jucewrapper/build/*_artefacts/Release/AU/*.component bin/
      - name: Build macOS universal (packaging)
        if: steps.cache.outputs.cache-hit == 'true'
        env:
          MACOS_ARCHS: 'arm64,x86_64'
        run: |
          pushd deps/PawPaw; source local.env macos-universal; popd
          ./utils/create-macos-installer.sh
      - name: Set sha8 (non-release)
        if: startsWith(github.ref, 'refs/tags/') != true
        run: echo "SHA8=$(echo ${{ github.sha }} | cut -c1-8)" >> $GITHUB_ENV
      - name: Set sha8 (release)
        if: startsWith(github.ref, 'refs/tags/')
        run: echo "SHA8=$(echo ${{ github.ref_name }})" >> $GITHUB_ENV
      - name: Rename macOS bundle
        if: steps.cache.outputs.cache-hit == 'true'
        run: |
          mv ${{ github.event.repository.name }}-macOS.pkg ${{ github.event.repository.name }}-macOS-universal-${{ github.event.pull_request.number || env.SHA8 }}.pkg
      - uses: actions/upload-artifact@v3
        with:
          name: ${{ github.event.repository.name }}-macOS-universal-${{ github.event.pull_request.number || env.SHA8 }}
          path: |
            ${{ github.event.repository.name }}-*.pkg
      - uses: softprops/action-gh-release@v1
        if: startsWith(github.ref, 'refs/tags/')
        with:
          tag_name: ${{ github.ref_name }}
          name: ${{ github.ref_name }}
          draft: false
          prerelease: false
          files: |
            ${{ github.event.repository.name }}-*.pkg

  modduo:
    runs-on: ubuntu-20.04
    steps:
      - uses: actions/checkout@v3
        with:
          submodules: recursive
      - name: Set up cache
        uses: actions/cache@v3
        id: mpb-cache
        with:
          path: |
            ~/mod-workdir
          key: modduo-static-v${{ env.CACHE_VERSION }}-${{ env.WITH_LTO }}
      - name: Set up dependencies
        run: |
          sudo apt-get update -qq
          sudo apt-get install -yqq acl bc curl cvs git mercurial rsync subversion wget bison bzip2 flex gawk gperf gzip help2man nano perl patch tar texinfo unzip automake binutils build-essential cpio libtool libncurses-dev pkg-config python libtool-bin liblo-dev qemu-user-static
          sudo apt-get install -yqq pandoc texlive-latex-recommended texlive-latex-extra
          sudo apt-get clean
      - name: Bootstrap toolchain
        if: steps.mpb-cache.outputs.cache-hit != 'true'
        run: |
          git clone --depth=1 https://github.com/moddevices/mod-plugin-builder.git deps/mod-plugin-builder
          sed -i "s/CT_LOG_PROGRESS_BAR=y/CT_LOG_PROGRESS_BAR=n/" deps/mod-plugin-builder/toolchain/*.config
          $(pwd)/deps/mod-plugin-builder/bootstrap.sh modduo-static minimal && $(pwd)/deps/mod-plugin-builder/.clean-install.sh modduo-static
      - name: Build for modduo
        if: steps.mpb-cache.outputs.cache-hit == 'true'
        run: |
          make modduo HEADLESS=true WITH_LTO=${{ env.WITH_LTO }} MODDUO=true -j $(nproc)
      - name: Set sha8
        id: slug
        run: echo "SHA8=$(echo ${{ github.sha }} | cut -c1-8)" >> $GITHUB_ENV
      - name: Pack binaries
        if: steps.mpb-cache.outputs.cache-hit == 'true'
        run: |
          tar -c -h --hard-dereference -z -f ${{ github.event.repository.name }}-modduo-${{ github.event.pull_request.number || env.SHA8 }}.tar.gz -C bin $(ls bin | grep lv2)
      - uses: actions/upload-artifact@v3
        with:
          name: ${{ github.event.repository.name }}-modduo-${{ github.event.pull_request.number || env.SHA8 }}
          path: |
            *.tar.gz

  modduox:
    runs-on: ubuntu-20.04
    steps:
      - uses: actions/checkout@v3
        with:
          submodules: recursive
      - name: Set up cache
        uses: actions/cache@v3
        id: mpb-cache
        with:
          path: |
            ~/mod-workdir
          key: modduox-v${{ env.CACHE_VERSION }}-${{ env.WITH_LTO }}
      - name: Set up dependencies
        run: |
          sudo apt-get update -qq
          sudo apt-get install -yqq acl bc curl cvs git mercurial rsync subversion wget bison bzip2 flex gawk gperf gzip help2man nano perl patch tar texinfo unzip automake binutils build-essential cpio libtool libncurses-dev pkg-config python libtool-bin liblo-dev qemu-user-static
          sudo apt-get install -yqq pandoc texlive-latex-recommended texlive-latex-extra
          sudo apt-get clean
      - name: Bootstrap toolchain
        if: steps.mpb-cache.outputs.cache-hit != 'true'
        run: |
          git clone --depth=1 https://github.com/moddevices/mod-plugin-builder.git deps/mod-plugin-builder
          sed -i "s/CT_LOG_PROGRESS_BAR=y/CT_LOG_PROGRESS_BAR=n/" deps/mod-plugin-builder/toolchain/*.config
          $(pwd)/deps/mod-plugin-builder/bootstrap.sh modduox-static minimal && $(pwd)/deps/mod-plugin-builder/.clean-install.sh modduox-static
      - name: Build for modduox
        if: steps.mpb-cache.outputs.cache-hit == 'true'
        run: |
          make modduox HEADLESS=true WITH_LTO=${{ env.WITH_LTO }} -j $(nproc)
      - name: Set sha8
        id: slug
        run: echo "SHA8=$(echo ${{ github.sha }} | cut -c1-8)" >> $GITHUB_ENV
      - name: Pack binaries
        if: steps.mpb-cache.outputs.cache-hit == 'true'
        run: |
          tar -c -h --hard-dereference -z -f ${{ github.event.repository.name }}-modduox-${{ github.event.pull_request.number || env.SHA8 }}.tar.gz -C bin $(ls bin | grep lv2)
      - uses: actions/upload-artifact@v3
        with:
          name: ${{ github.event.repository.name }}-modduox-${{ github.event.pull_request.number || env.SHA8 }}
          path: |
            *.tar.gz

  moddwarf:
    runs-on: ubuntu-20.04
    steps:
      - uses: actions/checkout@v3
        with:
          submodules: recursive
      - name: Set up cache
        uses: actions/cache@v3
        id: mpb-cache
        with:
          path: |
            ~/mod-workdir
          key: moddwarf-v${{ env.CACHE_VERSION }}-${{ env.WITH_LTO }}
      - name: Set up dependencies
        run: |
          sudo apt-get update -qq
          sudo apt-get install -yqq acl bc curl cvs git mercurial rsync subversion wget bison bzip2 flex gawk gperf gzip help2man nano perl patch tar texinfo unzip automake binutils build-essential cpio libtool libncurses-dev pkg-config python libtool-bin liblo-dev qemu-user-static
          sudo apt-get install -yqq pandoc texlive-latex-recommended texlive-latex-extra
          sudo apt-get clean
      - name: Bootstrap toolchain
        if: steps.mpb-cache.outputs.cache-hit != 'true'
        run: |
          git clone --depth=1 https://github.com/moddevices/mod-plugin-builder.git deps/mod-plugin-builder
          sed -i "s/CT_LOG_PROGRESS_BAR=y/CT_LOG_PROGRESS_BAR=n/" deps/mod-plugin-builder/toolchain/*.config
          $(pwd)/deps/mod-plugin-builder/bootstrap.sh moddwarf minimal && $(pwd)/deps/mod-plugin-builder/.clean-install.sh moddwarf
      - name: Build for moddwarf
        if: steps.mpb-cache.outputs.cache-hit == 'true'
        run: |
          make moddwarf HEADLESS=true WITH_LTO=${{ env.WITH_LTO }} -j $(nproc)
      - name: Set sha8
        id: slug
        run: echo "SHA8=$(echo ${{ github.sha }} | cut -c1-8)" >> $GITHUB_ENV
      - name: Pack binaries
        if: steps.mpb-cache.outputs.cache-hit == 'true'
        run: |
          tar -c -h --hard-dereference -z -f ${{ github.event.repository.name }}-moddwarf-${{ github.event.pull_request.number || env.SHA8 }}.tar.gz -C bin $(ls bin | grep lv2)
      - uses: actions/upload-artifact@v3
        with:
          name: ${{ github.event.repository.name }}-moddwarf-${{ github.event.pull_request.number || env.SHA8 }}
          path: |
            *.tar.gz

  wasm:
    runs-on: ubuntu-22.04
    steps:
      - uses: actions/checkout@v3
        with:
          submodules: recursive
      - name: Set up cache
        id: cache
        uses: actions/cache@v3
        with:
          path: |
            ~/PawPawBuilds
            src/Rack/dep/bin
            src/Rack/dep/include
            src/Rack/dep/lib
            src/Rack/dep/share
            src/Rack/dep/jansson-2.12
            src/Rack/dep/libarchive-3.4.3
            src/Rack/dep/libsamplerate-0.1.9
            src/Rack/dep/speexdsp-SpeexDSP-1.2rc3
            src/Rack/dep/zstd-1.4.5
          key: wasm-v${{ env.CACHE_VERSION }}
      - name: Set up dependencies
        run: |
          sudo apt-get update -qq
          sudo apt-get install -yqq brotli gperf
          sudo apt-get clean
          [ -e ~/PawPawBuilds/emsdk ] || git clone https://github.com/emscripten-core/emsdk.git ~/PawPawBuilds/emsdk
          cd ~/PawPawBuilds/emsdk && ./emsdk install ${{ env.EMSCRIPTEN_VERSION }} && ./emsdk activate ${{ env.EMSCRIPTEN_VERSION }}
      - name: Build extra dependencies
        run: |
          source ~/PawPawBuilds/emsdk/emsdk_env.sh
          ./deps/PawPaw/bootstrap-cardinal.sh wasm && ./deps/PawPaw/.cleanup.sh wasm
      - name: Build wasm cross-compiled
        if: steps.cache.outputs.cache-hit == 'true'
        env:
          WITH_LTO: 'false'
        run: |
          source ~/PawPawBuilds/emsdk/emsdk_env.sh
          pushd deps/PawPaw; source local.env wasm; popd
          make features
          make CIBUILD=true HAVE_LIBLO=false NOOPT=true USE_GLES2=true -j $(nproc)
      - name: Make wasm versioned and compress
        if: steps.cache.outputs.cache-hit == 'true'
        run: |
          VERSION=$(cat Makefile | awk 'sub("VERSION = ","")')
          cd bin
          rm -r *.lv2
          sed -i "s/CardinalNative\./CardinalNative-v${VERSION}\./g" *.html *.js
          mv CardinalNative.data CardinalNative-v${VERSION}.data
          mv CardinalNative.js   CardinalNative-v${VERSION}.js
          mv CardinalNative.wasm CardinalNative-v${VERSION}.wasm
          brotli -k -q 11 *.*
      - name: Set sha8 (non-release)
        if: startsWith(github.ref, 'refs/tags/') != true
        run: echo "SHA8=$(echo ${{ github.sha }} | cut -c1-8)" >> $GITHUB_ENV
      - name: Set sha8 (release)
        if: startsWith(github.ref, 'refs/tags/')
        run: echo "SHA8=$(echo ${{ github.ref_name }})" >> $GITHUB_ENV
      - name: Pack binaries
        if: steps.cache.outputs.cache-hit == 'true'
        run: |
          cd bin; zip -r -9 ../${{ github.event.repository.name }}-wasm-${{ github.event.pull_request.number || env.SHA8 }}.zip $(ls *.br *.html *.data *.js *.wasm)
      - uses: actions/upload-artifact@v3
        with:
          name: ${{ github.event.repository.name }}-wasm-${{ github.event.pull_request.number || env.SHA8 }}
          path: |
            *.zip
      - uses: softprops/action-gh-release@v1
        if: startsWith(github.ref, 'refs/tags/')
        with:
          tag_name: ${{ github.ref_name }}
          name: ${{ github.ref_name }}
          draft: false
          prerelease: false
          files: |
            *.zip

  wasm-mini:
    runs-on: ubuntu-22.04
    steps:
      - uses: actions/checkout@v3
        with:
          submodules: recursive
      - name: Set up cache
        id: cache
        uses: actions/cache@v3
        with:
          path: |
            ~/emsdk
            src/Rack/dep/bin
            src/Rack/dep/include
            src/Rack/dep/lib
            src/Rack/dep/share
            src/Rack/dep/jansson-2.12
            src/Rack/dep/libarchive-3.4.3
            src/Rack/dep/libsamplerate-0.1.9
            src/Rack/dep/speexdsp-SpeexDSP-1.2rc3
            src/Rack/dep/zstd-1.4.5
          key: wasm-mini-v${{ env.CACHE_VERSION }}
      - name: Set up dependencies
        run: |
          sudo apt-get update -qq
          sudo apt-get install -yqq brotli
          sudo apt-get clean
          [ -e ~/emsdk ] || git clone https://github.com/emscripten-core/emsdk.git ~/emsdk
          cd ~/emsdk && ./emsdk install ${{ env.EMSCRIPTEN_VERSION }} && ./emsdk activate ${{ env.EMSCRIPTEN_VERSION }}
      - name: Build wasm-mini cross-compiled
        env:
          AR: emar
          CC: emcc
          CXX: em++
          NM: emnm
          RANLIB: emranlib
          STRIP: emstrip
          WITH_LTO: 'false'
        run: |
          source ~/emsdk/emsdk_env.sh
          make features
          make CIBUILD=true NOPLUGINS=true STATIC_BUILD=true USE_GLES2=true -j $(nproc)
      - name: Make wasm versioned and compress
        run: |
          VERSION=$(cat Makefile | awk 'sub("VERSION = ","")')
          cd bin
          rm -r *.lv2
          sed -i "s/CardinalNative\./CardinalNative-v${VERSION}\./g" *.html *.js
          mv CardinalNative.data CardinalNative-v${VERSION}.data
          mv CardinalNative.js   CardinalNative-v${VERSION}.js
          mv CardinalNative.wasm CardinalNative-v${VERSION}.wasm
          brotli -k -q 11 *.*
      - name: Set sha8 (non-release)
        if: startsWith(github.ref, 'refs/tags/') != true
        run: echo "SHA8=$(echo ${{ github.sha }} | cut -c1-8)" >> $GITHUB_ENV
      - name: Set sha8 (release)
        if: startsWith(github.ref, 'refs/tags/')
        run: echo "SHA8=$(echo ${{ github.ref_name }})" >> $GITHUB_ENV
      - name: Pack binaries
        run: |
          cd bin; zip -r -9 ../${{ github.event.repository.name }}-wasm-mini-${{ github.event.pull_request.number || env.SHA8 }}.zip $(ls *.br *.html *.data *.js *.wasm)
      - uses: actions/upload-artifact@v3
        with:
          name: ${{ github.event.repository.name }}-wasm-mini-${{ github.event.pull_request.number || env.SHA8 }}
          path: |
            *.zip
      - uses: softprops/action-gh-release@v1
        if: startsWith(github.ref, 'refs/tags/')
        with:
          tag_name: ${{ github.ref_name }}
          name: ${{ github.ref_name }}
          draft: false
          prerelease: false
          files: |
            *.zip

  win32:
    runs-on: ubuntu-22.04
    steps:
      - uses: actions/checkout@v3
        with:
          submodules: recursive
      - name: Set up cache
        id: cache
        uses: actions/cache@v3
        with:
          path: |
            ~/PawPawBuilds
            src/Rack/dep/bin
            src/Rack/dep/include
            src/Rack/dep/lib
            src/Rack/dep/share
            src/Rack/dep/jansson-2.12
            src/Rack/dep/libarchive-3.4.3
            src/Rack/dep/libsamplerate-0.1.9
            src/Rack/dep/speexdsp-SpeexDSP-1.2rc3
            src/Rack/dep/zstd-1.4.5
          key: win32-v${{ env.CACHE_VERSION }}-${{ env.WITH_LTO }}
      - name: Fix GitHub's mess
        run: |
          sudo rm -f /etc/apt/sources.list.d/microsoft-prod.list
          sudo apt-get update -qq
          sudo apt-get install -yqq --allow-downgrades libgd3/jammy
          sudo apt-get purge -yqq libmono* moby* mono* msbuild* php* libgdiplus libpcre2-posix3 nuget
          sudo apt-get clean
      - name: Set up dependencies
        run: |
          sudo dpkg --add-architecture i386
          sudo apt-get update -qq
          sudo apt-get install -yqq binutils-mingw-w64-i686 g++-mingw-w64-i686 mingw-w64 wine-stable:i386 gperf qttools5-dev qttools5-dev-tools xvfb
          sudo apt-get clean
      - name: Set up ccache
        uses: hendrikmuhs/ccache-action@v1.2
        with:
          key: ccache-win32-v${{ env.CACHE_VERSION }}-${{ env.WITH_LTO }}
      - name: Build extra dependencies
        run: |
          if [ "${{ env.WITH_LTO }}" != "true" ]; then export PAWPAW_SKIP_LTO=1; fi
          ./deps/PawPaw/bootstrap-cardinal.sh win32 && ./deps/PawPaw/.cleanup.sh win32
      - name: Build win32 cross-compiled (base)
        if: steps.cache.outputs.cache-hit == 'true'
        run: |
          if [ "${{ env.WITH_LTO }}" != "true" ]; then export PAWPAW_SKIP_LTO=1; fi
          export PATH="/usr/lib/ccache:${PATH}"
          pushd deps/PawPaw; source local.env win32; popd
          make features
          make CIBUILD=true NOOPT=true WITH_LTO=${{ env.WITH_LTO }} -j $(nproc)
      - name: Build win32 cross-compiled (carla)
        if: steps.cache.outputs.cache-hit == 'true'
        run: |
          if [ "${{ env.WITH_LTO }}" != "true" ]; then export PAWPAW_SKIP_LTO=1; fi
          export PATH="/usr/lib/ccache:${PATH}"
          pushd deps/PawPaw; source local.env win32; popd
          make carla-win32 -j $(nproc)
          make -C carla EMBED_TARGET=true TESTING=true dist
          make -C carla EMBED_TARGET=true TESTING=true dist
      - name: Build win32 cross-compiled (packaging)
        if: steps.cache.outputs.cache-hit == 'true'
        run: |
          pushd deps/PawPaw; source local.env win32; popd
          xvfb-run ./utils/create-windows-installer.sh 32
          make unzipfx
      - name: Set sha8 (non-release)
        if: startsWith(github.ref, 'refs/tags/') != true
        run: echo "SHA8=$(echo ${{ github.sha }} | cut -c1-8)" >> $GITHUB_ENV
      - name: Set sha8 (release)
        if: startsWith(github.ref, 'refs/tags/')
        run: echo "SHA8=$(echo ${{ github.ref_name }})" >> $GITHUB_ENV
      - name: Pack binaries
        if: steps.cache.outputs.cache-hit == 'true'
        run: |
          pushd bin
          zip -r -9 ../${{ github.event.repository.name }}-win32-${{ github.event.pull_request.number || env.SHA8 }}.zip $(ls | grep -e lv2 -e vst -e clap)
          popd
          zip -u -9 ${{ github.event.repository.name }}-win32-${{ github.event.pull_request.number || env.SHA8 }}.zip LICENSE README.md docs/*.* CardinalJACK.exe CardinalNative.exe
      - uses: actions/upload-artifact@v3
        with:
          name: ${{ github.event.repository.name }}-win32-${{ github.event.pull_request.number || env.SHA8 }}
          path: |
            Cardinal-*.exe
            Cardinal-*.zip
      - uses: softprops/action-gh-release@v1
        if: startsWith(github.ref, 'refs/tags/')
        with:
          tag_name: ${{ github.ref_name }}
          name: ${{ github.ref_name }}
          draft: false
          prerelease: false
          files: |
            Cardinal-*.exe
            Cardinal-*.zip

  win64:
    runs-on: ubuntu-22.04
    steps:
      - uses: actions/checkout@v3
        with:
          submodules: recursive
      - name: Set up cache
        id: cache
        uses: actions/cache@v3
        with:
          path: |
            ~/PawPawBuilds
            src/Rack/dep/bin
            src/Rack/dep/include
            src/Rack/dep/lib
            src/Rack/dep/share
            src/Rack/dep/jansson-2.12
            src/Rack/dep/libarchive-3.4.3
            src/Rack/dep/libsamplerate-0.1.9
            src/Rack/dep/speexdsp-SpeexDSP-1.2rc3
            src/Rack/dep/zstd-1.4.5
          key: win64-v${{ env.CACHE_VERSION }}-${{ env.WITH_LTO }}
      - name: Fix GitHub's mess
        run: |
          sudo rm -f /etc/apt/sources.list.d/microsoft-prod.list
          sudo apt-get update -qq
          sudo apt-get install -yqq --allow-downgrades libgd3/jammy
          sudo apt-get purge -yqq libmono* moby* mono* msbuild* php* libgdiplus libpcre2-posix3 nuget
          sudo apt-get clean
      - name: Set up dependencies
        run: |
          sudo dpkg --add-architecture i386
          sudo apt-get update -qq
          sudo apt-get install -yqq binutils-mingw-w64-x86-64 g++-mingw-w64-x86-64 mingw-w64 wine-stable gperf qttools5-dev qttools5-dev-tools xvfb
          sudo apt-get clean
      - name: Set up ccache
        uses: hendrikmuhs/ccache-action@v1.2
        with:
          key: ccache-win64-v${{ env.CACHE_VERSION }}-${{ env.WITH_LTO }}
      - name: Build extra dependencies
        run: |
          if [ "${{ env.WITH_LTO }}" != "true" ]; then export PAWPAW_SKIP_LTO=1; fi
          ./deps/PawPaw/bootstrap-cardinal.sh win64 && ./deps/PawPaw/.cleanup.sh win64
      - name: Build win64 cross-compiled (base)
        if: steps.cache.outputs.cache-hit == 'true'
        run: |
          if [ "${{ env.WITH_LTO }}" != "true" ]; then export PAWPAW_SKIP_LTO=1; fi
          export PATH="/usr/lib/ccache:${PATH}"
          pushd deps/PawPaw; source local.env win64; popd
          make features
          make CIBUILD=true NOOPT=true WITH_LTO=${{ env.WITH_LTO }} -j $(nproc)
      - name: Build win64 cross-compiled (carla)
        if: steps.cache.outputs.cache-hit == 'true'
        run: |
          if [ "${{ env.WITH_LTO }}" != "true" ]; then export PAWPAW_SKIP_LTO=1; fi
          export PATH="/usr/lib/ccache:${PATH}"
          pushd deps/PawPaw; source local.env win64; popd
          make carla-win32 -j $(nproc)
          make -C carla EMBED_TARGET=true TESTING=true dist
          make -C carla EMBED_TARGET=true TESTING=true dist
      - name: Build win64 cross-compiled (packaging)
        if: steps.cache.outputs.cache-hit == 'true'
        run: |
          pushd deps/PawPaw; source local.env win64; popd
          xvfb-run ./utils/create-windows-installer.sh 64
          make unzipfx
      - name: Set sha8 (non-release)
        if: startsWith(github.ref, 'refs/tags/') != true
        run: echo "SHA8=$(echo ${{ github.sha }} | cut -c1-8)" >> $GITHUB_ENV
      - name: Set sha8 (release)
        if: startsWith(github.ref, 'refs/tags/')
        run: echo "SHA8=$(echo ${{ github.ref_name }})" >> $GITHUB_ENV
      - name: Pack binaries
        if: steps.cache.outputs.cache-hit == 'true'
        run: |
          pushd bin
          zip -r -9 ../${{ github.event.repository.name }}-win64-${{ github.event.pull_request.number || env.SHA8 }}.zip $(ls | grep -e lv2 -e vst -e clap)
          popd
          zip -u -9 ${{ github.event.repository.name }}-win64-${{ github.event.pull_request.number || env.SHA8 }}.zip LICENSE README.md docs/*.* CardinalJACK.exe CardinalNative.exe
      - uses: actions/upload-artifact@v3
        with:
          name: ${{ github.event.repository.name }}-win64-${{ github.event.pull_request.number || env.SHA8 }}
          path: |
            Cardinal-*.exe
            Cardinal-*.zip
      - uses: softprops/action-gh-release@v1
        if: startsWith(github.ref, 'refs/tags/')
        with:
          tag_name: ${{ github.ref_name }}
          name: ${{ github.ref_name }}
          draft: false
          prerelease: false
          files: |
            Cardinal-*.exe
            Cardinal-*.zip

  source-tarball:
    runs-on: ubuntu-20.04
    steps:
      - uses: actions/checkout@v3
        with:
          submodules: recursive
      - name: Set up dependencies
        run: |
          sudo apt-get update -qq
          sudo apt-get install -yqq liblo-dev
          sudo apt-get clean
      - name: Create source tarball
        run: |
          make HEADLESS=true tarball
          make HEADLESS=true tarball+deps
      - name: Set sha8 (non-release)
        if: startsWith(github.ref, 'refs/tags/') != true
        run: echo "SHA8=$(echo ${{ github.sha }} | cut -c1-8)" >> $GITHUB_ENV
      - name: Set sha8 (release)
        if: startsWith(github.ref, 'refs/tags/')
        run: echo "SHA8=$(echo ${{ github.ref_name }})" >> $GITHUB_ENV
      - uses: actions/upload-artifact@v3
        with:
          name: ${{ github.event.repository.name }}-source-${{ github.event.pull_request.number || env.SHA8 }}
          path: |
            /home/runner/cardinal*.tar.xz
            /home/runner/*/cardinal*.tar.xz
            /home/runner/*/*/cardinal*.tar.xz
      - uses: softprops/action-gh-release@v1
        if: startsWith(github.ref, 'refs/tags/')
        with:
          tag_name: ${{ github.ref_name }}
          name: ${{ github.ref_name }}
          draft: false
          prerelease: false
          files: |
            /home/runner/cardinal*.tar.xz
            /home/runner/*/cardinal*.tar.xz
            /home/runner/*/*/cardinal*.tar.xz

  plugin-validation:
    runs-on: ubuntu-20.04
    steps:
      - uses: actions/checkout@v3
        with:
          submodules: recursive
      - name: Set up cache
        id: cache
        uses: actions/cache@v3
        with:
          path: |
            src/Rack/dep/bin
            src/Rack/dep/include
            src/Rack/dep/lib
            src/Rack/dep/share
            src/Rack/dep/jansson-2.12
            src/Rack/dep/libarchive-3.4.3
            src/Rack/dep/libsamplerate-0.1.9
            src/Rack/dep/speexdsp-SpeexDSP-1.2rc3
            src/Rack/dep/zstd-1.4.5
          key: pluginval-v${{ env.CACHE_VERSION }}
      - name: Set up dependencies
        run: |
          # custom repos
          wget https://launchpad.net/~kxstudio-debian/+archive/kxstudio/+files/kxstudio-repos_11.1.0_all.deb
          sudo dpkg -i kxstudio-repos_11.1.0_all.deb
          sudo apt-get update -qq
          # build-deps
          sudo apt-get install -yqq libdbus-1-dev libgl1-mesa-dev liblo-dev libx11-dev libxcursor-dev libxext-dev libxrandr-dev
          # runtime testing
          sudo apt-get install -yqq carla-git lilv-utils lv2-dev lv2lint kxstudio-lv2-extensions mod-lv2-extensions valgrind xvfb
          sudo apt-get clean
      - name: Set up ccache
        uses: hendrikmuhs/ccache-action@v1.2
        with:
          key: ccache-pluginval-v${{ env.CACHE_VERSION }}
      - name: Build Cardinal
        env:
          CFLAGS: -g
          CXXFLAGS: -g -DDPF_ABORT_ON_ERROR -DDPF_RUNTIME_TESTING
          LDFLAGS: -static-libgcc -static-libstdc++
        run: |
          export PATH="/usr/lib/ccache:${PATH}"
          make features
          make NOOPT=true SKIP_STRIPPING=true -j $(nproc)
      - name: Run Cardinal self-tests
        run: |
          # --exit-on-first-error=yes
          xvfb-run valgrind \
                --gen-suppressions=all \
                --error-exitcode=255 \
                --leak-check=no \
                --track-origins=yes \
                --keep-debuginfo=yes \
                --suppressions=./dpf/utils/valgrind-dpf.supp \
                ./bin/Cardinal selftest
      - name: Validate LV2 ttl syntax
        run: |
          lv2_validate \
              /usr/lib/lv2/mod.lv2/*.ttl \
              /usr/lib/lv2/kx-meta/*.ttl \
              /usr/lib/lv2/kx-control-input-port-change-request.lv2/*.ttl \
              /usr/lib/lv2/kx-programs.lv2/*.ttl \
              ./bin/*.lv2/*.ttl
      - name: Validate LV2 metadata and binaries
        run: |
          export LV2_PATH=/tmp/lv2-path
          mkdir ${LV2_PATH}
          mv bin/CardinalFX.lv2 bin/CardinalSynth.lv2 ${LV2_PATH}
          cp -r /usr/lib/lv2/{atom,buf-size,core,data-access,kx-control-input-port-change-request,kx-programs,instance-access,midi,mod,parameters,port-groups,port-props,options,patch,presets,resize-port,state,time,ui,units,urid,worker}.lv2 ${LV2_PATH}
          xvfb-run lv2lint -s lv2_generate_ttl -l ld-linux-x86-64.so.2 -M nopack $(lv2ls)
      - name: Test LV2 plugin
        run: |
            export LV2_PATH=/tmp/lv2-path
            for p in $(lv2ls); do \
                env CARLA_BRIDGE_DUMMY=1 CARLA_BRIDGE_TESTING=native \
                    xvfb-run valgrind \
                    --error-exitcode=255 \
                    --leak-check=no \
                    --track-origins=yes \
                    --keep-debuginfo=yes \
                    --suppressions=./dpf/utils/valgrind-dpf.supp \
                    /usr/lib/carla/carla-bridge-native lv2 "" ${p}; \
            done
      - name: Test VST2 plugin
        run: |
            for p in $(ls bin/*.vst/*.so); do \
                env CARLA_BRIDGE_DUMMY=1 CARLA_BRIDGE_TESTING=native \
                    xvfb-run valgrind \
                    --error-exitcode=255 \
                    --leak-check=no \
                    --track-origins=yes \
                    --keep-debuginfo=yes \
                    --suppressions=./dpf/utils/valgrind-dpf.supp \
                    /usr/lib/carla/carla-bridge-native vst2 ./${p} ""; \
            done
      - name: Test VST3 plugin
        run: |
            for p in $(ls bin/ | grep vst3); do \
                env CARLA_BRIDGE_DUMMY=1 CARLA_BRIDGE_TESTING=native \
                    xvfb-run valgrind \
                    --error-exitcode=255 \
                    --leak-check=no \
                    --track-origins=yes \
                    --keep-debuginfo=yes \
                    --suppressions=./dpf/utils/valgrind-dpf.supp \
                    /usr/lib/carla/carla-bridge-native vst3 ./bin/${p} ""; \
            done
