name: linux-arm
on:
  push:
    branches: [master]
    paths:
    - '.github/workflows/linux-arm.yml'
    - 'toolchains/arm-linux-gnueabi.toolchain.cmake'
    - 'toolchains/arm-linux-gnueabihf.toolchain.cmake'
    - 'CMakeLists.txt'
    - 'cmake/**'
    - 'src/*'
    - 'src/layer/*'
    - 'src/layer/arm/**'
    - 'tests/**'
  pull_request:
    branches: [master]
    paths:
    - '.github/workflows/linux-arm.yml'
    - 'toolchains/arm-linux-gnueabi.toolchain.cmake'
    - 'toolchains/arm-linux-gnueabihf.toolchain.cmake'
    - 'CMakeLists.txt'
    - 'cmake/**'
    - 'src/*'
    - 'src/layer/*'
    - 'src/layer/arm/**'
    - 'tests/**'
concurrency:
  group: linux-arm-${{ github.ref }}
  cancel-in-progress: true
permissions:
  contents: read

jobs:
  arm:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4

    - name: arm-gnu-toolchain
      run: |
        sudo apt-get update
        sudo apt-get install g++-arm-linux-gnueabi qemu-user-static

    - name: build
      run: |
        mkdir build && cd build
        cmake -DCMAKE_TOOLCHAIN_FILE=../toolchains/arm-linux-gnueabi.toolchain.cmake -DNCNN_BUILD_TOOLS=OFF -DNCNN_BUILD_EXAMPLES=OFF -DNCNN_BUILD_TESTS=ON ..
        cmake --build . -j $(nproc)
    - name: test
      run: |
        cd build
        TESTS_EXECUTABLE_LOADER=qemu-arm-static TESTS_EXECUTABLE_LOADER_ARGUMENTS="-L;/usr/arm-linux-gnueabi" ctest --output-on-failure -j $(nproc)

    - name: build-noint8
      run: |
        mkdir build-noint8 && cd build-noint8
        cmake -DCMAKE_TOOLCHAIN_FILE=../toolchains/arm-linux-gnueabi.toolchain.cmake -DNCNN_BUILD_TOOLS=OFF -DNCNN_BUILD_EXAMPLES=OFF -DNCNN_BUILD_TESTS=ON -DNCNN_INT8=OFF ..
        cmake --build . -j $(nproc)
    - name: test-noint8
      run: |
        cd build-noint8
        TESTS_EXECUTABLE_LOADER=qemu-arm-static TESTS_EXECUTABLE_LOADER_ARGUMENTS="-L;/usr/arm-linux-gnueabi" ctest --output-on-failure -j $(nproc)

  armhf:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4

    - name: arm-gnu-toolchain
      run: |
        sudo apt-get update
        sudo apt-get install g++-arm-linux-gnueabihf qemu-user-static

    - name: build
      run: |
        mkdir build && cd build
        cmake -DCMAKE_TOOLCHAIN_FILE=../toolchains/arm-linux-gnueabihf.toolchain.cmake -DNCNN_BUILD_TOOLS=OFF -DNCNN_BUILD_EXAMPLES=OFF -DNCNN_BUILD_TESTS=ON ..
        cmake --build . -j $(nproc)
    - name: test
      run: |
        cd build
        TESTS_EXECUTABLE_LOADER=qemu-arm-static TESTS_EXECUTABLE_LOADER_ARGUMENTS="-L;/usr/arm-linux-gnueabihf" ctest --output-on-failure -j $(nproc)

    - name: build-noint8
      run: |
        mkdir build-noint8 && cd build-noint8
        cmake -DCMAKE_TOOLCHAIN_FILE=../toolchains/arm-linux-gnueabihf.toolchain.cmake -DNCNN_BUILD_TOOLS=OFF -DNCNN_BUILD_EXAMPLES=OFF -DNCNN_BUILD_TESTS=ON -DNCNN_INT8=OFF ..
        cmake --build . -j $(nproc)
    - name: test-noint8
      run: |
        cd build-noint8
        TESTS_EXECUTABLE_LOADER=qemu-arm-static TESTS_EXECUTABLE_LOADER_ARGUMENTS="-L;/usr/arm-linux-gnueabihf" ctest --output-on-failure -j $(nproc)

  armhf-vfpv3-d16:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4

    - name: arm-gnu-toolchain
      run: |
        sudo apt-get update
        sudo apt-get install g++-arm-linux-gnueabihf qemu-user-static

    - name: build
      run: |
        mkdir build && cd build
        cmake -DCMAKE_TOOLCHAIN_FILE=../toolchains/arm-linux-gnueabihf-vfpv3-d16.toolchain.cmake -DNCNN_BUILD_TOOLS=OFF -DNCNN_BUILD_EXAMPLES=OFF -DNCNN_BUILD_TESTS=ON ..
        cmake --build . -j $(nproc)
    - name: test
      run: |
        cd build
        TESTS_EXECUTABLE_LOADER=qemu-arm-static TESTS_EXECUTABLE_LOADER_ARGUMENTS="-L;/usr/arm-linux-gnueabihf" ctest --output-on-failure -j $(nproc)

    - name: build-noint8
      run: |
        mkdir build-noint8 && cd build-noint8
        cmake -DCMAKE_TOOLCHAIN_FILE=../toolchains/arm-linux-gnueabihf-vfpv3-d16.toolchain.cmake -DNCNN_BUILD_TOOLS=OFF -DNCNN_BUILD_EXAMPLES=OFF -DNCNN_BUILD_TESTS=ON -DNCNN_INT8=OFF ..
        cmake --build . -j $(nproc)
    - name: test-noint8
      run: |
        cd build-noint8
        TESTS_EXECUTABLE_LOADER=qemu-arm-static TESTS_EXECUTABLE_LOADER_ARGUMENTS="-L;/usr/arm-linux-gnueabihf" ctest --output-on-failure -j $(nproc)
