name: CI Pkgcheck
on: [push, pull_request]
jobs:
  ci-pkgcheck:
    name: ${{ matrix.name }}
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        name: [
          Ubuntu GCC,
          Ubuntu GCC -m32,
          Ubuntu GCC ARM HF,
          Ubuntu GCC AARCH64,
          Ubuntu GCC PPC,
          Ubuntu GCC PPC64LE,
          macOS Clang
        ]
        include:
          - name: Ubuntu GCC
            os: ubuntu-latest
            compiler: gcc

          - name: Ubuntu GCC -m32
            os: ubuntu-latest
            compiler: gcc
            packages: gcc-multilib
            cmake-args: -DCMAKE_C_FLAGS=-m32
            cflags: -m32
            ldflags: -m32

          - name: Ubuntu GCC ARM HF
            os: ubuntu-latest
            chost: arm-linux-gnueabihf
            compiler: arm-linux-gnueabihf-gcc
            cmake-args: -DCMAKE_TOOLCHAIN_FILE=cmake/toolchain-arm.cmake -DCMAKE_C_COMPILER_TARGET=arm-linux-gnueabihf
            packages: qemu gcc-arm-linux-gnueabihf libc6-dev-armhf-cross

          - name: Ubuntu GCC AARCH64
            os: ubuntu-latest
            chost: aarch64-linux-gnu
            compiler: aarch64-linux-gnu-gcc
            cmake-args: -DCMAKE_TOOLCHAIN_FILE=cmake/toolchain-aarch64.cmake
            packages: qemu gcc-aarch64-linux-gnu libc6-dev-arm64-cross

          - name: Ubuntu GCC PPC
            os: ubuntu-latest
            chost: powerpc-linux-gnu
            compiler: powerpc-linux-gnu-gcc
            cmake-args: -DCMAKE_TOOLCHAIN_FILE=cmake/toolchain-powerpc.cmake
            packages: qemu gcc-powerpc-linux-gnu libc6-dev-powerpc-cross

          - name: Ubuntu GCC PPC64LE
            os: ubuntu-latest
            chost: powerpc64le-linux-gnu
            compiler: powerpc64le-linux-gnu-gcc
            cmake-args: -DCMAKE_TOOLCHAIN_FILE=cmake/toolchain-powerpc64le.cmake
            packages: qemu gcc-powerpc64le-linux-gnu libc6-dev-ppc64el-cross

          - name: macOS Clang
            os: macOS-latest
            compiler: clang

    steps:
    - name: Checkout repository
      uses: actions/checkout@v1

    - name: Install packages (Ubuntu)
      if: runner.os == 'Linux'
      run: |
        sudo apt-get update
        sudo apt-get install -y --no-install-recommends abigail-tools ninja-build ${{ matrix.packages }}

    - name: Install packages (macOS)
      if: runner.os == 'macOS'
      run: |
        brew install ninja ${{ matrix.packages }}

    - name: Compare builds
      run: |
        sh test/pkgcheck.sh
      env:
        CC: ${{ matrix.compiler }}
        CFLAGS: ${{ matrix.cflags }}
        CHOST: ${{ matrix.chost }}
        CMAKE_ARGS: ${{ matrix.cmake-args }}
        LDFLAGS: ${{ matrix.ldflags }}

    - name: Compare builds (compat)
      run: |
        sh test/pkgcheck.sh --zlib-compat
      env:
        CC: ${{ matrix.compiler }}
        CFLAGS: ${{ matrix.cflags }}
        CHOST: ${{ matrix.chost }}
        CMAKE_ARGS: ${{ matrix.cmake-args }}
        LDFLAGS: ${{ matrix.ldflags }}

    - name: Check ABI
      run: |
        sh test/abicheck.sh --refresh_if
      env:
        CC: ${{ matrix.compiler }}
        CFLAGS: ${{ matrix.cflags }}
        CHOST: ${{ matrix.chost }}
        LDFLAGS: ${{ matrix.ldflags }}

    - name: Check ABI (compat)
      run: |
        if test "$CHOST" = "powerpc-linux-gnu" || test "$CFLAGS" = "-m32"; then echo "SKIP 32 bit compat broken, see issue 705"; else sh test/abicheck.sh --zlib-compat --refresh_if; fi
      env:
        CC: ${{ matrix.compiler }}
        CFLAGS: ${{ matrix.cflags }}
        CHOST: ${{ matrix.chost }}
        LDFLAGS: ${{ matrix.ldflags }}
