name: Ubuntu with default JDK

on:
  workflow_dispatch: # allows manual triggering
  push:
    branches: [ "1.1" ]
  pull_request:
    branches: [ "testing", "unstable" ]

jobs:
  build:
    name: ${{ matrix.os }} (${{ matrix.c_compiler }})
    runs-on: ${{ matrix.os }}

    strategy:
      fail-fast: false

      matrix:
        os: [ubuntu-24.04, ubuntu-24.04-arm]
        build_type: [Release]
        c_compiler: [gcc, clang]
        include:
          - os: ubuntu-24.04
            c_compiler: gcc
            cpp_compiler: g++
            cpu_all_variants: ON
          - os: ubuntu-24.04-arm
            c_compiler: gcc
            cpp_compiler: g++
            cpu_all_variants: OFF
          - os: ubuntu-24.04
            c_compiler: clang
            cpp_compiler: clang++
            cpu_all_variants: ON
          - os: ubuntu-24.04-arm
            c_compiler: clang
            cpp_compiler: clang++
            cpu_all_variants: OFF

    steps:
    - uses: actions/checkout@v4
      name: Clone recursively with tags
      with:
        submodules: 'true'
        fetch-depth: '0'
        fetch-tags: 'true'

    - name: Use latest third-parties
      run: make -f tooling.mk tp-clone tp-checkout-latest

    - name: Dependencies
      id: depends
      run: |
       sudo apt-get update
       sudo apt-get install -y default-jdk glslc libvulkan-dev

    - name: Configure CMake
      run: >
        cmake -B build/argeo-jjml
        -DJAVA_HOME=/usr/lib/jvm/default-java
        -DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }}
        -DCMAKE_C_COMPILER=${{ matrix.c_compiler }}
        -DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
        -DJJML_FORCE_BUILD_TP=ON
        -DLLAMA_CURL=OFF
        -DLLAMA_BUILD_COMMON=OFF
        -DLLAMA_BUILD_TOOLS=OFF
        -DLLAMA_BUILD_EXAMPLES=OFF
        -DLLAMA_BUILD_TESTS=OFF
        -DGGML_BACKEND_DL=${{ matrix.cpu_all_variants }}
        -DGGML_CPU_ALL_VARIANTS=${{ matrix.cpu_all_variants }}
        -DGGML_VULKAN=OFF
        -S ${{ github.workspace }}

    - name: Build
      run: cmake --build build/argeo-jjml -j $(nproc)

    - name: Test
      run: >
        java -ea
        -Djava.library.path=${{ github.workspace }}/build/a2/lib/$(uname -m)-linux-gnu/org.argeo.jjml:${{ github.workspace }}/build/a2/lib/$(uname -m)-linux-gnu/org.argeo.tp.ggml
        --module-path ${{ github.workspace }}/build/a2/lib/org.argeo.jjml
        --add-modules org.argeo.jjml
        sdk/jbin/JjmlSmokeTests.java
        allenai/OLMo-2-0425-1B-Instruct-GGUF
