name: Build

on:
  push:
    branches:
      - master
  pull_request:

jobs:
  build:
    strategy:
      fail-fast: false
      matrix:
        include:
          - name: Android (API 16, NDK 19)
            ANDROID_API: 16
            ANDROID_NDK: 19.2.5345600
          - name: Android (API 30 NDK 21)
            ANDROID_API: 30
            ANDROID_NDK: 21.3.6528147

    runs-on: macos-latest

    env:
      ANDROID_API: ${{ matrix.ANDROID_API }}
      ANDROID_NDK: ${{ matrix.ANDROID_NDK }}

    steps:
      - uses: actions/checkout@v2
        with:
          submodules: "recursive"

      - name: Installing Android SDK Dependencies
        run: |
          echo "Downloading ndk;$ANDROID_NDK"
          echo "y" | $ANDROID_HOME/tools/bin/sdkmanager --install \
            "ndk;$ANDROID_NDK" | \
            grep -v "\[=" || true # suppress the progress bar, so we get meaningful logs

      - name: Build x86_64
        run: |
          cmake -B build -S cmake \
            -D CMAKE_TOOLCHAIN_FILE=$ANDROID_HOME/ndk/$ANDROID_NDK/build/cmake/android.toolchain.cmake \
            -D ANDROID_NATIVE_API_LEVEL=$ANDROID_API \
            -D ANDROID_ABI=x86_64
          cmake --build build --parallel

      - name: Build arm64-v8a
        run: |
          rm -rf build
          cmake -B build -S cmake \
            -D CMAKE_TOOLCHAIN_FILE=$ANDROID_HOME/ndk/$ANDROID_NDK/build/cmake/android.toolchain.cmake \
            -D ANDROID_NATIVE_API_LEVEL=$ANDROID_API \
            -D ANDROID_ABI=arm64-v8a
          cmake --build build --parallel
