name: linux

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:
  build:
    if: "! contains(toJSON(github.event.commits.*.message), '[ci skip]')"

    name: Build and Test (linux) - ${{ matrix.os }}-${{ matrix.arch }}
    runs-on: ${{ matrix.os }}

    strategy:
      matrix:
        include:
          - os: ubuntu-latest
            arch: x64
          - os: ubuntu-24.04-arm
            arch: aarch64


    steps:
    - uses: actions/checkout@v1
      with:
        submodules: true

    - name: install packages
      run: sudo apt-get update && sudo apt-get install -y xorg-dev libglu1-mesa-dev xpra xserver-xorg-video-dummy freeglut3-dev

    - name: configure
      run: cd test && mkdir build && cd build && cmake -DCMAKE_BUILD_TYPE=Debug -DPOLYSCOPE_BACKEND_OPENGL3_GLFW=ON -DPOLYSCOPE_BACKEND_OPENGL_MOCK=ON ..

    - name: build
      run: cd test/build && cmake --build "." --parallel

    - name: run test mock backend
      run: cd test/build && ./bin/polyscope-test --gtest_catch_exceptions=0 backend=openGL_mock
    
    - name: run test egl backend
      # We get memory leaks inside of EGL that I can't track down. With ASAN, this means the exit code is always nonzero,
      # which is indistinguishable from tests failing. The ASAN_OPTIONS=detect_leaks=0 skips checking leaks for this test 
      # as a workaround.
      run: cd test/build && ASAN_OPTIONS=detect_leaks=0 ./bin/polyscope-test --gtest_catch_exceptions=0 backend=openGL3_egl
  
  build_shared:
    if: "! contains(toJSON(github.event.commits.*.message), '[ci skip]')"
    
    name: Build Shared and Test (linux) - ${{ matrix.os }}-${{ matrix.arch }}
    runs-on: ${{ matrix.os }}

    strategy:
      matrix:
        include:
          - os: ubuntu-latest
            arch: x64
          - os: ubuntu-24.04-arm
            arch: aarch64

    steps:
    - uses: actions/checkout@v1
      with:
        submodules: true

    - name: install packages
      run: sudo apt-get update && sudo apt-get install -y xorg-dev libglu1-mesa-dev xpra xserver-xorg-video-dummy freeglut3-dev

    - name: configure
      run: cd test && mkdir build && cd build && cmake -DBUILD_SHARED_LIBS=TRUE -DCMAKE_BUILD_TYPE=Debug -DPOLYSCOPE_BACKEND_OPENGL3_GLFW=ON -DPOLYSCOPE_BACKEND_OPENGL_MOCK=ON -DPOLYSCOPE_BACKEND_OPENGL3_EGL=ON ..

    - name: build
      run: cd test/build && cmake --build "." --parallel

    - name: run test mock backend
      run: cd test/build && ./bin/polyscope-test --gtest_catch_exceptions=0 backend=openGL_mock
    
    - name: run test egl backend
      # We get memory leaks inside of EGL that I can't track down. With ASAN, this means the exit code is always nonzero,
      # which is indistinguishable from tests failing. The ASAN_OPTIONS=detect_leaks=0 skips checking leaks for this test 
      # as a workaround.
      # run: cd test/build && ASAN_OPTIONS=detect_leaks=0 ./bin/polyscope-test --gtest_catch_exceptions=0 backend=openGL3_egl
      run: cd test/build && ./bin/polyscope-test --gtest_catch_exceptions=0 backend=openGL3_egl
