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

jobs:
  gcc-loongarch64:
    runs-on: [self-hosted, linux, centos]

    steps:
    - uses: actions/checkout@v4

    # - name: qemu
    #   run: |
    #     sudo apt-get update
    #     sudo apt-get install -y qemu-user-static

    # - name: loongarch64-toolchain
    #   run: |
    #     wget https://github.com/sunhaiyong1978/CLFS-for-LoongArch/releases/download/8.0/loongarch64-clfs-8.0-cross-tools-gcc-full.tar.xz
    #     tar -xf loongarch64-clfs-8.0-cross-tools-gcc-full.tar.xz

    - name: build
      run: |
        export LOONGARCH64_ROOT_PATH=/data/action/osd/cross-tools
        mkdir build && cd build
        cmake -DCMAKE_TOOLCHAIN_FILE=../toolchains/loongarch64-unknown-linux-gnu.toolchain.cmake -DNCNN_BUILD_TOOLS=OFF -DNCNN_BUILD_EXAMPLES=OFF -DNCNN_BUILD_TESTS=ON ..
        cmake --build . -j 4

    - name: test
      run: |
        cd build
        TESTS_EXECUTABLE_LOADER=qemu-loongarch64-static TESTS_EXECUTABLE_LOADER_ARGUMENTS="-L;/data/action/osd/cross-tools/target" ctest --output-on-failure -j 4
