name: Android

on:
  pull_request:
    branches:
      - main
  push:
    branches:
      - main

permissions:
  contents: read

jobs:
  build_x86_64:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4
    - uses: nttld/setup-ndk@v1.3.1
      id: setup-ndk
      with:
        submodules: true
        ndk-version: r21e
        local-cache: true

    - name: Install Packages
      run: |
        sudo apt-get update
        sudo apt-get install meson ninja-build libgles-dev

    - name: Build
      env:
        NDK: ${{ steps.setup-ndk.outputs.ndk-path }}
        API: 21
      run: |
        sed -e "s|NDK|$NDK|g" -e "s|HOST_TAG|linux-x86_64|g" -e "s|API|$API|g" ./cross/android_x86_64.txt > /tmp/android_cross.txt
        meson setup build -Dlog=true -Dengines="sw, gl" -Dloaders=all -Dsavers=all -Dbindings=capi -Dstatic=true -Dthreads=false --cross-file /tmp/android_cross.txt
        sudo ninja -C build install

    - uses: actions/upload-artifact@v4
      with:
        name: result_x86_64
        path: build/src/libthorvg*

  build_aarch64:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4
    - uses: nttld/setup-ndk@v1.3.1
      id: setup-ndk
      with:
        submodules: true
        ndk-version: r21e
        local-cache: true

    - name: Install Packages
      run: |
        sudo apt-get update
        sudo apt-get install meson ninja-build libgles-dev

    - name: Build
      env:
        NDK: ${{ steps.setup-ndk.outputs.ndk-path }}
        API: 21
      run: |
        sed -e "s|NDK|$NDK|g" -e "s|HOST_TAG|linux-x86_64|g" -e "s|API|$API|g" ./cross/android_aarch64.txt > /tmp/android_cross.txt
        meson setup build -Dlog=true -Dengines="sw, gl" -Dloaders=all -Dsavers=all -Dbindings=capi -Dstatic=true -Dthreads=false --cross-file /tmp/android_cross.txt
        sudo ninja -C build install

    - uses: actions/upload-artifact@v4
      with:
        name: result_aarch64
        path: build/src/libthorvg*
