name: windows-x64-cpu-vs2019
on:
  push:
    branches: [master]
    paths:
    - '.github/workflows/windows-x64-cpu-vs2019.yml'
    - 'CMakeLists.txt'
    - 'cmake/**'
    - 'src/*'
    - 'src/layer/*'
    - 'src/layer/x86/**'
    - 'tests/**'
    - 'tools/**'
    - '!tools/pnnx/**'
    - 'examples/**'
  pull_request:
    branches: [master]
    paths:
    - '.github/workflows/windows-x64-cpu-vs2019.yml'
    - 'CMakeLists.txt'
    - 'cmake/**'
    - 'src/*'
    - 'src/layer/*'
    - 'src/layer/x86/**'
    - 'tests/**'
    - 'tools/**'
    - '!tools/pnnx/**'
    - 'examples/**'
concurrency:
  group: windows-x64-cpu-vs2019-${{ github.ref }}
  cancel-in-progress: true
jobs:
  windows-vs2019:
    runs-on: windows-latest
    steps:
    - uses: actions/checkout@v2
    - name: cache-protobuf
      id: cache-protobuf
      uses: actions/cache@v2.1.7
      with:
        path: "protobuf-install"
        key: protobuf-windows-install
    - name: protobuf
      if: steps.cache-protobuf.outputs.cache-hit != 'true'
      run: |
        Invoke-WebRequest -Uri https://github.com/protocolbuffers/protobuf/archive/v3.11.2.zip -OutFile protobuf-3.11.2.zip
        7z x ./protobuf-3.11.2.zip
        cd protobuf-3.11.2
        mkdir build-vs2019; cd build-vs2019; cmake -DCMAKE_INSTALL_PREFIX="$env:GITHUB_WORKSPACE\protobuf-install" -Dprotobuf_BUILD_TESTS=OFF -Dprotobuf_MSVC_STATIC_RUNTIME=OFF -DNCNN_BUILD_TESTS=ON ../cmake
        cmake --build . --config Release -j 2
        cmake --build . --config Release --target install
    - name: build-sse2
      run: |
        mkdir build-sse2; cd build-sse2
        cmake -DProtobuf_INCLUDE_DIR="$env:GITHUB_WORKSPACE\protobuf-install\include" -DProtobuf_LIBRARIES="$env:GITHUB_WORKSPACE\protobuf-install\lib\libprotobuf.lib" -DProtobuf_PROTOC_EXECUTABLE="$env:GITHUB_WORKSPACE\protobuf-install\bin\protoc.exe" -DNCNN_RUNTIME_CPU=OFF -DNCNN_AVX2=OFF -DNCNN_AVX=OFF -DNCNN_BUILD_TESTS=ON ..
        cmake --build . --config Release -j 2
    - name: test-sse2
      run: cd build-sse2; ctest -C Release --output-on-failure -j 2
    - name: build-shared
      run: |
        mkdir build-shared; cd build-shared
        cmake -DProtobuf_INCLUDE_DIR="$env:GITHUB_WORKSPACE\protobuf-install\include" -DProtobuf_LIBRARIES="$env:GITHUB_WORKSPACE\protobuf-install\lib\libprotobuf.lib" -DProtobuf_PROTOC_EXECUTABLE="$env:GITHUB_WORKSPACE\protobuf-install\bin\protoc.exe" -DNCNN_RUNTIME_CPU=ON -DNCNN_AVX2=ON -DNCNN_SHARED_LIB=ON -DNCNN_ENABLE_LTO=ON ..
        cmake --build . --config Release -j 2
    - name: build-avx2
      run: |
        mkdir build-avx2; cd build-avx2
        cmake -DProtobuf_INCLUDE_DIR="$env:GITHUB_WORKSPACE\protobuf-install\include" -DProtobuf_LIBRARIES="$env:GITHUB_WORKSPACE\protobuf-install\lib\libprotobuf.lib" -DProtobuf_PROTOC_EXECUTABLE="$env:GITHUB_WORKSPACE\protobuf-install\bin\protoc.exe" -DNCNN_RUNTIME_CPU=OFF -DNCNN_AVX2=ON -DNCNN_BUILD_TESTS=ON ..
        cmake --build . --config Release -j 2
    - name: test-avx2
      run: cd build-avx2; ctest -C Release --output-on-failure -j 2
    - name: build-avx
      run: |
        mkdir build-avx; cd build-avx
        cmake -DProtobuf_INCLUDE_DIR="$env:GITHUB_WORKSPACE\protobuf-install\include" -DProtobuf_LIBRARIES="$env:GITHUB_WORKSPACE\protobuf-install\lib\libprotobuf.lib" -DProtobuf_PROTOC_EXECUTABLE="$env:GITHUB_WORKSPACE\protobuf-install\bin\protoc.exe" -DNCNN_RUNTIME_CPU=OFF -DNCNN_AVX=ON -DNCNN_AVX2=OFF -DNCNN_BUILD_TESTS=ON ..
        cmake --build . --config Release -j 2
    - name: test-avx
      run: cd build-avx; ctest -C Release --output-on-failure -j 2
    - name: build-avx1-2
      run: |
        mkdir build-avx1-2; cd build-avx1-2
        cmake -DProtobuf_INCLUDE_DIR="$env:GITHUB_WORKSPACE\protobuf-install\include" -DProtobuf_LIBRARIES="$env:GITHUB_WORKSPACE\protobuf-install\lib\libprotobuf.lib" -DProtobuf_PROTOC_EXECUTABLE="$env:GITHUB_WORKSPACE\protobuf-install\bin\protoc.exe" -DNCNN_RUNTIME_CPU=OFF -DNCNN_AVX=ON -DNCNN_AVX2=ON -DNCNN_BUILD_TESTS=ON ..
        cmake --build . --config Release -j 2
    - name: test-avx1-2
      run: cd build-avx1-2; ctest -C Release --output-on-failure -j 2