name: release
on:
  push:
    tags:
      - '*'

env:
  DEVELOPER_DIR: /Applications/Xcode_15.2.app/Contents/Developer
  IOS_DEPLOYMENT_TARGET: '13.0'
  MAC_DEPLOYMENT_TARGET: '11.0'
  MAC_CATALYST_DEPLOYMENT_TARGET: '13.1'
  WATCHOS_DEPLOYMENT_TARGET: '6.0'
  TVOS_DEPLOYMENT_TARGET: '11.0'
  VISIONOS_DEPLOYMENT_TARGET: '1.0'
  ENABLE_BITCODE: OFF
  ENABLE_ARC: OFF
  ENABLE_VISIBILITY: OFF
  EMSCRIPTEN_VERSION: 3.1.28

permissions:
  contents: read

jobs:

  setup:
    permissions:
      contents: none
    runs-on: ubuntu-latest
    outputs:
      VERSION: ${{ steps.get_version.outputs.VERSION }}
    steps:
    - name: get-version
      id: get_version
      run: echo "VERSION=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_OUTPUT

  full-source:
    needs: [setup]
    runs-on: ubuntu-latest
    env:
      PACKAGENAME: ncnn-${{ needs.setup.outputs.VERSION }}-full-source
    steps:
    - uses: actions/checkout@v4
      with:
        submodules: true
    - name: package
      run: |
        rm -rf .git
        rm -f /tmp/${{ env.PACKAGENAME }}.zip
        zip -9 -y -r /tmp/${{ env.PACKAGENAME }}.zip .
    - name: upload-zip
      uses: actions/upload-artifact@v4
      with:
        name: ${{ env.PACKAGENAME }}
        path: /tmp/${{ env.PACKAGENAME }}.zip

  ubuntu:
    needs: [setup]
    strategy:
      matrix:
        opt:
          - { shared-lib: OFF, os: ubuntu-22.04, id: ubuntu-2204        }
          - { shared-lib: OFF, os: ubuntu-24.04, id: ubuntu-2404        }
          - { shared-lib: ON,  os: ubuntu-22.04, id: ubuntu-2204-shared }
          - { shared-lib: ON,  os: ubuntu-24.04, id: ubuntu-2404-shared }
    runs-on: ${{ matrix.opt.os }}
    env:
      PACKAGENAME: ncnn-${{ needs.setup.outputs.VERSION }}-${{ matrix.opt.id }}
    steps:
    - uses: actions/checkout@v4
      with:
        submodules: true
    - name: apt
      run: |
        sudo apt-get install -y libprotobuf-dev protobuf-compiler
    - name: build
      run: |
        mkdir build && cd build
        cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=install -DNCNN_VERSION_STRING="${{ needs.setup.outputs.VERSION }}" \
            -DNCNN_VULKAN=ON -DNCNN_BUILD_EXAMPLES=OFF -DNCNN_BUILD_TOOLS=ON -DNCNN_BUILD_BENCHMARK=OFF -DNCNN_SHARED_LIB=${{ matrix.opt.shared-lib }} ..
        cmake --build . -j $(nproc)
        cmake --build . --target install/strip
    - name: package
      run: |
        rm -rf ${{ env.PACKAGENAME }}
        mkdir -p ${{ env.PACKAGENAME }}
        cp -a build/install/* ${{ env.PACKAGENAME }}
        rm -f ${{ env.PACKAGENAME }}.zip
        zip -9 -y -r ${{ env.PACKAGENAME }}.zip ${{ env.PACKAGENAME }}
    - name: upload-zip
      uses: actions/upload-artifact@v4
      with:
        name: ${{ env.PACKAGENAME }}
        path: ${{ env.PACKAGENAME }}.zip

  openmp-macos:
    runs-on: macos-13
    env:
      OPENMP_VERSION: '18.1.2'
      OPENMP_CMAKE_OPTIONS: |
        -DCMAKE_TOOLCHAIN_FILE=../../toolchains/ios.toolchain.cmake \
        -DDEPLOYMENT_TARGET=$MAC_DEPLOYMENT_TARGET \
        -DENABLE_BITCODE=$ENABLE_BITCODE \
        -DENABLE_ARC=$ENABLE_ARC \
        -DENABLE_VISIBILITY=$ENABLE_VISIBILITY \
        -DCMAKE_INSTALL_PREFIX=install \
        -DCMAKE_BUILD_TYPE=Release \
        -DPERL_EXECUTABLE=/usr/local/bin/perl \
        -DLIBOMP_ENABLE_SHARED=OFF \
        -DLIBOMP_OMPT_SUPPORT=OFF \
        -DLIBOMP_USE_HWLOC=OFF \
    steps:
    - name: cache-openmp
      id: cache-openmp
      uses: actions/cache@v4
      with:
        path: openmp-install
        key: openmp-macos-release-18.1.2-20240403
    - name: checkout
      if: steps.cache-openmp.outputs.cache-hit != 'true'
      uses: actions/checkout@v4
    - name: openmp
      if: steps.cache-openmp.outputs.cache-hit != 'true'
      run: |
        wget https://github.com/llvm/llvm-project/releases/download/llvmorg-${{ env.OPENMP_VERSION }}/cmake-${{ env.OPENMP_VERSION }}.src.tar.xz
        tar -xf cmake-${{ env.OPENMP_VERSION }}.src.tar.xz
        wget https://github.com/llvm/llvm-project/releases/download/llvmorg-${{ env.OPENMP_VERSION }}/openmp-${{ env.OPENMP_VERSION }}.src.tar.xz
        tar -xf openmp-${{ env.OPENMP_VERSION }}.src.tar.xz
        mv cmake-${{ env.OPENMP_VERSION }}.src/Modules/* openmp-${{ env.OPENMP_VERSION }}.src/cmake/
        cd openmp-${{ env.OPENMP_VERSION }}.src
        wget https://github.com/nihui/llvm-project/commit/ef8c35bcf5d9cfdb0764ffde6a63c04ec715bc37.patch
        patch -p2 -i ef8c35bcf5d9cfdb0764ffde6a63c04ec715bc37.patch
        wget https://github.com/nihui/llvm-project/commit/5c12711f9a21f41bea70566bf15a4026804d6b20.patch
        patch -p2 -i 5c12711f9a21f41bea70566bf15a4026804d6b20.patch
    - name: build-x86_64
      if: steps.cache-openmp.outputs.cache-hit != 'true'
      run: |
        cd openmp-${{ env.OPENMP_VERSION }}.src
        mkdir -p build-x86_64 && cd build-x86_64
        cmake ${{ env.OPENMP_CMAKE_OPTIONS }} -DPLATFORM=MAC -DARCHS="x86_64" ..
        cmake --build . -j 4
        cmake --build . --target install/strip
    - name: build-arm64
      if: steps.cache-openmp.outputs.cache-hit != 'true'
      run: |
        cd openmp-${{ env.OPENMP_VERSION }}.src
        mkdir -p build-arm64 && cd build-arm64
        cmake ${{ env.OPENMP_CMAKE_OPTIONS }} -DPLATFORM=MAC_ARM64 -DARCHS="arm64" ..
        cmake --build . -j 4
        cmake --build . --target install/strip
    - name: merge-fat-library
      if: steps.cache-openmp.outputs.cache-hit != 'true'
      run: |
        rm -rf $GITHUB_WORKSPACE/openmp-install
        mkdir -p $GITHUB_WORKSPACE/openmp-install
        cp -a openmp-${{ env.OPENMP_VERSION }}.src/build-x86_64/install/include $GITHUB_WORKSPACE/openmp-install
        mkdir -p $GITHUB_WORKSPACE/openmp-install/lib
        lipo -create \
            openmp-${{ env.OPENMP_VERSION }}.src/build-x86_64/install/lib/libomp.a \
            openmp-${{ env.OPENMP_VERSION }}.src/build-arm64/install/lib/libomp.a \
            -o $GITHUB_WORKSPACE/openmp-install/lib/libomp.a
    - name: upload
      uses: actions/upload-artifact@v4
      with:
        name: openmp-macos
        path: openmp-install

  macos:
    needs: [setup, openmp-macos]
    strategy:
      matrix:
        opt:
          - { vulkan: OFF, id: macos        }
          - { vulkan: ON,  id: macos-vulkan }
    runs-on: macos-13
    env:
      PACKAGENAME: ncnn-${{ needs.setup.outputs.VERSION }}-${{ matrix.opt.id }}
      NCNN_CMAKE_OPTIONS: |
        -DCMAKE_TOOLCHAIN_FILE=../toolchains/ios.toolchain.cmake \
        -DDEPLOYMENT_TARGET=$MAC_DEPLOYMENT_TARGET \
        -DENABLE_BITCODE=$ENABLE_BITCODE \
        -DENABLE_ARC=$ENABLE_ARC \
        -DENABLE_VISIBILITY=$ENABLE_VISIBILITY \
        -DCMAKE_INSTALL_PREFIX=install \
        -DCMAKE_BUILD_TYPE=Release \
        -DOpenMP_C_FLAGS="-Xclang -fopenmp" -DOpenMP_CXX_FLAGS="-Xclang -fopenmp" \
        -DOpenMP_C_LIB_NAMES="libomp" -DOpenMP_CXX_LIB_NAMES="libomp" \
        -DOpenMP_libomp_LIBRARY="libomp.a" \
        -DNCNN_VERSION_STRING="${{ needs.setup.outputs.VERSION }}" \
        -DNCNN_BUILD_TOOLS=OFF \
        -DNCNN_BUILD_EXAMPLES=OFF \
        -DNCNN_BUILD_BENCHMARK=OFF \
        -DNCNN_VULKAN=${{ matrix.opt.vulkan }} \

    steps:
    - uses: actions/checkout@v4
      with:
        submodules: true
    - name: download-openmp-macos
      uses: actions/download-artifact@v4
      with:
        name: openmp-macos
        path: openmp-macos
    - name: install-openmp
      run: |
        sudo cp openmp-macos/include/* $DEVELOPER_DIR/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include
        sudo cp openmp-macos/lib/libomp.a $DEVELOPER_DIR/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/lib
    - name: build-x86_64
      run: |
        mkdir build-x86_64 && cd build-x86_64
        cmake ${{ env.NCNN_CMAKE_OPTIONS }} -DPLATFORM=MAC -DARCHS="x86_64" ..
        cmake --build . -j 4
        cmake --build . --target install/strip
    - name: build-arm64
      run: |
        mkdir build-arm64 && cd build-arm64
        cmake ${{ env.NCNN_CMAKE_OPTIONS }} -DPLATFORM=MAC_ARM64 -DARCHS="arm64" ..
        cmake --build . -j 4
        cmake --build . --target install/strip
    - name: package-openmp
      run: |
        rm -rf openmp.framework
        mkdir -p openmp.framework/Versions/A/Headers
        mkdir -p openmp.framework/Versions/A/Resources
        ln -s A openmp.framework/Versions/Current
        ln -s Versions/Current/Headers openmp.framework/Headers
        ln -s Versions/Current/Resources openmp.framework/Resources
        ln -s Versions/Current/openmp openmp.framework/openmp
        cp openmp-macos/lib/libomp.a openmp.framework/Versions/A/openmp
        cp -a openmp-macos/include/* openmp.framework/Versions/A/Headers/
        sed -e 's/__NAME__/openmp/g' -e 's/__IDENTIFIER__/org.llvm.openmp/g' -e 's/__VERSION__/18.1/g' Info.plist > openmp.framework/Versions/A/Resources/Info.plist
    - name: package-glslang
      if: matrix.opt.vulkan == 'ON'
      run: |
        rm -rf glslang.framework
        mkdir -p glslang.framework/Versions/A/Headers
        mkdir -p glslang.framework/Versions/A/Resources
        ln -s A glslang.framework/Versions/Current
        ln -s Versions/Current/Headers glslang.framework/Headers
        ln -s Versions/Current/Resources glslang.framework/Resources
        ln -s Versions/Current/glslang glslang.framework/glslang
        libtool -static \
            build-x86_64/install/lib/libglslang.a \
            build-x86_64/install/lib/libSPIRV.a \
            -o build-x86_64/install/lib/libglslang_combined.a
        libtool -static \
            build-arm64/install/lib/libglslang.a \
            build-arm64/install/lib/libSPIRV.a \
            -o build-arm64/install/lib/libglslang_combined.a
        lipo -create build-x86_64/install/lib/libglslang_combined.a build-arm64/install/lib/libglslang_combined.a -o glslang.framework/Versions/A/glslang
        cp -a build-x86_64/install/include/glslang glslang.framework/Versions/A/Headers/
        sed -e 's/__NAME__/glslang/g' -e 's/__IDENTIFIER__/org.khronos.glslang/g' -e 's/__VERSION__/1.0/g' Info.plist > glslang.framework/Versions/A/Resources/Info.plist
    - name: package-ncnn
      run: |
        rm -rf ncnn.framework
        mkdir -p ncnn.framework/Versions/A/Headers
        mkdir -p ncnn.framework/Versions/A/Resources
        ln -s A ncnn.framework/Versions/Current
        ln -s Versions/Current/Headers ncnn.framework/Headers
        ln -s Versions/Current/Resources ncnn.framework/Resources
        ln -s Versions/Current/ncnn ncnn.framework/ncnn
        lipo -create build-x86_64/install/lib/libncnn.a build-arm64/install/lib/libncnn.a -o ncnn.framework/Versions/A/ncnn
        cp -a build-x86_64/install/include/* ncnn.framework/Versions/A/Headers/
        sed -e 's/__NAME__/ncnn/g' -e 's/__IDENTIFIER__/com.tencent.ncnn/g' -e 's/__VERSION__/1.0/g' Info.plist > ncnn.framework/Versions/A/Resources/Info.plist
    - name: package
      if: matrix.opt.vulkan == 'OFF'
      run: |
        rm -f ${{ env.PACKAGENAME }}.zip
        zip -9 -y -r ${{ env.PACKAGENAME }}.zip openmp.framework ncnn.framework
    - name: package
      if: matrix.opt.vulkan == 'ON'
      run: |
        rm -f ${{ env.PACKAGENAME }}.zip
        zip -9 -y -r ${{ env.PACKAGENAME }}.zip openmp.framework glslang.framework ncnn.framework
    - name: upload-zip
      uses: actions/upload-artifact@v4
      with:
        name: ${{ env.PACKAGENAME }}
        path: ${{ env.PACKAGENAME }}.zip

  openmp-ios:
    runs-on: macos-13
    env:
      OPENMP_VERSION: '18.1.2'
      OPENMP_CMAKE_OPTIONS: |
        -DCMAKE_TOOLCHAIN_FILE=../../toolchains/ios.toolchain.cmake \
        -DDEPLOYMENT_TARGET=$IOS_DEPLOYMENT_TARGET \
        -DENABLE_BITCODE=$ENABLE_BITCODE \
        -DENABLE_ARC=$ENABLE_ARC \
        -DENABLE_VISIBILITY=$ENABLE_VISIBILITY \
        -DCMAKE_INSTALL_PREFIX=install \
        -DCMAKE_BUILD_TYPE=Release \
        -DPERL_EXECUTABLE=/usr/local/bin/perl \
        -DLIBOMP_ENABLE_SHARED=OFF \
        -DLIBOMP_OMPT_SUPPORT=OFF \
        -DLIBOMP_USE_HWLOC=OFF \
    steps:
    - name: cache-openmp
      id: cache-openmp
      uses: actions/cache@v4
      with:
        path: openmp-install
        key: openmp-ios-release-18.1.2-20240403
    - name: checkout
      if: steps.cache-openmp.outputs.cache-hit != 'true'
      uses: actions/checkout@v4
    - name: openmp
      if: steps.cache-openmp.outputs.cache-hit != 'true'
      run: |
        wget https://github.com/llvm/llvm-project/releases/download/llvmorg-${{ env.OPENMP_VERSION }}/cmake-${{ env.OPENMP_VERSION }}.src.tar.xz
        tar -xf cmake-${{ env.OPENMP_VERSION }}.src.tar.xz
        wget https://github.com/llvm/llvm-project/releases/download/llvmorg-${{ env.OPENMP_VERSION }}/openmp-${{ env.OPENMP_VERSION }}.src.tar.xz
        tar -xf openmp-${{ env.OPENMP_VERSION }}.src.tar.xz
        mv cmake-${{ env.OPENMP_VERSION }}.src/Modules/* openmp-${{ env.OPENMP_VERSION }}.src/cmake/
        cd openmp-${{ env.OPENMP_VERSION }}.src
        wget https://github.com/nihui/llvm-project/commit/ef8c35bcf5d9cfdb0764ffde6a63c04ec715bc37.patch
        patch -p2 -i ef8c35bcf5d9cfdb0764ffde6a63c04ec715bc37.patch
        wget https://github.com/nihui/llvm-project/commit/5c12711f9a21f41bea70566bf15a4026804d6b20.patch
        patch -p2 -i 5c12711f9a21f41bea70566bf15a4026804d6b20.patch
    - name: build-arm64
      if: steps.cache-openmp.outputs.cache-hit != 'true'
      run: |
        cd openmp-${{ env.OPENMP_VERSION }}.src
        mkdir -p build-arm64 && cd build-arm64
        cmake ${{ env.OPENMP_CMAKE_OPTIONS }} -DPLATFORM=OS64 -DARCHS="arm64" ..
        cmake --build . -j 4
        cmake --build . --target install/strip
    - name: merge-fat-library
      if: steps.cache-openmp.outputs.cache-hit != 'true'
      run: |
        rm -rf $GITHUB_WORKSPACE/openmp-install
        mkdir -p $GITHUB_WORKSPACE/openmp-install
        cp -a openmp-${{ env.OPENMP_VERSION }}.src/build-arm64/install/include $GITHUB_WORKSPACE/openmp-install
        mkdir -p $GITHUB_WORKSPACE/openmp-install/lib
        cp openmp-${{ env.OPENMP_VERSION }}.src/build-arm64/install/lib/libomp.a $GITHUB_WORKSPACE/openmp-install/lib/libomp.a
    - name: upload
      uses: actions/upload-artifact@v4
      with:
        name: openmp-ios
        path: openmp-install

  ios:
    needs: [setup, openmp-ios]
    strategy:
      matrix:
        opt:
          - { vulkan: OFF, id: ios        }
          - { vulkan: ON,  id: ios-vulkan }
    runs-on: macos-13
    env:
      PACKAGENAME: ncnn-${{ needs.setup.outputs.VERSION }}-${{ matrix.opt.id }}
      NCNN_CMAKE_OPTIONS: |
        -DCMAKE_TOOLCHAIN_FILE=../toolchains/ios.toolchain.cmake \
        -DDEPLOYMENT_TARGET=$IOS_DEPLOYMENT_TARGET \
        -DENABLE_BITCODE=$ENABLE_BITCODE \
        -DENABLE_ARC=$ENABLE_ARC \
        -DENABLE_VISIBILITY=$ENABLE_VISIBILITY \
        -DCMAKE_INSTALL_PREFIX=install \
        -DCMAKE_BUILD_TYPE=Release \
        -DOpenMP_C_FLAGS="-Xclang -fopenmp" -DOpenMP_CXX_FLAGS="-Xclang -fopenmp" \
        -DOpenMP_C_LIB_NAMES="libomp" -DOpenMP_CXX_LIB_NAMES="libomp" \
        -DOpenMP_libomp_LIBRARY="libomp.a" \
        -DNCNN_VERSION_STRING="${{ needs.setup.outputs.VERSION }}" \
        -DNCNN_BUILD_BENCHMARK=OFF \
        -DNCNN_VULKAN=${{ matrix.opt.vulkan }} \

    steps:
    - uses: actions/checkout@v4
      with:
        submodules: true
    - name: download-openmp-ios
      uses: actions/download-artifact@v4
      with:
        name: openmp-ios
        path: openmp-ios
    - name: install-openmp
      run: |
        sudo cp openmp-ios/include/* $DEVELOPER_DIR/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include
        sudo cp openmp-ios/lib/libomp.a $DEVELOPER_DIR/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/lib
    - name: build-arm64
      run: |
        mkdir build-arm64 && cd build-arm64
        cmake ${{ env.NCNN_CMAKE_OPTIONS }} -DPLATFORM=OS64 -DARCHS="arm64" ..
        cmake --build . -j 4
        cmake --build . --target install/strip
    - name: package-openmp
      run: |
        rm -rf openmp.framework
        mkdir -p openmp.framework/Versions/A/Headers
        mkdir -p openmp.framework/Versions/A/Resources
        ln -s A openmp.framework/Versions/Current
        ln -s Versions/Current/Headers openmp.framework/Headers
        ln -s Versions/Current/Resources openmp.framework/Resources
        ln -s Versions/Current/openmp openmp.framework/openmp
        cp openmp-ios/lib/libomp.a openmp.framework/Versions/A/openmp
        cp -a openmp-ios/include/* openmp.framework/Versions/A/Headers/
        sed -e 's/__NAME__/openmp/g' -e 's/__IDENTIFIER__/org.llvm.openmp/g' -e 's/__VERSION__/18.1/g' Info.plist > openmp.framework/Versions/A/Resources/Info.plist
    - name: package-glslang
      if: matrix.opt.vulkan == 'ON'
      run: |
        rm -rf glslang.framework
        mkdir -p glslang.framework/Versions/A/Headers
        mkdir -p glslang.framework/Versions/A/Resources
        ln -s A glslang.framework/Versions/Current
        ln -s Versions/Current/Headers glslang.framework/Headers
        ln -s Versions/Current/Resources glslang.framework/Resources
        ln -s Versions/Current/glslang glslang.framework/glslang
        libtool -static \
            build-arm64/install/lib/libglslang.a \
            build-arm64/install/lib/libSPIRV.a \
            -o build-arm64/install/lib/libglslang_combined.a
        cp build-arm64/install/lib/libglslang_combined.a glslang.framework/Versions/A/glslang
        cp -a build-arm64/install/include/glslang glslang.framework/Versions/A/Headers/
        sed -e 's/__NAME__/glslang/g' -e 's/__IDENTIFIER__/org.khronos.glslang/g' -e 's/__VERSION__/1.0/g' Info.plist > glslang.framework/Versions/A/Resources/Info.plist
    - name: package-ncnn
      run: |
        rm -rf ncnn.framework
        mkdir -p ncnn.framework/Versions/A/Headers
        mkdir -p ncnn.framework/Versions/A/Resources
        ln -s A ncnn.framework/Versions/Current
        ln -s Versions/Current/Headers ncnn.framework/Headers
        ln -s Versions/Current/Resources ncnn.framework/Resources
        ln -s Versions/Current/ncnn ncnn.framework/ncnn
        cp build-arm64/install/lib/libncnn.a ncnn.framework/Versions/A/ncnn
        cp -a build-arm64/install/include/* ncnn.framework/Versions/A/Headers/
        sed -e 's/__NAME__/ncnn/g' -e 's/__IDENTIFIER__/com.tencent.ncnn/g' -e 's/__VERSION__/1.0/g' Info.plist > ncnn.framework/Versions/A/Resources/Info.plist
    - name: package
      if: matrix.opt.vulkan == 'OFF'
      run: |
        rm -f ${{ env.PACKAGENAME }}.zip
        zip -9 -y -r ${{ env.PACKAGENAME }}.zip openmp.framework ncnn.framework
    - name: package
      if: matrix.opt.vulkan == 'ON'
      run: |
        rm -f ${{ env.PACKAGENAME }}.zip
        zip -9 -y -r ${{ env.PACKAGENAME }}.zip openmp.framework glslang.framework ncnn.framework
    - name: upload-zip
      uses: actions/upload-artifact@v4
      with:
        name: ${{ env.PACKAGENAME }}
        path: ${{ env.PACKAGENAME }}.zip

  openmp-ios-simulator:
    runs-on: macos-13
    env:
      OPENMP_VERSION: '18.1.2'
      OPENMP_CMAKE_OPTIONS: |
        -DCMAKE_TOOLCHAIN_FILE=../../toolchains/ios.toolchain.cmake \
        -DDEPLOYMENT_TARGET=$IOS_DEPLOYMENT_TARGET \
        -DENABLE_BITCODE=$ENABLE_BITCODE \
        -DENABLE_ARC=$ENABLE_ARC \
        -DENABLE_VISIBILITY=$ENABLE_VISIBILITY \
        -DCMAKE_INSTALL_PREFIX=install \
        -DCMAKE_BUILD_TYPE=Release \
        -DPERL_EXECUTABLE=/usr/local/bin/perl \
        -DLIBOMP_ENABLE_SHARED=OFF \
        -DLIBOMP_OMPT_SUPPORT=OFF \
        -DLIBOMP_USE_HWLOC=OFF \
    steps:
    - name: cache-openmp
      id: cache-openmp
      uses: actions/cache@v4
      with:
        path: openmp-install
        key: openmp-ios-simulator-release-18.1.2-20240403
    - name: checkout
      if: steps.cache-openmp.outputs.cache-hit != 'true'
      uses: actions/checkout@v4
    - name: openmp
      if: steps.cache-openmp.outputs.cache-hit != 'true'
      run: |
        wget https://github.com/llvm/llvm-project/releases/download/llvmorg-${{ env.OPENMP_VERSION }}/cmake-${{ env.OPENMP_VERSION }}.src.tar.xz
        tar -xf cmake-${{ env.OPENMP_VERSION }}.src.tar.xz
        wget https://github.com/llvm/llvm-project/releases/download/llvmorg-${{ env.OPENMP_VERSION }}/openmp-${{ env.OPENMP_VERSION }}.src.tar.xz
        tar -xf openmp-${{ env.OPENMP_VERSION }}.src.tar.xz
        mv cmake-${{ env.OPENMP_VERSION }}.src/Modules/* openmp-${{ env.OPENMP_VERSION }}.src/cmake/
        cd openmp-${{ env.OPENMP_VERSION }}.src
        wget https://github.com/nihui/llvm-project/commit/ef8c35bcf5d9cfdb0764ffde6a63c04ec715bc37.patch
        patch -p2 -i ef8c35bcf5d9cfdb0764ffde6a63c04ec715bc37.patch
        wget https://github.com/nihui/llvm-project/commit/5c12711f9a21f41bea70566bf15a4026804d6b20.patch
        patch -p2 -i 5c12711f9a21f41bea70566bf15a4026804d6b20.patch
    - name: build-x86_64
      if: steps.cache-openmp.outputs.cache-hit != 'true'
      run: |
        cd openmp-${{ env.OPENMP_VERSION }}.src
        mkdir -p build-x86_64 && cd build-x86_64
        cmake ${{ env.OPENMP_CMAKE_OPTIONS }} -DPLATFORM=SIMULATOR64 -DARCHS="x86_64" ..
        cmake --build . -j 4
        cmake --build . --target install/strip
    - name: build-arm64
      if: steps.cache-openmp.outputs.cache-hit != 'true'
      run: |
        cd openmp-${{ env.OPENMP_VERSION }}.src
        mkdir -p build-arm64 && cd build-arm64
        cmake ${{ env.OPENMP_CMAKE_OPTIONS }} -DPLATFORM=SIMULATORARM64 -DARCHS="arm64" ..
        cmake --build . -j 4
        cmake --build . --target install/strip
    - name: merge-fat-library
      if: steps.cache-openmp.outputs.cache-hit != 'true'
      run: |
        rm -rf $GITHUB_WORKSPACE/openmp-install
        mkdir -p $GITHUB_WORKSPACE/openmp-install
        cp -a openmp-${{ env.OPENMP_VERSION }}.src/build-x86_64/install/include $GITHUB_WORKSPACE/openmp-install
        mkdir -p $GITHUB_WORKSPACE/openmp-install/lib
        lipo -create \
            openmp-${{ env.OPENMP_VERSION }}.src/build-x86_64/install/lib/libomp.a \
            openmp-${{ env.OPENMP_VERSION }}.src/build-arm64/install/lib/libomp.a \
            -o $GITHUB_WORKSPACE/openmp-install/lib/libomp.a
    - name: upload
      uses: actions/upload-artifact@v4
      with:
        name: openmp-ios-simulator
        path: openmp-install

  ios-simulator:
    needs: [setup, openmp-ios-simulator]
    strategy:
      matrix:
        opt:
          - { vulkan: OFF, id: ios-simulator        }
          - { vulkan: ON,  id: ios-simulator-vulkan }
    runs-on: macos-13
    env:
      PACKAGENAME: ncnn-${{ needs.setup.outputs.VERSION }}-${{ matrix.opt.id }}
      NCNN_CMAKE_OPTIONS: |
        -DCMAKE_TOOLCHAIN_FILE=../toolchains/ios.toolchain.cmake \
        -DDEPLOYMENT_TARGET=$IOS_DEPLOYMENT_TARGET \
        -DENABLE_BITCODE=$ENABLE_BITCODE \
        -DENABLE_ARC=$ENABLE_ARC \
        -DENABLE_VISIBILITY=$ENABLE_VISIBILITY \
        -DCMAKE_INSTALL_PREFIX=install \
        -DCMAKE_BUILD_TYPE=Release \
        -DOpenMP_C_FLAGS="-Xclang -fopenmp" -DOpenMP_CXX_FLAGS="-Xclang -fopenmp" \
        -DOpenMP_C_LIB_NAMES="libomp" -DOpenMP_CXX_LIB_NAMES="libomp" \
        -DOpenMP_libomp_LIBRARY="libomp.a" \
        -DNCNN_VERSION_STRING="${{ needs.setup.outputs.VERSION }}" \
        -DNCNN_BUILD_BENCHMARK=OFF \
        -DNCNN_VULKAN=${{ matrix.opt.vulkan }} \

    steps:
    - uses: actions/checkout@v4
      with:
        submodules: true
    - name: download-openmp-ios-simulator
      uses: actions/download-artifact@v4
      with:
        name: openmp-ios-simulator
        path: openmp-ios-simulator
    - name: install-openmp
      run: |
        sudo cp openmp-ios-simulator/include/* $DEVELOPER_DIR/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/usr/include
        sudo cp openmp-ios-simulator/lib/libomp.a $DEVELOPER_DIR/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/usr/lib
    - name: build-x86_64
      run: |
        mkdir build-x86_64 && cd build-x86_64
        cmake ${{ env.NCNN_CMAKE_OPTIONS }} -DPLATFORM=SIMULATOR64 -DARCHS="x86_64" ..
        cmake --build . -j 4
        cmake --build . --target install/strip
    - name: build-arm64
      run: |
        mkdir build-arm64 && cd build-arm64
        cmake ${{ env.NCNN_CMAKE_OPTIONS }} -DPLATFORM=SIMULATORARM64 -DARCHS="arm64" ..
        cmake --build . -j 4
        cmake --build . --target install/strip
    - name: package-openmp
      run: |
        rm -rf openmp.framework
        mkdir -p openmp.framework/Versions/A/Headers
        mkdir -p openmp.framework/Versions/A/Resources
        ln -s A openmp.framework/Versions/Current
        ln -s Versions/Current/Headers openmp.framework/Headers
        ln -s Versions/Current/Resources openmp.framework/Resources
        ln -s Versions/Current/openmp openmp.framework/openmp
        cp openmp-ios-simulator/lib/libomp.a openmp.framework/Versions/A/openmp
        cp -a openmp-ios-simulator/include/* openmp.framework/Versions/A/Headers/
        sed -e 's/__NAME__/openmp/g' -e 's/__IDENTIFIER__/org.llvm.openmp/g' -e 's/__VERSION__/18.1/g' Info.plist > openmp.framework/Versions/A/Resources/Info.plist
    - name: package-glslang
      if: matrix.opt.vulkan == 'ON'
      run: |
        rm -rf glslang.framework
        mkdir -p glslang.framework/Versions/A/Headers
        mkdir -p glslang.framework/Versions/A/Resources
        ln -s A glslang.framework/Versions/Current
        ln -s Versions/Current/Headers glslang.framework/Headers
        ln -s Versions/Current/Resources glslang.framework/Resources
        ln -s Versions/Current/glslang glslang.framework/glslang
        libtool -static \
            build-x86_64/install/lib/libglslang.a \
            build-x86_64/install/lib/libSPIRV.a \
            -o build-x86_64/install/lib/libglslang_combined.a
        libtool -static \
            build-arm64/install/lib/libglslang.a \
            build-arm64/install/lib/libSPIRV.a \
            -o build-arm64/install/lib/libglslang_combined.a
        lipo -create \
            build-x86_64/install/lib/libglslang_combined.a \
            build-arm64/install/lib/libglslang_combined.a \
            -o glslang.framework/Versions/A/glslang
        cp -a build-x86_64/install/include/glslang glslang.framework/Versions/A/Headers/
        sed -e 's/__NAME__/glslang/g' -e 's/__IDENTIFIER__/org.khronos.glslang/g' -e 's/__VERSION__/1.0/g' Info.plist > glslang.framework/Versions/A/Resources/Info.plist
    - name: package-ncnn
      run: |
        rm -rf ncnn.framework
        mkdir -p ncnn.framework/Versions/A/Headers
        mkdir -p ncnn.framework/Versions/A/Resources
        ln -s A ncnn.framework/Versions/Current
        ln -s Versions/Current/Headers ncnn.framework/Headers
        ln -s Versions/Current/Resources ncnn.framework/Resources
        ln -s Versions/Current/ncnn ncnn.framework/ncnn
        lipo -create \
            build-x86_64/install/lib/libncnn.a \
            build-arm64/install/lib/libncnn.a \
            -o ncnn.framework/Versions/A/ncnn
        cp -a build-x86_64/install/include/* ncnn.framework/Versions/A/Headers/
        sed -e 's/__NAME__/ncnn/g' -e 's/__IDENTIFIER__/com.tencent.ncnn/g' -e 's/__VERSION__/1.0/g' Info.plist > ncnn.framework/Versions/A/Resources/Info.plist
    - name: package
      if: matrix.opt.vulkan == 'OFF'
      run: |
        rm -f ${{ env.PACKAGENAME }}.zip
        zip -9 -y -r ${{ env.PACKAGENAME }}.zip openmp.framework ncnn.framework
    - name: package
      if: matrix.opt.vulkan == 'ON'
      run: |
        rm -f ${{ env.PACKAGENAME }}.zip
        zip -9 -y -r ${{ env.PACKAGENAME }}.zip openmp.framework glslang.framework ncnn.framework
    - name: upload-zip
      uses: actions/upload-artifact@v4
      with:
        name: ${{ env.PACKAGENAME }}
        path: ${{ env.PACKAGENAME }}.zip

  openmp-mac-catalyst:
    runs-on: macos-13
    env:
      OPENMP_VERSION: '18.1.2'
      OPENMP_CMAKE_OPTIONS: |
        -DCMAKE_TOOLCHAIN_FILE=../../toolchains/ios.toolchain.cmake \
        -DDEPLOYMENT_TARGET=$MAC_CATALYST_DEPLOYMENT_TARGET \
        -DENABLE_BITCODE=$ENABLE_BITCODE \
        -DENABLE_ARC=$ENABLE_ARC \
        -DENABLE_VISIBILITY=$ENABLE_VISIBILITY \
        -DCMAKE_INSTALL_PREFIX=install \
        -DCMAKE_BUILD_TYPE=Release \
        -DPERL_EXECUTABLE=/usr/local/bin/perl \
        -DLIBOMP_ENABLE_SHARED=OFF \
        -DLIBOMP_OMPT_SUPPORT=OFF \
        -DLIBOMP_USE_HWLOC=OFF \
    steps:
    - name: cache-openmp
      id: cache-openmp
      uses: actions/cache@v4
      with:
        path: openmp-install
        key: openmp-mac-catalyst-release-18.1.2-20240403
    - name: checkout
      if: steps.cache-openmp.outputs.cache-hit != 'true'
      uses: actions/checkout@v4
    - name: openmp
      if: steps.cache-openmp.outputs.cache-hit != 'true'
      run: |
        wget https://github.com/llvm/llvm-project/releases/download/llvmorg-${{ env.OPENMP_VERSION }}/cmake-${{ env.OPENMP_VERSION }}.src.tar.xz
        tar -xf cmake-${{ env.OPENMP_VERSION }}.src.tar.xz
        wget https://github.com/llvm/llvm-project/releases/download/llvmorg-${{ env.OPENMP_VERSION }}/openmp-${{ env.OPENMP_VERSION }}.src.tar.xz
        tar -xf openmp-${{ env.OPENMP_VERSION }}.src.tar.xz
        mv cmake-${{ env.OPENMP_VERSION }}.src/Modules/* openmp-${{ env.OPENMP_VERSION }}.src/cmake/
        cd openmp-${{ env.OPENMP_VERSION }}.src
        wget https://github.com/nihui/llvm-project/commit/ef8c35bcf5d9cfdb0764ffde6a63c04ec715bc37.patch
        patch -p2 -i ef8c35bcf5d9cfdb0764ffde6a63c04ec715bc37.patch
        wget https://github.com/nihui/llvm-project/commit/5c12711f9a21f41bea70566bf15a4026804d6b20.patch
        patch -p2 -i 5c12711f9a21f41bea70566bf15a4026804d6b20.patch
    - name: build-x86_64
      if: steps.cache-openmp.outputs.cache-hit != 'true'
      run: |
        cd openmp-${{ env.OPENMP_VERSION }}.src
        mkdir -p build-x86_64 && cd build-x86_64
        cmake ${{ env.OPENMP_CMAKE_OPTIONS }} -DPLATFORM=MAC_CATALYST -DARCHS="x86_64" ..
        cmake --build . -j 4
        cmake --build . --target install/strip
    - name: build-arm64
      if: steps.cache-openmp.outputs.cache-hit != 'true'
      run: |
        cd openmp-${{ env.OPENMP_VERSION }}.src
        mkdir -p build-arm64 && cd build-arm64
        cmake ${{ env.OPENMP_CMAKE_OPTIONS }} -DPLATFORM=MAC_CATALYST_ARM64 -DARCHS="arm64" ..
        cmake --build . -j 4
        cmake --build . --target install/strip
    - name: merge-fat-library
      if: steps.cache-openmp.outputs.cache-hit != 'true'
      run: |
        rm -rf $GITHUB_WORKSPACE/openmp-install
        mkdir -p $GITHUB_WORKSPACE/openmp-install
        cp -a openmp-${{ env.OPENMP_VERSION }}.src/build-x86_64/install/include $GITHUB_WORKSPACE/openmp-install
        mkdir -p $GITHUB_WORKSPACE/openmp-install/lib
        lipo -create \
            openmp-${{ env.OPENMP_VERSION }}.src/build-x86_64/install/lib/libomp.a \
            openmp-${{ env.OPENMP_VERSION }}.src/build-arm64/install/lib/libomp.a \
            -o $GITHUB_WORKSPACE/openmp-install/lib/libomp.a
    - name: upload
      uses: actions/upload-artifact@v4
      with:
        name: openmp-mac-catalyst
        path: openmp-install

  mac-catalyst:
    needs: [setup, openmp-mac-catalyst]
    strategy:
      matrix:
        opt:
          - { vulkan: OFF, id: mac-catalyst        }
          - { vulkan: ON,  id: mac-catalyst-vulkan }
    runs-on: macos-13
    env:
      PACKAGENAME: ncnn-${{ needs.setup.outputs.VERSION }}-${{ matrix.opt.id }}
      NCNN_CMAKE_OPTIONS: |
        -DCMAKE_TOOLCHAIN_FILE=../toolchains/ios.toolchain.cmake \
        -DDEPLOYMENT_TARGET=$MAC_CATALYST_DEPLOYMENT_TARGET \
        -DENABLE_BITCODE=$ENABLE_BITCODE \
        -DENABLE_ARC=$ENABLE_ARC \
        -DENABLE_VISIBILITY=$ENABLE_VISIBILITY \
        -DCMAKE_INSTALL_PREFIX=install \
        -DCMAKE_BUILD_TYPE=Release \
        -DOpenMP_C_FLAGS="-Xclang -fopenmp" -DOpenMP_CXX_FLAGS="-Xclang -fopenmp" \
        -DOpenMP_C_LIB_NAMES="libomp" -DOpenMP_CXX_LIB_NAMES="libomp" \
        -DOpenMP_libomp_LIBRARY="libomp.a" \
        -DNCNN_VERSION_STRING="${{ needs.setup.outputs.VERSION }}" \
        -DNCNN_BUILD_BENCHMARK=OFF \
        -DNCNN_VULKAN=${{ matrix.opt.vulkan }} \

    steps:
    - uses: actions/checkout@v4
      with:
        submodules: true
    - name: download-openmp-mac-catalyst
      uses: actions/download-artifact@v4
      with:
        name: openmp-mac-catalyst
        path: openmp-mac-catalyst
    - name: install-openmp
      run: |
        sudo cp openmp-mac-catalyst/include/* $DEVELOPER_DIR/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include
        sudo cp openmp-mac-catalyst/lib/libomp.a $DEVELOPER_DIR/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/lib
    - name: build-x86_64
      run: |
        mkdir build-x86_64 && cd build-x86_64
        cmake ${{ env.NCNN_CMAKE_OPTIONS }} -DPLATFORM=MAC_CATALYST -DARCHS="x86_64" ..
        cmake --build . -j 4
        cmake --build . --target install/strip
    - name: build-arm64
      run: |
        mkdir build-arm64 && cd build-arm64
        cmake ${{ env.NCNN_CMAKE_OPTIONS }} -DPLATFORM=MAC_CATALYST -DARCHS="arm64" ..
        cmake --build . -j 4
        cmake --build . --target install/strip
    - name: package-openmp
      run: |
        rm -rf openmp.framework
        mkdir -p openmp.framework/Versions/A/Headers
        mkdir -p openmp.framework/Versions/A/Resources
        ln -s A openmp.framework/Versions/Current
        ln -s Versions/Current/Headers openmp.framework/Headers
        ln -s Versions/Current/Resources openmp.framework/Resources
        ln -s Versions/Current/openmp openmp.framework/openmp
        cp openmp-mac-catalyst/lib/libomp.a openmp.framework/Versions/A/openmp
        cp -a openmp-mac-catalyst/include/* openmp.framework/Versions/A/Headers/
        sed -e 's/__NAME__/openmp/g' -e 's/__IDENTIFIER__/org.llvm.openmp/g' -e 's/__VERSION__/18.1/g' Info.plist > openmp.framework/Versions/A/Resources/Info.plist
    - name: package-glslang
      if: matrix.opt.vulkan == 'ON'
      run: |
        rm -rf glslang.framework
        mkdir -p glslang.framework/Versions/A/Headers
        mkdir -p glslang.framework/Versions/A/Resources
        ln -s A glslang.framework/Versions/Current
        ln -s Versions/Current/Headers glslang.framework/Headers
        ln -s Versions/Current/Resources glslang.framework/Resources
        ln -s Versions/Current/glslang glslang.framework/glslang
        libtool -static \
            build-x86_64/install/lib/libglslang.a \
            build-x86_64/install/lib/libSPIRV.a \
            -o build-x86_64/install/lib/libglslang_combined.a
        libtool -static \
            build-arm64/install/lib/libglslang.a \
            build-arm64/install/lib/libSPIRV.a \
            -o build-arm64/install/lib/libglslang_combined.a
        lipo -create \
            build-x86_64/install/lib/libglslang_combined.a \
            build-arm64/install/lib/libglslang_combined.a \
            -o glslang.framework/Versions/A/glslang
        cp -a build-x86_64/install/include/glslang glslang.framework/Versions/A/Headers/
        sed -e 's/__NAME__/glslang/g' -e 's/__IDENTIFIER__/org.khronos.glslang/g' -e 's/__VERSION__/1.0/g' Info.plist > glslang.framework/Versions/A/Resources/Info.plist
    - name: package-ncnn
      run: |
        rm -rf ncnn.framework
        mkdir -p ncnn.framework/Versions/A/Headers
        mkdir -p ncnn.framework/Versions/A/Resources
        ln -s A ncnn.framework/Versions/Current
        ln -s Versions/Current/Headers ncnn.framework/Headers
        ln -s Versions/Current/Resources ncnn.framework/Resources
        ln -s Versions/Current/ncnn ncnn.framework/ncnn
        lipo -create \
            build-x86_64/install/lib/libncnn.a \
            build-arm64/install/lib/libncnn.a \
            -o ncnn.framework/Versions/A/ncnn
        cp -a build-x86_64/install/include/* ncnn.framework/Versions/A/Headers/
        sed -e 's/__NAME__/ncnn/g' -e 's/__IDENTIFIER__/com.tencent.ncnn/g' -e 's/__VERSION__/1.0/g' Info.plist > ncnn.framework/Versions/A/Resources/Info.plist
    - name: package
      if: matrix.opt.vulkan == 'OFF'
      run: |
        rm -f ${{ env.PACKAGENAME }}.zip
        zip -9 -y -r ${{ env.PACKAGENAME }}.zip openmp.framework ncnn.framework
    - name: package
      if: matrix.opt.vulkan == 'ON'
      run: |
        rm -f ${{ env.PACKAGENAME }}.zip
        zip -9 -y -r ${{ env.PACKAGENAME }}.zip openmp.framework glslang.framework ncnn.framework
    - name: upload-zip
      uses: actions/upload-artifact@v4
      with:
        name: ${{ env.PACKAGENAME }}
        path: ${{ env.PACKAGENAME }}.zip

  openmp-watchos:
    runs-on: macos-13
    env:
      OPENMP_VERSION: '18.1.2'
      OPENMP_CMAKE_OPTIONS: |
        -DCMAKE_TOOLCHAIN_FILE=../../toolchains/ios.toolchain.cmake \
        -DDEPLOYMENT_TARGET=$WATCHOS_DEPLOYMENT_TARGET \
        -DENABLE_BITCODE=$ENABLE_BITCODE \
        -DENABLE_ARC=$ENABLE_ARC \
        -DENABLE_VISIBILITY=$ENABLE_VISIBILITY \
        -DCMAKE_INSTALL_PREFIX=install \
        -DCMAKE_BUILD_TYPE=Release \
        -DPERL_EXECUTABLE=/usr/local/bin/perl \
        -DLIBOMP_ENABLE_SHARED=OFF \
        -DLIBOMP_OMPT_SUPPORT=OFF \
        -DLIBOMP_USE_HWLOC=OFF \
    steps:
    - name: cache-openmp
      id: cache-openmp
      uses: actions/cache@v4
      with:
        path: openmp-install
        key: openmp-watchos-release-18.1.2-20240403
    - name: checkout
      if: steps.cache-openmp.outputs.cache-hit != 'true'
      uses: actions/checkout@v4
    - name: openmp
      if: steps.cache-openmp.outputs.cache-hit != 'true'
      run: |
        wget https://github.com/llvm/llvm-project/releases/download/llvmorg-${{ env.OPENMP_VERSION }}/cmake-${{ env.OPENMP_VERSION }}.src.tar.xz
        tar -xf cmake-${{ env.OPENMP_VERSION }}.src.tar.xz
        wget https://github.com/llvm/llvm-project/releases/download/llvmorg-${{ env.OPENMP_VERSION }}/openmp-${{ env.OPENMP_VERSION }}.src.tar.xz
        tar -xf openmp-${{ env.OPENMP_VERSION }}.src.tar.xz
        mv cmake-${{ env.OPENMP_VERSION }}.src/Modules/* openmp-${{ env.OPENMP_VERSION }}.src/cmake/
        cd openmp-${{ env.OPENMP_VERSION }}.src
        wget https://github.com/nihui/llvm-project/commit/ef8c35bcf5d9cfdb0764ffde6a63c04ec715bc37.patch
        patch -p2 -i ef8c35bcf5d9cfdb0764ffde6a63c04ec715bc37.patch
        wget https://github.com/nihui/llvm-project/commit/5c12711f9a21f41bea70566bf15a4026804d6b20.patch
        patch -p2 -i 5c12711f9a21f41bea70566bf15a4026804d6b20.patch
    - name: build-armv7k
      if: steps.cache-openmp.outputs.cache-hit != 'true'
      run: |
        cd openmp-${{ env.OPENMP_VERSION }}.src
        mkdir -p build-armv7k && cd build-armv7k
        cmake ${{ env.OPENMP_CMAKE_OPTIONS }} -DPLATFORM=WATCHOS -DARCHS="armv7k" ..
        cmake --build . -j 4
        cmake --build . --target install/strip
    - name: build-arm64_32
      if: steps.cache-openmp.outputs.cache-hit != 'true'
      run: |
        cd openmp-${{ env.OPENMP_VERSION }}.src
        mkdir -p build-arm64_32 && cd build-arm64_32
        cmake ${{ env.OPENMP_CMAKE_OPTIONS }} -DPLATFORM=WATCHOS -DARCHS="arm64_32" ..
        cmake --build . -j 4
        cmake --build . --target install/strip
    - name: merge-fat-library
      if: steps.cache-openmp.outputs.cache-hit != 'true'
      run: |
        rm -rf $GITHUB_WORKSPACE/openmp-install
        mkdir -p $GITHUB_WORKSPACE/openmp-install
        cp -a openmp-${{ env.OPENMP_VERSION }}.src/build-arm64_32/install/include $GITHUB_WORKSPACE/openmp-install
        mkdir -p $GITHUB_WORKSPACE/openmp-install/lib
        lipo -create \
            openmp-${{ env.OPENMP_VERSION }}.src/build-armv7k/install/lib/libomp.a \
            openmp-${{ env.OPENMP_VERSION }}.src/build-arm64_32/install/lib/libomp.a \
            -o $GITHUB_WORKSPACE/openmp-install/lib/libomp.a
    - name: upload
      uses: actions/upload-artifact@v4
      with:
        name: openmp-watchos
        path: openmp-install

  watchos:
    needs: [setup, openmp-watchos]
    runs-on: macos-13
    env:
      PACKAGENAME: ncnn-${{ needs.setup.outputs.VERSION }}-watchos
      NCNN_CMAKE_OPTIONS: |
        -DCMAKE_TOOLCHAIN_FILE=../toolchains/ios.toolchain.cmake \
        -DDEPLOYMENT_TARGET=$WATCHOS_DEPLOYMENT_TARGET \
        -DENABLE_BITCODE=$ENABLE_BITCODE \
        -DENABLE_ARC=$ENABLE_ARC \
        -DENABLE_VISIBILITY=$ENABLE_VISIBILITY \
        -DCMAKE_INSTALL_PREFIX=install \
        -DCMAKE_BUILD_TYPE=Release \
        -DOpenMP_C_FLAGS="-Xclang -fopenmp" -DOpenMP_CXX_FLAGS="-Xclang -fopenmp" \
        -DOpenMP_C_LIB_NAMES="libomp" -DOpenMP_CXX_LIB_NAMES="libomp" \
        -DOpenMP_libomp_LIBRARY="libomp.a" \
        -DNCNN_VERSION_STRING="${{ needs.setup.outputs.VERSION }}" \
        -DNCNN_BUILD_BENCHMARK=OFF \

    steps:
    - uses: actions/checkout@v4
    - name: download-openmp-watchos
      uses: actions/download-artifact@v4
      with:
        name: openmp-watchos
        path: openmp-watchos
    - name: install-openmp
      run: |
        sudo cp openmp-watchos/include/* $DEVELOPER_DIR/Platforms/WatchOS.platform/Developer/SDKs/WatchOS.sdk/usr/include
        sudo cp openmp-watchos/lib/libomp.a $DEVELOPER_DIR/Platforms/WatchOS.platform/Developer/SDKs/WatchOS.sdk/usr/lib
    - name: build-armv7k
      run: |
        mkdir build-armv7k && cd build-armv7k
        cmake ${{ env.NCNN_CMAKE_OPTIONS }} -DPLATFORM=WATCHOS -DARCHS="armv7k" ..
        cmake --build . -j 4
        cmake --build . --target install/strip
    - name: build-arm64_32
      run: |
        mkdir build-arm64_32 && cd build-arm64_32
        cmake ${{ env.NCNN_CMAKE_OPTIONS }} -DPLATFORM=WATCHOS -DARCHS="arm64_32" ..
        cmake --build . -j 4
        cmake --build . --target install/strip
    - name: package-openmp
      run: |
        rm -rf openmp.framework
        mkdir -p openmp.framework/Versions/A/Headers
        mkdir -p openmp.framework/Versions/A/Resources
        ln -s A openmp.framework/Versions/Current
        ln -s Versions/Current/Headers openmp.framework/Headers
        ln -s Versions/Current/Resources openmp.framework/Resources
        ln -s Versions/Current/openmp openmp.framework/openmp
        cp openmp-watchos/lib/libomp.a openmp.framework/Versions/A/openmp
        cp -a openmp-watchos/include/* openmp.framework/Versions/A/Headers/
        sed -e 's/__NAME__/openmp/g' -e 's/__IDENTIFIER__/org.llvm.openmp/g' -e 's/__VERSION__/18.1/g' Info.plist > openmp.framework/Versions/A/Resources/Info.plist
    - name: package
      run: |
        rm -rf ncnn.framework
        mkdir -p ncnn.framework/Versions/A/Headers
        mkdir -p ncnn.framework/Versions/A/Resources
        ln -s A ncnn.framework/Versions/Current
        ln -s Versions/Current/Headers ncnn.framework/Headers
        ln -s Versions/Current/Resources ncnn.framework/Resources
        ln -s Versions/Current/ncnn ncnn.framework/ncnn
        lipo -create \
            build-armv7k/install/lib/libncnn.a \
            build-arm64_32/install/lib/libncnn.a \
            -o ncnn.framework/Versions/A/ncnn
        cp -a build-arm64_32/install/include/* ncnn.framework/Versions/A/Headers/
        sed -e 's/__NAME__/ncnn/g' -e 's/__IDENTIFIER__/com.tencent.ncnn/g' -e 's/__VERSION__/1.0/g' Info.plist > ncnn.framework/Versions/A/Resources/Info.plist
        rm -f ${{ env.PACKAGENAME }}.zip
        zip -9 -y -r ${{ env.PACKAGENAME }}.zip openmp.framework ncnn.framework
    - name: upload-zip
      uses: actions/upload-artifact@v4
      with:
        name: ${{ env.PACKAGENAME }}
        path: ${{ env.PACKAGENAME }}.zip

  openmp-watchos-simulator:
    runs-on: macos-13
    env:
      OPENMP_VERSION: '18.1.2'
      OPENMP_CMAKE_OPTIONS: |
        -DCMAKE_TOOLCHAIN_FILE=../../toolchains/ios.toolchain.cmake \
        -DDEPLOYMENT_TARGET=$WATCHOS_DEPLOYMENT_TARGET \
        -DENABLE_BITCODE=$ENABLE_BITCODE \
        -DENABLE_ARC=$ENABLE_ARC \
        -DENABLE_VISIBILITY=$ENABLE_VISIBILITY \
        -DCMAKE_INSTALL_PREFIX=install \
        -DCMAKE_BUILD_TYPE=Release \
        -DPERL_EXECUTABLE=/usr/local/bin/perl \
        -DLIBOMP_ENABLE_SHARED=OFF \
        -DLIBOMP_OMPT_SUPPORT=OFF \
        -DLIBOMP_USE_HWLOC=OFF \
    steps:
    - name: cache-openmp
      id: cache-openmp
      uses: actions/cache@v4
      with:
        path: openmp-install
        key: openmp-watchos-simulator-release-18.1.2-20240403
    - name: checkout
      if: steps.cache-openmp.outputs.cache-hit != 'true'
      uses: actions/checkout@v4
    - name: openmp
      if: steps.cache-openmp.outputs.cache-hit != 'true'
      run: |
        wget https://github.com/llvm/llvm-project/releases/download/llvmorg-${{ env.OPENMP_VERSION }}/cmake-${{ env.OPENMP_VERSION }}.src.tar.xz
        tar -xf cmake-${{ env.OPENMP_VERSION }}.src.tar.xz
        wget https://github.com/llvm/llvm-project/releases/download/llvmorg-${{ env.OPENMP_VERSION }}/openmp-${{ env.OPENMP_VERSION }}.src.tar.xz
        tar -xf openmp-${{ env.OPENMP_VERSION }}.src.tar.xz
        mv cmake-${{ env.OPENMP_VERSION }}.src/Modules/* openmp-${{ env.OPENMP_VERSION }}.src/cmake/
        cd openmp-${{ env.OPENMP_VERSION }}.src
        wget https://github.com/nihui/llvm-project/commit/ef8c35bcf5d9cfdb0764ffde6a63c04ec715bc37.patch
        patch -p2 -i ef8c35bcf5d9cfdb0764ffde6a63c04ec715bc37.patch
        wget https://github.com/nihui/llvm-project/commit/5c12711f9a21f41bea70566bf15a4026804d6b20.patch
        patch -p2 -i 5c12711f9a21f41bea70566bf15a4026804d6b20.patch
    - name: build-x86_64
      if: steps.cache-openmp.outputs.cache-hit != 'true'
      run: |
        cd openmp-${{ env.OPENMP_VERSION }}.src
        mkdir -p build-x86_64 && cd build-x86_64
        cmake ${{ env.OPENMP_CMAKE_OPTIONS }} -DPLATFORM=SIMULATOR_WATCHOS -DARCHS="x86_64" ..
        cmake --build . -j 4
        cmake --build . --target install/strip
    - name: build-arm64
      if: steps.cache-openmp.outputs.cache-hit != 'true'
      run: |
        cd openmp-${{ env.OPENMP_VERSION }}.src
        mkdir -p build-arm64 && cd build-arm64
        cmake ${{ env.OPENMP_CMAKE_OPTIONS }} -DPLATFORM=SIMULATOR_WATCHOS -DARCHS="arm64" ..
        cmake --build . -j 4
        cmake --build . --target install/strip
    - name: merge-fat-library
      if: steps.cache-openmp.outputs.cache-hit != 'true'
      run: |
        rm -rf $GITHUB_WORKSPACE/openmp-install
        mkdir -p $GITHUB_WORKSPACE/openmp-install
        cp -a openmp-${{ env.OPENMP_VERSION }}.src/build-x86_64/install/include $GITHUB_WORKSPACE/openmp-install
        mkdir -p $GITHUB_WORKSPACE/openmp-install/lib
        lipo -create \
            openmp-${{ env.OPENMP_VERSION }}.src/build-x86_64/install/lib/libomp.a \
            openmp-${{ env.OPENMP_VERSION }}.src/build-arm64/install/lib/libomp.a \
            -o $GITHUB_WORKSPACE/openmp-install/lib/libomp.a
    - name: upload
      uses: actions/upload-artifact@v4
      with:
        name: openmp-watchos-simulator
        path: openmp-install

  watchos-simulator:
    needs: [setup, openmp-watchos-simulator]
    runs-on: macos-13
    env:
      PACKAGENAME: ncnn-${{ needs.setup.outputs.VERSION }}-watchos-simulator
      NCNN_CMAKE_OPTIONS: |
        -DCMAKE_TOOLCHAIN_FILE=../toolchains/ios.toolchain.cmake \
        -DDEPLOYMENT_TARGET=$WATCHOS_DEPLOYMENT_TARGET \
        -DENABLE_BITCODE=$ENABLE_BITCODE \
        -DENABLE_ARC=$ENABLE_ARC \
        -DENABLE_VISIBILITY=$ENABLE_VISIBILITY \
        -DCMAKE_INSTALL_PREFIX=install \
        -DCMAKE_BUILD_TYPE=Release \
        -DOpenMP_C_FLAGS="-Xclang -fopenmp" -DOpenMP_CXX_FLAGS="-Xclang -fopenmp" \
        -DOpenMP_C_LIB_NAMES="libomp" -DOpenMP_CXX_LIB_NAMES="libomp" \
        -DOpenMP_libomp_LIBRARY="libomp.a" \
        -DNCNN_VERSION_STRING="${{ needs.setup.outputs.VERSION }}" \
        -DNCNN_BUILD_BENCHMARK=OFF \

    steps:
    - uses: actions/checkout@v4
    - name: download-openmp-watchos-simulator
      uses: actions/download-artifact@v4
      with:
        name: openmp-watchos-simulator
        path: openmp-watchos-simulator
    - name: install-openmp
      run: |
        sudo cp openmp-watchos-simulator/include/* $DEVELOPER_DIR/Platforms/WatchSimulator.platform/Developer/SDKs/WatchSimulator.sdk/usr/include
        sudo cp openmp-watchos-simulator/lib/libomp.a $DEVELOPER_DIR/Platforms/WatchSimulator.platform/Developer/SDKs/WatchSimulator.sdk/usr/lib
    - name: build-x86_64
      run: |
        mkdir build-x86_64 && cd build-x86_64
        cmake ${{ env.NCNN_CMAKE_OPTIONS }} -DPLATFORM=SIMULATOR_WATCHOS -DARCHS="x86_64" ..
        cmake --build . -j 4
        cmake --build . --target install/strip
    - name: build-arm64
      run: |
        mkdir build-arm64 && cd build-arm64
        cmake ${{ env.NCNN_CMAKE_OPTIONS }} -DPLATFORM=SIMULATOR_WATCHOS -DARCHS="arm64" ..
        cmake --build . -j 4
        cmake --build . --target install/strip
    - name: package-openmp
      run: |
        rm -rf openmp.framework
        mkdir -p openmp.framework/Versions/A/Headers
        mkdir -p openmp.framework/Versions/A/Resources
        ln -s A openmp.framework/Versions/Current
        ln -s Versions/Current/Headers openmp.framework/Headers
        ln -s Versions/Current/Resources openmp.framework/Resources
        ln -s Versions/Current/openmp openmp.framework/openmp
        cp openmp-watchos-simulator/lib/libomp.a openmp.framework/Versions/A/openmp
        cp -a openmp-watchos-simulator/include/* openmp.framework/Versions/A/Headers/
        sed -e 's/__NAME__/openmp/g' -e 's/__IDENTIFIER__/org.llvm.openmp/g' -e 's/__VERSION__/18.1/g' Info.plist > openmp.framework/Versions/A/Resources/Info.plist
    - name: package
      run: |
        rm -rf ncnn.framework
        mkdir -p ncnn.framework/Versions/A/Headers
        mkdir -p ncnn.framework/Versions/A/Resources
        ln -s A ncnn.framework/Versions/Current
        ln -s Versions/Current/Headers ncnn.framework/Headers
        ln -s Versions/Current/Resources ncnn.framework/Resources
        ln -s Versions/Current/ncnn ncnn.framework/ncnn
        lipo -create \
            build-x86_64/install/lib/libncnn.a \
            build-arm64/install/lib/libncnn.a \
            -o ncnn.framework/Versions/A/ncnn
        cp -a build-x86_64/install/include/* ncnn.framework/Versions/A/Headers/
        sed -e 's/__NAME__/ncnn/g' -e 's/__IDENTIFIER__/com.tencent.ncnn/g' -e 's/__VERSION__/1.0/g' Info.plist > ncnn.framework/Versions/A/Resources/Info.plist
        rm -f ${{ env.PACKAGENAME }}.zip
        zip -9 -y -r ${{ env.PACKAGENAME }}.zip openmp.framework ncnn.framework
    - name: upload-zip
      uses: actions/upload-artifact@v4
      with:
        name: ${{ env.PACKAGENAME }}
        path: ${{ env.PACKAGENAME }}.zip

  openmp-tvos:
    runs-on: macos-13
    env:
      OPENMP_VERSION: '18.1.2'
      OPENMP_CMAKE_OPTIONS: |
        -DCMAKE_TOOLCHAIN_FILE=../../toolchains/ios.toolchain.cmake \
        -DDEPLOYMENT_TARGET=$TVOS_DEPLOYMENT_TARGET \
        -DENABLE_BITCODE=$ENABLE_BITCODE \
        -DENABLE_ARC=$ENABLE_ARC \
        -DENABLE_VISIBILITY=$ENABLE_VISIBILITY \
        -DCMAKE_INSTALL_PREFIX=install \
        -DCMAKE_BUILD_TYPE=Release \
        -DPERL_EXECUTABLE=/usr/local/bin/perl \
        -DLIBOMP_ENABLE_SHARED=OFF \
        -DLIBOMP_OMPT_SUPPORT=OFF \
        -DLIBOMP_USE_HWLOC=OFF \
    steps:
    - name: cache-openmp
      id: cache-openmp
      uses: actions/cache@v4
      with:
        path: openmp-install
        key: openmp-tvos-release-18.1.2-20240403
    - name: checkout
      if: steps.cache-openmp.outputs.cache-hit != 'true'
      uses: actions/checkout@v4
    - name: openmp
      if: steps.cache-openmp.outputs.cache-hit != 'true'
      run: |
        wget https://github.com/llvm/llvm-project/releases/download/llvmorg-${{ env.OPENMP_VERSION }}/cmake-${{ env.OPENMP_VERSION }}.src.tar.xz
        tar -xf cmake-${{ env.OPENMP_VERSION }}.src.tar.xz
        wget https://github.com/llvm/llvm-project/releases/download/llvmorg-${{ env.OPENMP_VERSION }}/openmp-${{ env.OPENMP_VERSION }}.src.tar.xz
        tar -xf openmp-${{ env.OPENMP_VERSION }}.src.tar.xz
        mv cmake-${{ env.OPENMP_VERSION }}.src/Modules/* openmp-${{ env.OPENMP_VERSION }}.src/cmake/
        cd openmp-${{ env.OPENMP_VERSION }}.src
        wget https://github.com/nihui/llvm-project/commit/ef8c35bcf5d9cfdb0764ffde6a63c04ec715bc37.patch
        patch -p2 -i ef8c35bcf5d9cfdb0764ffde6a63c04ec715bc37.patch
        wget https://github.com/nihui/llvm-project/commit/5c12711f9a21f41bea70566bf15a4026804d6b20.patch
        patch -p2 -i 5c12711f9a21f41bea70566bf15a4026804d6b20.patch
    - name: build-arm64
      if: steps.cache-openmp.outputs.cache-hit != 'true'
      run: |
        cd openmp-${{ env.OPENMP_VERSION }}.src
        mkdir -p build-arm64 && cd build-arm64
        cmake ${{ env.OPENMP_CMAKE_OPTIONS }} -DPLATFORM=TVOS -DARCHS="arm64" ..
        cmake --build . -j 4
        cmake --build . --target install/strip
    - name: build-arm64e
      if: steps.cache-openmp.outputs.cache-hit != 'true'
      run: |
        cd openmp-${{ env.OPENMP_VERSION }}.src
        mkdir -p build-arm64e && cd build-arm64e
        cmake ${{ env.OPENMP_CMAKE_OPTIONS }} -DPLATFORM=TVOS -DARCHS="arm64e" ..
        cmake --build . -j 4
        cmake --build . --target install/strip
    - name: merge-fat-library
      if: steps.cache-openmp.outputs.cache-hit != 'true'
      run: |
        rm -rf $GITHUB_WORKSPACE/openmp-install
        mkdir -p $GITHUB_WORKSPACE/openmp-install
        cp -a openmp-${{ env.OPENMP_VERSION }}.src/build-arm64/install/include $GITHUB_WORKSPACE/openmp-install
        mkdir -p $GITHUB_WORKSPACE/openmp-install/lib
        lipo -create \
            openmp-${{ env.OPENMP_VERSION }}.src/build-arm64/install/lib/libomp.a \
            openmp-${{ env.OPENMP_VERSION }}.src/build-arm64e/install/lib/libomp.a \
            -o $GITHUB_WORKSPACE/openmp-install/lib/libomp.a
    - name: upload
      uses: actions/upload-artifact@v4
      with:
        name: openmp-tvos
        path: openmp-install

  tvos:
    needs: [setup, openmp-tvos]
    strategy:
      matrix:
        opt:
          - { vulkan: OFF, id: tvos        }
          - { vulkan: ON,  id: tvos-vulkan }
    runs-on: macos-13
    env:
      PACKAGENAME: ncnn-${{ needs.setup.outputs.VERSION }}-${{ matrix.opt.id }}
      NCNN_CMAKE_OPTIONS: |
        -DCMAKE_TOOLCHAIN_FILE=../toolchains/ios.toolchain.cmake \
        -DDEPLOYMENT_TARGET=$TVOS_DEPLOYMENT_TARGET \
        -DENABLE_BITCODE=$ENABLE_BITCODE \
        -DENABLE_ARC=$ENABLE_ARC \
        -DENABLE_VISIBILITY=$ENABLE_VISIBILITY \
        -DCMAKE_INSTALL_PREFIX=install \
        -DCMAKE_BUILD_TYPE=Release \
        -DOpenMP_C_FLAGS="-Xclang -fopenmp" -DOpenMP_CXX_FLAGS="-Xclang -fopenmp" \
        -DOpenMP_C_LIB_NAMES="libomp" -DOpenMP_CXX_LIB_NAMES="libomp" \
        -DOpenMP_libomp_LIBRARY="libomp.a" \
        -DNCNN_VERSION_STRING="${{ needs.setup.outputs.VERSION }}" \
        -DNCNN_BUILD_BENCHMARK=OFF \
        -DNCNN_VULKAN=${{ matrix.opt.vulkan }} \

    steps:
    - uses: actions/checkout@v4
      with:
        submodules: true
    - name: download-openmp-tvos
      uses: actions/download-artifact@v4
      with:
        name: openmp-tvos
        path: openmp-tvos
    - name: install-openmp
      run: |
        sudo cp openmp-tvos/include/* $DEVELOPER_DIR/Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS.sdk/usr/include
        sudo cp openmp-tvos/lib/libomp.a $DEVELOPER_DIR/Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS.sdk/usr/lib
    - name: build-arm64
      run: |
        mkdir build-arm64 && cd build-arm64
        cmake ${{ env.NCNN_CMAKE_OPTIONS }} -DPLATFORM=TVOS -DARCHS="arm64" ..
        cmake --build . -j 4
        cmake --build . --target install/strip
    - name: build-arm64e
      run: |
        mkdir build-arm64e && cd build-arm64e
        cmake ${{ env.NCNN_CMAKE_OPTIONS }} -DPLATFORM=TVOS -DARCHS="arm64e" ..
        cmake --build . -j 4
        cmake --build . --target install/strip
    - name: package-openmp
      run: |
        rm -rf openmp.framework
        mkdir -p openmp.framework/Versions/A/Headers
        mkdir -p openmp.framework/Versions/A/Resources
        ln -s A openmp.framework/Versions/Current
        ln -s Versions/Current/Headers openmp.framework/Headers
        ln -s Versions/Current/Resources openmp.framework/Resources
        ln -s Versions/Current/openmp openmp.framework/openmp
        cp openmp-tvos/lib/libomp.a openmp.framework/Versions/A/openmp
        cp -a openmp-tvos/include/* openmp.framework/Versions/A/Headers/
        sed -e 's/__NAME__/openmp/g' -e 's/__IDENTIFIER__/org.llvm.openmp/g' -e 's/__VERSION__/18.1/g' Info.plist > openmp.framework/Versions/A/Resources/Info.plist
    - name: package-glslang
      if: matrix.opt.vulkan == 'ON'
      run: |
        rm -rf glslang.framework
        mkdir -p glslang.framework/Versions/A/Headers
        mkdir -p glslang.framework/Versions/A/Resources
        ln -s A glslang.framework/Versions/Current
        ln -s Versions/Current/Headers glslang.framework/Headers
        ln -s Versions/Current/Resources glslang.framework/Resources
        ln -s Versions/Current/glslang glslang.framework/glslang
        libtool -static \
            build-arm64/install/lib/libglslang.a \
            build-arm64/install/lib/libSPIRV.a \
            -o build-arm64/install/lib/libglslang_combined.a
        libtool -static \
            build-arm64e/install/lib/libglslang.a \
            build-arm64e/install/lib/libSPIRV.a \
            -o build-arm64e/install/lib/libglslang_combined.a
        lipo -create \
            build-arm64/install/lib/libglslang_combined.a \
            build-arm64e/install/lib/libglslang_combined.a \
            -o glslang.framework/Versions/A/glslang
        cp -a build-arm64/install/include/glslang glslang.framework/Versions/A/Headers/
        sed -e 's/__NAME__/glslang/g' -e 's/__IDENTIFIER__/org.khronos.glslang/g' -e 's/__VERSION__/1.0/g' Info.plist > glslang.framework/Versions/A/Resources/Info.plist
    - name: package-ncnn
      run: |
        rm -rf ncnn.framework
        mkdir -p ncnn.framework/Versions/A/Headers
        mkdir -p ncnn.framework/Versions/A/Resources
        ln -s A ncnn.framework/Versions/Current
        ln -s Versions/Current/Headers ncnn.framework/Headers
        ln -s Versions/Current/Resources ncnn.framework/Resources
        ln -s Versions/Current/ncnn ncnn.framework/ncnn
        lipo -create \
            build-arm64/install/lib/libncnn.a \
            build-arm64e/install/lib/libncnn.a \
            -o ncnn.framework/Versions/A/ncnn
        cp -a build-arm64/install/include/* ncnn.framework/Versions/A/Headers/
        sed -e 's/__NAME__/ncnn/g' -e 's/__IDENTIFIER__/com.tencent.ncnn/g' -e 's/__VERSION__/1.0/g' Info.plist > ncnn.framework/Versions/A/Resources/Info.plist
    - name: package
      if: matrix.opt.vulkan == 'OFF'
      run: |
        rm -f ${{ env.PACKAGENAME }}.zip
        zip -9 -y -r ${{ env.PACKAGENAME }}.zip openmp.framework ncnn.framework
    - name: package
      if: matrix.opt.vulkan == 'ON'
      run: |
        rm -f ${{ env.PACKAGENAME }}.zip
        zip -9 -y -r ${{ env.PACKAGENAME }}.zip openmp.framework glslang.framework ncnn.framework
    - name: upload-zip
      uses: actions/upload-artifact@v4
      with:
        name: ${{ env.PACKAGENAME }}
        path: ${{ env.PACKAGENAME }}.zip

  openmp-tvos-simulator:
    runs-on: macos-13
    env:
      OPENMP_VERSION: '18.1.2'
      OPENMP_CMAKE_OPTIONS: |
        -DCMAKE_TOOLCHAIN_FILE=../../toolchains/ios.toolchain.cmake \
        -DDEPLOYMENT_TARGET=$TVOS_DEPLOYMENT_TARGET \
        -DENABLE_BITCODE=$ENABLE_BITCODE \
        -DENABLE_ARC=$ENABLE_ARC \
        -DENABLE_VISIBILITY=$ENABLE_VISIBILITY \
        -DCMAKE_INSTALL_PREFIX=install \
        -DCMAKE_BUILD_TYPE=Release \
        -DPERL_EXECUTABLE=/usr/local/bin/perl \
        -DLIBOMP_ENABLE_SHARED=OFF \
        -DLIBOMP_OMPT_SUPPORT=OFF \
        -DLIBOMP_USE_HWLOC=OFF \
    steps:
    - name: cache-openmp
      id: cache-openmp
      uses: actions/cache@v4
      with:
        path: openmp-install
        key: openmp-tvos-simulator-release-18.1.2-20240403
    - name: checkout
      if: steps.cache-openmp.outputs.cache-hit != 'true'
      uses: actions/checkout@v4
    - name: openmp
      if: steps.cache-openmp.outputs.cache-hit != 'true'
      run: |
        wget https://github.com/llvm/llvm-project/releases/download/llvmorg-${{ env.OPENMP_VERSION }}/cmake-${{ env.OPENMP_VERSION }}.src.tar.xz
        tar -xf cmake-${{ env.OPENMP_VERSION }}.src.tar.xz
        wget https://github.com/llvm/llvm-project/releases/download/llvmorg-${{ env.OPENMP_VERSION }}/openmp-${{ env.OPENMP_VERSION }}.src.tar.xz
        tar -xf openmp-${{ env.OPENMP_VERSION }}.src.tar.xz
        mv cmake-${{ env.OPENMP_VERSION }}.src/Modules/* openmp-${{ env.OPENMP_VERSION }}.src/cmake/
        cd openmp-${{ env.OPENMP_VERSION }}.src
        wget https://github.com/nihui/llvm-project/commit/ef8c35bcf5d9cfdb0764ffde6a63c04ec715bc37.patch
        patch -p2 -i ef8c35bcf5d9cfdb0764ffde6a63c04ec715bc37.patch
        wget https://github.com/nihui/llvm-project/commit/5c12711f9a21f41bea70566bf15a4026804d6b20.patch
        patch -p2 -i 5c12711f9a21f41bea70566bf15a4026804d6b20.patch
    - name: build-x86_64
      if: steps.cache-openmp.outputs.cache-hit != 'true'
      run: |
        cd openmp-${{ env.OPENMP_VERSION }}.src
        mkdir -p build-x86_64 && cd build-x86_64
        cmake ${{ env.OPENMP_CMAKE_OPTIONS }} -DPLATFORM=SIMULATOR_TVOS -DARCHS="x86_64" ..
        cmake --build . -j 4
        cmake --build . --target install/strip
    - name: build-arm64
      if: steps.cache-openmp.outputs.cache-hit != 'true'
      run: |
        cd openmp-${{ env.OPENMP_VERSION }}.src
        mkdir -p build-arm64 && cd build-arm64
        cmake ${{ env.OPENMP_CMAKE_OPTIONS }} -DPLATFORM=SIMULATOR_TVOS -DARCHS="arm64" ..
        cmake --build . -j 4
        cmake --build . --target install/strip
    - name: merge-fat-library
      if: steps.cache-openmp.outputs.cache-hit != 'true'
      run: |
        rm -rf $GITHUB_WORKSPACE/openmp-install
        mkdir -p $GITHUB_WORKSPACE/openmp-install
        cp -a openmp-${{ env.OPENMP_VERSION }}.src/build-x86_64/install/include $GITHUB_WORKSPACE/openmp-install
        mkdir -p $GITHUB_WORKSPACE/openmp-install/lib
        lipo -create \
            openmp-${{ env.OPENMP_VERSION }}.src/build-x86_64/install/lib/libomp.a \
            openmp-${{ env.OPENMP_VERSION }}.src/build-arm64/install/lib/libomp.a \
            -o $GITHUB_WORKSPACE/openmp-install/lib/libomp.a
    - name: upload
      uses: actions/upload-artifact@v4
      with:
        name: openmp-tvos-simulator
        path: openmp-install

  tvos-simulator:
    needs: [setup, openmp-tvos-simulator]
    strategy:
      matrix:
        opt:
          - { vulkan: OFF, id: tvos-simulator        }
          - { vulkan: ON,  id: tvos-simulator-vulkan }
    runs-on: macos-13
    env:
      PACKAGENAME: ncnn-${{ needs.setup.outputs.VERSION }}-${{ matrix.opt.id }}
      NCNN_CMAKE_OPTIONS: |
        -DCMAKE_TOOLCHAIN_FILE=../toolchains/ios.toolchain.cmake \
        -DDEPLOYMENT_TARGET=$TVOS_DEPLOYMENT_TARGET \
        -DENABLE_BITCODE=$ENABLE_BITCODE \
        -DENABLE_ARC=$ENABLE_ARC \
        -DENABLE_VISIBILITY=$ENABLE_VISIBILITY \
        -DCMAKE_INSTALL_PREFIX=install \
        -DCMAKE_BUILD_TYPE=Release \
        -DOpenMP_C_FLAGS="-Xclang -fopenmp" -DOpenMP_CXX_FLAGS="-Xclang -fopenmp" \
        -DOpenMP_C_LIB_NAMES="libomp" -DOpenMP_CXX_LIB_NAMES="libomp" \
        -DOpenMP_libomp_LIBRARY="libomp.a" \
        -DNCNN_VERSION_STRING="${{ needs.setup.outputs.VERSION }}" \
        -DNCNN_BUILD_BENCHMARK=OFF \
        -DNCNN_VULKAN=${{ matrix.opt.vulkan }} \

    steps:
    - uses: actions/checkout@v4
      with:
        submodules: true
    - name: download-openmp-tvos-simulator
      uses: actions/download-artifact@v4
      with:
        name: openmp-tvos-simulator
        path: openmp-tvos-simulator
    - name: install-openmp
      run: |
        sudo cp openmp-tvos-simulator/include/* $DEVELOPER_DIR/Platforms/AppleTVSimulator.platform/Developer/SDKs/AppleTVSimulator.sdk/usr/include
        sudo cp openmp-tvos-simulator/lib/libomp.a $DEVELOPER_DIR/Platforms/AppleTVSimulator.platform/Developer/SDKs/AppleTVSimulator.sdk/usr/lib
    - name: build-x86_64
      run: |
        mkdir build-x86_64 && cd build-x86_64
        cmake ${{ env.NCNN_CMAKE_OPTIONS }} -DPLATFORM=SIMULATOR_TVOS -DARCHS="x86_64" ..
        cmake --build . -j 4
        cmake --build . --target install/strip
    - name: build-arm64
      run: |
        mkdir build-arm64 && cd build-arm64
        cmake ${{ env.NCNN_CMAKE_OPTIONS }} -DPLATFORM=SIMULATOR_TVOS -DARCHS="arm64" ..
        cmake --build . -j 4
        cmake --build . --target install/strip
    - name: package-openmp
      run: |
        rm -rf openmp.framework
        mkdir -p openmp.framework/Versions/A/Headers
        mkdir -p openmp.framework/Versions/A/Resources
        ln -s A openmp.framework/Versions/Current
        ln -s Versions/Current/Headers openmp.framework/Headers
        ln -s Versions/Current/Resources openmp.framework/Resources
        ln -s Versions/Current/openmp openmp.framework/openmp
        cp openmp-tvos-simulator/lib/libomp.a openmp.framework/Versions/A/openmp
        cp -a openmp-tvos-simulator/include/* openmp.framework/Versions/A/Headers/
        sed -e 's/__NAME__/openmp/g' -e 's/__IDENTIFIER__/org.llvm.openmp/g' -e 's/__VERSION__/18.1/g' Info.plist > openmp.framework/Versions/A/Resources/Info.plist
    - name: package-glslang
      if: matrix.opt.vulkan == 'ON'
      run: |
        rm -rf glslang.framework
        mkdir -p glslang.framework/Versions/A/Headers
        mkdir -p glslang.framework/Versions/A/Resources
        ln -s A glslang.framework/Versions/Current
        ln -s Versions/Current/Headers glslang.framework/Headers
        ln -s Versions/Current/Resources glslang.framework/Resources
        ln -s Versions/Current/glslang glslang.framework/glslang
        libtool -static \
            build-x86_64/install/lib/libglslang.a \
            build-x86_64/install/lib/libSPIRV.a \
            -o build-x86_64/install/lib/libglslang_combined.a
        libtool -static \
            build-arm64/install/lib/libglslang.a \
            build-arm64/install/lib/libSPIRV.a \
            -o build-arm64/install/lib/libglslang_combined.a
        lipo -create \
            build-x86_64/install/lib/libglslang_combined.a \
            build-arm64/install/lib/libglslang_combined.a \
            -o glslang.framework/Versions/A/glslang
        cp -a build-x86_64/install/include/glslang glslang.framework/Versions/A/Headers/
        sed -e 's/__NAME__/glslang/g' -e 's/__IDENTIFIER__/org.khronos.glslang/g' -e 's/__VERSION__/1.0/g' Info.plist > glslang.framework/Versions/A/Resources/Info.plist
    - name: package-ncnn
      run: |
        rm -rf ncnn.framework
        mkdir -p ncnn.framework/Versions/A/Headers
        mkdir -p ncnn.framework/Versions/A/Resources
        ln -s A ncnn.framework/Versions/Current
        ln -s Versions/Current/Headers ncnn.framework/Headers
        ln -s Versions/Current/Resources ncnn.framework/Resources
        ln -s Versions/Current/ncnn ncnn.framework/ncnn
        lipo -create \
            build-x86_64/install/lib/libncnn.a \
            build-arm64/install/lib/libncnn.a \
            -o ncnn.framework/Versions/A/ncnn
        cp -a build-x86_64/install/include/* ncnn.framework/Versions/A/Headers/
        sed -e 's/__NAME__/ncnn/g' -e 's/__IDENTIFIER__/com.tencent.ncnn/g' -e 's/__VERSION__/1.0/g' Info.plist > ncnn.framework/Versions/A/Resources/Info.plist
    - name: package
      if: matrix.opt.vulkan == 'OFF'
      run: |
        rm -f ${{ env.PACKAGENAME }}.zip
        zip -9 -y -r ${{ env.PACKAGENAME }}.zip openmp.framework ncnn.framework
    - name: package
      if: matrix.opt.vulkan == 'ON'
      run: |
        rm -f ${{ env.PACKAGENAME }}.zip
        zip -9 -y -r ${{ env.PACKAGENAME }}.zip openmp.framework glslang.framework ncnn.framework
    - name: upload-zip
      uses: actions/upload-artifact@v4
      with:
        name: ${{ env.PACKAGENAME }}
        path: ${{ env.PACKAGENAME }}.zip

  openmp-visionos:
    runs-on: macos-13
    env:
      OPENMP_VERSION: '18.1.2'
      OPENMP_CMAKE_OPTIONS: |
        -DCMAKE_TOOLCHAIN_FILE=../../toolchains/ios.toolchain.cmake \
        -DDEPLOYMENT_TARGET=$VISIONOS_DEPLOYMENT_TARGET \
        -DENABLE_BITCODE=$ENABLE_BITCODE \
        -DENABLE_ARC=$ENABLE_ARC \
        -DENABLE_VISIBILITY=$ENABLE_VISIBILITY \
        -DCMAKE_INSTALL_PREFIX=install \
        -DCMAKE_BUILD_TYPE=Release \
        -DPERL_EXECUTABLE=/usr/local/bin/perl \
        -DLIBOMP_ENABLE_SHARED=OFF \
        -DLIBOMP_OMPT_SUPPORT=OFF \
        -DLIBOMP_USE_HWLOC=OFF \
    steps:
    - name: cache-openmp
      id: cache-openmp
      uses: actions/cache@v4
      with:
        path: openmp-install
        key: openmp-visionos-release-18.1.2-20240403
    - name: checkout
      if: steps.cache-openmp.outputs.cache-hit != 'true'
      uses: actions/checkout@v4
    - name: openmp
      if: steps.cache-openmp.outputs.cache-hit != 'true'
      run: |
        wget https://github.com/llvm/llvm-project/releases/download/llvmorg-${{ env.OPENMP_VERSION }}/cmake-${{ env.OPENMP_VERSION }}.src.tar.xz
        tar -xf cmake-${{ env.OPENMP_VERSION }}.src.tar.xz
        wget https://github.com/llvm/llvm-project/releases/download/llvmorg-${{ env.OPENMP_VERSION }}/openmp-${{ env.OPENMP_VERSION }}.src.tar.xz
        tar -xf openmp-${{ env.OPENMP_VERSION }}.src.tar.xz
        mv cmake-${{ env.OPENMP_VERSION }}.src/Modules/* openmp-${{ env.OPENMP_VERSION }}.src/cmake/
        cd openmp-${{ env.OPENMP_VERSION }}.src
        wget https://github.com/nihui/llvm-project/commit/ef8c35bcf5d9cfdb0764ffde6a63c04ec715bc37.patch
        patch -p2 -i ef8c35bcf5d9cfdb0764ffde6a63c04ec715bc37.patch
        wget https://github.com/nihui/llvm-project/commit/5c12711f9a21f41bea70566bf15a4026804d6b20.patch
        patch -p2 -i 5c12711f9a21f41bea70566bf15a4026804d6b20.patch
    - name: build-arm64
      if: steps.cache-openmp.outputs.cache-hit != 'true'
      run: |
        cd openmp-${{ env.OPENMP_VERSION }}.src
        mkdir -p build-arm64 && cd build-arm64
        cmake ${{ env.OPENMP_CMAKE_OPTIONS }} -DPLATFORM=VISIONOS -DARCHS="arm64" ..
        cmake --build . -j 4
        cmake --build . --target install/strip
    - name: merge-fat-library
      if: steps.cache-openmp.outputs.cache-hit != 'true'
      run: |
        rm -rf $GITHUB_WORKSPACE/openmp-install
        mkdir -p $GITHUB_WORKSPACE/openmp-install
        cp -a openmp-${{ env.OPENMP_VERSION }}.src/build-arm64/install/include $GITHUB_WORKSPACE/openmp-install
        mkdir -p $GITHUB_WORKSPACE/openmp-install/lib
        cp openmp-${{ env.OPENMP_VERSION }}.src/build-arm64/install/lib/libomp.a $GITHUB_WORKSPACE/openmp-install/lib/libomp.a
    - name: upload
      uses: actions/upload-artifact@v4
      with:
        name: openmp-visionos
        path: openmp-install

  visionos:
    needs: [setup, openmp-visionos]
    strategy:
      matrix:
        opt:
          - { vulkan: OFF, id: visionos        }
          - { vulkan: ON,  id: visionos-vulkan }
    runs-on: macos-13
    env:
      PACKAGENAME: ncnn-${{ needs.setup.outputs.VERSION }}-${{ matrix.opt.id }}
      NCNN_CMAKE_OPTIONS: |
        -DCMAKE_TOOLCHAIN_FILE=../toolchains/ios.toolchain.cmake \
        -DDEPLOYMENT_TARGET=$VISIONOS_DEPLOYMENT_TARGET \
        -DENABLE_BITCODE=$ENABLE_BITCODE \
        -DENABLE_ARC=$ENABLE_ARC \
        -DENABLE_VISIBILITY=$ENABLE_VISIBILITY \
        -DCMAKE_INSTALL_PREFIX=install \
        -DCMAKE_BUILD_TYPE=Release \
        -DOpenMP_C_FLAGS="-Xclang -fopenmp" -DOpenMP_CXX_FLAGS="-Xclang -fopenmp" \
        -DOpenMP_C_LIB_NAMES="libomp" -DOpenMP_CXX_LIB_NAMES="libomp" \
        -DOpenMP_libomp_LIBRARY="libomp.a" \
        -DNCNN_VERSION_STRING="${{ needs.setup.outputs.VERSION }}" \
        -DNCNN_BUILD_BENCHMARK=OFF \
        -DNCNN_VULKAN=${{ matrix.opt.vulkan }} \

    steps:
    - uses: actions/checkout@v4
      with:
        submodules: true
    - name: download-openmp-visionos
      uses: actions/download-artifact@v4
      with:
        name: openmp-visionos
        path: openmp-visionos
    - name: install-openmp
      run: |
        sudo cp openmp-visionos/include/* $DEVELOPER_DIR/Platforms/XROS.platform/Developer/SDKs/XROS.sdk/usr/include
        sudo cp openmp-visionos/lib/libomp.a $DEVELOPER_DIR/Platforms/XROS.platform/Developer/SDKs/XROS.sdk/usr/lib
    - name: build-arm64
      run: |
        mkdir build-arm64 && cd build-arm64
        cmake ${{ env.NCNN_CMAKE_OPTIONS }} -DPLATFORM=VISIONOS -DARCHS="arm64" ..
        cmake --build . -j 4
        cmake --build . --target install/strip
    - name: package-openmp
      run: |
        rm -rf openmp.framework
        mkdir -p openmp.framework/Versions/A/Headers
        mkdir -p openmp.framework/Versions/A/Resources
        ln -s A openmp.framework/Versions/Current
        ln -s Versions/Current/Headers openmp.framework/Headers
        ln -s Versions/Current/Resources openmp.framework/Resources
        ln -s Versions/Current/openmp openmp.framework/openmp
        cp openmp-visionos/lib/libomp.a openmp.framework/Versions/A/openmp
        cp -a openmp-visionos/include/* openmp.framework/Versions/A/Headers/
        sed -e 's/__NAME__/openmp/g' -e 's/__IDENTIFIER__/org.llvm.openmp/g' -e 's/__VERSION__/18.1/g' Info.plist > openmp.framework/Versions/A/Resources/Info.plist
    - name: package-glslang
      if: matrix.opt.vulkan == 'ON'
      run: |
        rm -rf glslang.framework
        mkdir -p glslang.framework/Versions/A/Headers
        mkdir -p glslang.framework/Versions/A/Resources
        ln -s A glslang.framework/Versions/Current
        ln -s Versions/Current/Headers glslang.framework/Headers
        ln -s Versions/Current/Resources glslang.framework/Resources
        ln -s Versions/Current/glslang glslang.framework/glslang
        libtool -static \
            build-arm64/install/lib/libglslang.a \
            build-arm64/install/lib/libSPIRV.a \
            -o build-arm64/install/lib/libglslang_combined.a
        cp build-arm64/install/lib/libglslang_combined.a glslang.framework/Versions/A/glslang
        cp -a build-arm64/install/include/glslang glslang.framework/Versions/A/Headers/
        sed -e 's/__NAME__/glslang/g' -e 's/__IDENTIFIER__/org.khronos.glslang/g' -e 's/__VERSION__/1.0/g' Info.plist > glslang.framework/Versions/A/Resources/Info.plist
    - name: package-ncnn
      run: |
        rm -rf ncnn.framework
        mkdir -p ncnn.framework/Versions/A/Headers
        mkdir -p ncnn.framework/Versions/A/Resources
        ln -s A ncnn.framework/Versions/Current
        ln -s Versions/Current/Headers ncnn.framework/Headers
        ln -s Versions/Current/Resources ncnn.framework/Resources
        ln -s Versions/Current/ncnn ncnn.framework/ncnn
        cp build-arm64/install/lib/libncnn.a ncnn.framework/Versions/A/ncnn
        cp -a build-arm64/install/include/* ncnn.framework/Versions/A/Headers/
        sed -e 's/__NAME__/ncnn/g' -e 's/__IDENTIFIER__/com.tencent.ncnn/g' -e 's/__VERSION__/1.0/g' Info.plist > ncnn.framework/Versions/A/Resources/Info.plist
    - name: package
      if: matrix.opt.vulkan == 'OFF'
      run: |
        rm -f ${{ env.PACKAGENAME }}.zip
        zip -9 -y -r ${{ env.PACKAGENAME }}.zip openmp.framework ncnn.framework
    - name: package
      if: matrix.opt.vulkan == 'ON'
      run: |
        rm -f ${{ env.PACKAGENAME }}.zip
        zip -9 -y -r ${{ env.PACKAGENAME }}.zip openmp.framework glslang.framework ncnn.framework
    - name: upload-zip
      uses: actions/upload-artifact@v4
      with:
        name: ${{ env.PACKAGENAME }}
        path: ${{ env.PACKAGENAME }}.zip

  openmp-visionos-simulator:
    runs-on: macos-13
    env:
      OPENMP_VERSION: '18.1.2'
      OPENMP_CMAKE_OPTIONS: |
        -DCMAKE_TOOLCHAIN_FILE=../../toolchains/ios.toolchain.cmake \
        -DDEPLOYMENT_TARGET=$VISIONOS_DEPLOYMENT_TARGET \
        -DENABLE_BITCODE=$ENABLE_BITCODE \
        -DENABLE_ARC=$ENABLE_ARC \
        -DENABLE_VISIBILITY=$ENABLE_VISIBILITY \
        -DCMAKE_INSTALL_PREFIX=install \
        -DCMAKE_BUILD_TYPE=Release \
        -DPERL_EXECUTABLE=/usr/local/bin/perl \
        -DLIBOMP_ENABLE_SHARED=OFF \
        -DLIBOMP_OMPT_SUPPORT=OFF \
        -DLIBOMP_USE_HWLOC=OFF \
    steps:
    - name: cache-openmp
      id: cache-openmp
      uses: actions/cache@v4
      with:
        path: openmp-install
        key: openmp-visionos-simulator-release-18.1.2-20240403
    - name: checkout
      if: steps.cache-openmp.outputs.cache-hit != 'true'
      uses: actions/checkout@v4
    - name: openmp
      if: steps.cache-openmp.outputs.cache-hit != 'true'
      run: |
        wget https://github.com/llvm/llvm-project/releases/download/llvmorg-${{ env.OPENMP_VERSION }}/cmake-${{ env.OPENMP_VERSION }}.src.tar.xz
        tar -xf cmake-${{ env.OPENMP_VERSION }}.src.tar.xz
        wget https://github.com/llvm/llvm-project/releases/download/llvmorg-${{ env.OPENMP_VERSION }}/openmp-${{ env.OPENMP_VERSION }}.src.tar.xz
        tar -xf openmp-${{ env.OPENMP_VERSION }}.src.tar.xz
        mv cmake-${{ env.OPENMP_VERSION }}.src/Modules/* openmp-${{ env.OPENMP_VERSION }}.src/cmake/
        cd openmp-${{ env.OPENMP_VERSION }}.src
        wget https://github.com/nihui/llvm-project/commit/ef8c35bcf5d9cfdb0764ffde6a63c04ec715bc37.patch
        patch -p2 -i ef8c35bcf5d9cfdb0764ffde6a63c04ec715bc37.patch
        wget https://github.com/nihui/llvm-project/commit/5c12711f9a21f41bea70566bf15a4026804d6b20.patch
        patch -p2 -i 5c12711f9a21f41bea70566bf15a4026804d6b20.patch
    - name: build-x86_64
      if: steps.cache-openmp.outputs.cache-hit != 'true'
      run: |
        cd openmp-${{ env.OPENMP_VERSION }}.src
        mkdir -p build-x86_64 && cd build-x86_64
        cmake ${{ env.OPENMP_CMAKE_OPTIONS }} -DPLATFORM=SIMULATOR_VISIONOS -DARCHS="x86_64" ..
        cmake --build . -j 4
        cmake --build . --target install/strip
    - name: build-arm64
      if: steps.cache-openmp.outputs.cache-hit != 'true'
      run: |
        cd openmp-${{ env.OPENMP_VERSION }}.src
        mkdir -p build-arm64 && cd build-arm64
        cmake ${{ env.OPENMP_CMAKE_OPTIONS }} -DPLATFORM=SIMULATOR_VISIONOS -DARCHS="arm64" ..
        cmake --build . -j 4
        cmake --build . --target install/strip
    - name: merge-fat-library
      if: steps.cache-openmp.outputs.cache-hit != 'true'
      run: |
        rm -rf $GITHUB_WORKSPACE/openmp-install
        mkdir -p $GITHUB_WORKSPACE/openmp-install
        cp -a openmp-${{ env.OPENMP_VERSION }}.src/build-x86_64/install/include $GITHUB_WORKSPACE/openmp-install
        mkdir -p $GITHUB_WORKSPACE/openmp-install/lib
        lipo -create \
            openmp-${{ env.OPENMP_VERSION }}.src/build-x86_64/install/lib/libomp.a \
            openmp-${{ env.OPENMP_VERSION }}.src/build-arm64/install/lib/libomp.a \
            -o $GITHUB_WORKSPACE/openmp-install/lib/libomp.a
    - name: upload
      uses: actions/upload-artifact@v4
      with:
        name: openmp-visionos-simulator
        path: openmp-install

  visionos-simulator:
    needs: [setup, openmp-visionos-simulator]
    strategy:
      matrix:
        opt:
          - { vulkan: OFF, id: visionos-simulator        }
          - { vulkan: ON,  id: visionos-simulator-vulkan }
    runs-on: macos-13
    env:
      PACKAGENAME: ncnn-${{ needs.setup.outputs.VERSION }}-${{ matrix.opt.id }}
      NCNN_CMAKE_OPTIONS: |
        -DCMAKE_TOOLCHAIN_FILE=../toolchains/ios.toolchain.cmake \
        -DDEPLOYMENT_TARGET=$VISIONOS_DEPLOYMENT_TARGET \
        -DENABLE_BITCODE=$ENABLE_BITCODE \
        -DENABLE_ARC=$ENABLE_ARC \
        -DENABLE_VISIBILITY=$ENABLE_VISIBILITY \
        -DCMAKE_INSTALL_PREFIX=install \
        -DCMAKE_BUILD_TYPE=Release \
        -DOpenMP_C_FLAGS="-Xclang -fopenmp" -DOpenMP_CXX_FLAGS="-Xclang -fopenmp" \
        -DOpenMP_C_LIB_NAMES="libomp" -DOpenMP_CXX_LIB_NAMES="libomp" \
        -DOpenMP_libomp_LIBRARY="libomp.a" \
        -DNCNN_VERSION_STRING="${{ needs.setup.outputs.VERSION }}" \
        -DNCNN_BUILD_BENCHMARK=OFF \
        -DNCNN_VULKAN=${{ matrix.opt.vulkan }} \

    steps:
    - uses: actions/checkout@v4
      with:
        submodules: true
    - name: download-openmp-visionos-simulator
      uses: actions/download-artifact@v4
      with:
        name: openmp-visionos-simulator
        path: openmp-visionos-simulator
    - name: install-openmp
      run: |
        sudo cp openmp-visionos-simulator/include/* $DEVELOPER_DIR/Platforms/XRSimulator.platform/Developer/SDKs/XRSimulator.sdk/usr/include
        sudo cp openmp-visionos-simulator/lib/libomp.a $DEVELOPER_DIR/Platforms/XRSimulator.platform/Developer/SDKs/XRSimulator.sdk/usr/lib
    - name: build-x86_64
      run: |
        mkdir build-x86_64 && cd build-x86_64
        cmake ${{ env.NCNN_CMAKE_OPTIONS }} -DPLATFORM=SIMULATOR_VISIONOS -DARCHS="x86_64" ..
        cmake --build . -j 4
        cmake --build . --target install/strip
    - name: build-arm64
      run: |
        mkdir build-arm64 && cd build-arm64
        cmake ${{ env.NCNN_CMAKE_OPTIONS }} -DPLATFORM=SIMULATOR_VISIONOS -DARCHS="arm64" ..
        cmake --build . -j 4
        cmake --build . --target install/strip
    - name: package-openmp
      run: |
        rm -rf openmp.framework
        mkdir -p openmp.framework/Versions/A/Headers
        mkdir -p openmp.framework/Versions/A/Resources
        ln -s A openmp.framework/Versions/Current
        ln -s Versions/Current/Headers openmp.framework/Headers
        ln -s Versions/Current/Resources openmp.framework/Resources
        ln -s Versions/Current/openmp openmp.framework/openmp
        cp openmp-visionos-simulator/lib/libomp.a openmp.framework/Versions/A/openmp
        cp -a openmp-visionos-simulator/include/* openmp.framework/Versions/A/Headers/
        sed -e 's/__NAME__/openmp/g' -e 's/__IDENTIFIER__/org.llvm.openmp/g' -e 's/__VERSION__/18.1/g' Info.plist > openmp.framework/Versions/A/Resources/Info.plist
    - name: package-glslang
      if: matrix.opt.vulkan == 'ON'
      run: |
        rm -rf glslang.framework
        mkdir -p glslang.framework/Versions/A/Headers
        mkdir -p glslang.framework/Versions/A/Resources
        ln -s A glslang.framework/Versions/Current
        ln -s Versions/Current/Headers glslang.framework/Headers
        ln -s Versions/Current/Resources glslang.framework/Resources
        ln -s Versions/Current/glslang glslang.framework/glslang
        libtool -static \
            build-x86_64/install/lib/libglslang.a \
            build-x86_64/install/lib/libSPIRV.a \
            -o build-x86_64/install/lib/libglslang_combined.a
        libtool -static \
            build-arm64/install/lib/libglslang.a \
            build-arm64/install/lib/libSPIRV.a \
            -o build-arm64/install/lib/libglslang_combined.a
        lipo -create \
            build-x86_64/install/lib/libglslang_combined.a \
            build-arm64/install/lib/libglslang_combined.a \
            -o glslang.framework/Versions/A/glslang
        cp -a build-x86_64/install/include/glslang glslang.framework/Versions/A/Headers/
        sed -e 's/__NAME__/glslang/g' -e 's/__IDENTIFIER__/org.khronos.glslang/g' -e 's/__VERSION__/1.0/g' Info.plist > glslang.framework/Versions/A/Resources/Info.plist
    - name: package-ncnn
      run: |
        rm -rf ncnn.framework
        mkdir -p ncnn.framework/Versions/A/Headers
        mkdir -p ncnn.framework/Versions/A/Resources
        ln -s A ncnn.framework/Versions/Current
        ln -s Versions/Current/Headers ncnn.framework/Headers
        ln -s Versions/Current/Resources ncnn.framework/Resources
        ln -s Versions/Current/ncnn ncnn.framework/ncnn
        lipo -create \
            build-x86_64/install/lib/libncnn.a \
            build-arm64/install/lib/libncnn.a \
            -o ncnn.framework/Versions/A/ncnn
        cp -a build-x86_64/install/include/* ncnn.framework/Versions/A/Headers/
        sed -e 's/__NAME__/ncnn/g' -e 's/__IDENTIFIER__/com.tencent.ncnn/g' -e 's/__VERSION__/1.0/g' Info.plist > ncnn.framework/Versions/A/Resources/Info.plist
    - name: package
      if: matrix.opt.vulkan == 'OFF'
      run: |
        rm -f ${{ env.PACKAGENAME }}.zip
        zip -9 -y -r ${{ env.PACKAGENAME }}.zip openmp.framework ncnn.framework
    - name: package
      if: matrix.opt.vulkan == 'ON'
      run: |
        rm -f ${{ env.PACKAGENAME }}.zip
        zip -9 -y -r ${{ env.PACKAGENAME }}.zip openmp.framework glslang.framework ncnn.framework
    - name: upload-zip
      uses: actions/upload-artifact@v4
      with:
        name: ${{ env.PACKAGENAME }}
        path: ${{ env.PACKAGENAME }}.zip

  android:
    needs: [setup]
    strategy:
      matrix:
        opt:
          - { vulkan: OFF, shared-lib: OFF, id: android               }
          - { vulkan: OFF, shared-lib: ON,  id: android-shared        }
          - { vulkan: ON,  shared-lib: OFF, id: android-vulkan        }
          - { vulkan: ON,  shared-lib: ON,  id: android-vulkan-shared }
    runs-on: ubuntu-latest
    env:
      PACKAGENAME: ncnn-${{ needs.setup.outputs.VERSION }}-${{ matrix.opt.id }}
      NCNN_CMAKE_OPTIONS: |
        -DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK_LATEST_HOME/build/cmake/android.toolchain.cmake \
        -DANDROID_PLATFORM=android-21 \
        -DANDROID_USE_LEGACY_TOOLCHAIN_FILE=False \
        -DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON \
        -DCMAKE_BUILD_TYPE=Release \
        -DCMAKE_INSTALL_PREFIX=install \
        -DNCNN_VERSION_STRING="${{ needs.setup.outputs.VERSION }}" \
        -DNCNN_BUILD_BENCHMARK=OFF \
        -DNCNN_VULKAN=${{ matrix.opt.vulkan }} \
        -DNCNN_SHARED_LIB=${{ matrix.opt.shared-lib }} \

    steps:
    - uses: actions/checkout@v4
      with:
        submodules: true
    - name: ndk-fix-debug
      run: sed -i -e '/^  -g$/d' $ANDROID_NDK_LATEST_HOME/build/cmake/android-legacy.toolchain.cmake
    - name: build-armeabi-v7a
      run: |
        mkdir build-armeabi-v7a && cd build-armeabi-v7a
        cmake ${{ env.NCNN_CMAKE_OPTIONS }} -DANDROID_ABI="armeabi-v7a" -DANDROID_ARM_NEON=ON ..
        cmake --build . -j $(nproc)
        cmake --build . --target install/strip
    - name: build-arm64-v8a
      run: |
        mkdir build-arm64-v8a && cd build-arm64-v8a
        cmake ${{ env.NCNN_CMAKE_OPTIONS }}-DANDROID_ABI="arm64-v8a" ..
        cmake --build . -j $(nproc)
        cmake --build . --target install/strip
    - name: build-x86
      run: |
        mkdir build-x86 && cd build-x86
        cmake ${{ env.NCNN_CMAKE_OPTIONS }}-DANDROID_ABI="x86" ..
        cmake --build . -j $(nproc)
        cmake --build . --target install/strip
    - name: build-x86_64
      run: |
        mkdir build-x86_64 && cd build-x86_64
        cmake ${{ env.NCNN_CMAKE_OPTIONS }}-DANDROID_ABI="x86_64" ..
        cmake --build . -j $(nproc)
        cmake --build . --target install/strip
    - name: build-riscv64
      run: |
        mkdir build-riscv64 && cd build-riscv64
        cmake ${{ env.NCNN_CMAKE_OPTIONS }}-DANDROID_ABI="riscv64" ..
        cmake --build . -j $(nproc)
        cmake --build . --target install/strip
    - name: package
      run: |
        rm -rf ${{ env.PACKAGENAME }}
        mkdir -p ${{ env.PACKAGENAME }}
        cp -a build-armeabi-v7a/install ${{ env.PACKAGENAME }}/armeabi-v7a
        cp -a build-arm64-v8a/install ${{ env.PACKAGENAME }}/arm64-v8a
        cp -a build-x86/install ${{ env.PACKAGENAME }}/x86
        cp -a build-x86_64/install ${{ env.PACKAGENAME }}/x86_64
        cp -a build-riscv64/install ${{ env.PACKAGENAME }}/riscv64
        rm -f ${{ env.PACKAGENAME }}.zip
        zip -9 -y -r ${{ env.PACKAGENAME }}.zip ${{ env.PACKAGENAME }}
    - name: upload-zip
      uses: actions/upload-artifact@v4
      with:
        name: ${{ env.PACKAGENAME }}
        path: ${{ env.PACKAGENAME }}.zip

  webassembly:
    needs: [setup]
    runs-on: ubuntu-latest
    env:
      PACKAGENAME: ncnn-${{ needs.setup.outputs.VERSION }}-webassembly
    steps:
    - uses: actions/checkout@v4
    - name: emsdk
      run: |
        git clone https://github.com/emscripten-core/emsdk.git
        cd emsdk
        ./emsdk install $EMSCRIPTEN_VERSION
        ./emsdk activate $EMSCRIPTEN_VERSION
    - name: build
      run: |
        source emsdk/emsdk_env.sh
        mkdir build && cd build
        cmake -DCMAKE_TOOLCHAIN_FILE=$EMSDK/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=install -DNCNN_VERSION_STRING="${{ needs.setup.outputs.VERSION }}" \
            -DNCNN_THREADS=OFF -DNCNN_OPENMP=OFF -DNCNN_SIMPLEOMP=OFF -DNCNN_SIMPLEOCV=ON -DNCNN_RUNTIME_CPU=OFF -DNCNN_SSE2=OFF -DNCNN_AVX2=OFF -DNCNN_AVX=OFF \
            -DNCNN_BUILD_TOOLS=OFF -DNCNN_BUILD_EXAMPLES=OFF -DNCNN_BUILD_BENCHMARK=OFF ..
        cmake --build . -j $(nproc)
        cmake --build . --target install/strip
    - name: build-simd
      run: |
        source emsdk/emsdk_env.sh
        mkdir build-simd && cd build-simd
        cmake -DCMAKE_TOOLCHAIN_FILE=$EMSDK/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=install -DNCNN_VERSION_STRING="${{ needs.setup.outputs.VERSION }}" \
            -DNCNN_THREADS=OFF -DNCNN_OPENMP=OFF -DNCNN_SIMPLEOMP=OFF -DNCNN_SIMPLEOCV=ON -DNCNN_RUNTIME_CPU=OFF -DNCNN_SSE2=ON -DNCNN_AVX2=OFF -DNCNN_AVX=OFF \
            -DNCNN_BUILD_TOOLS=OFF -DNCNN_BUILD_EXAMPLES=OFF -DNCNN_BUILD_BENCHMARK=OFF ..
        cmake --build . -j $(nproc)
        cmake --build . --target install/strip
    - name: build-threads
      run: |
        source emsdk/emsdk_env.sh
        mkdir build-threads && cd build-threads
        cmake -DCMAKE_TOOLCHAIN_FILE=$EMSDK/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=install -DNCNN_VERSION_STRING="${{ needs.setup.outputs.VERSION }}" \
            -DNCNN_THREADS=ON -DNCNN_OPENMP=ON -DNCNN_SIMPLEOMP=ON -DNCNN_SIMPLEOCV=ON -DNCNN_RUNTIME_CPU=OFF -DNCNN_SSE2=OFF -DNCNN_AVX2=OFF -DNCNN_AVX=OFF \
            -DNCNN_BUILD_TOOLS=OFF -DNCNN_BUILD_EXAMPLES=OFF -DNCNN_BUILD_BENCHMARK=OFF ..
        cmake --build . -j $(nproc)
        cmake --build . --target install/strip
    - name: build-simd-threads
      run: |
        source emsdk/emsdk_env.sh
        mkdir build-simd-threads && cd build-simd-threads
        cmake -DCMAKE_TOOLCHAIN_FILE=$EMSDK/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=install -DNCNN_VERSION_STRING="${{ needs.setup.outputs.VERSION }}" \
            -DNCNN_THREADS=ON -DNCNN_OPENMP=ON -DNCNN_SIMPLEOMP=ON -DNCNN_SIMPLEOCV=ON -DNCNN_RUNTIME_CPU=OFF -DNCNN_SSE2=ON -DNCNN_AVX2=OFF -DNCNN_AVX=OFF \
            -DNCNN_BUILD_TOOLS=OFF -DNCNN_BUILD_EXAMPLES=OFF -DNCNN_BUILD_BENCHMARK=OFF ..
        cmake --build . -j $(nproc)
        cmake --build . --target install/strip
    - name: package
      run: |
        rm -rf ${{ env.PACKAGENAME }}
        mkdir -p ${{ env.PACKAGENAME }}
        cp -a build/install ${{ env.PACKAGENAME }}/basic
        cp -a build-simd/install ${{ env.PACKAGENAME }}/simd
        cp -a build-threads/install ${{ env.PACKAGENAME }}/threads
        cp -a build-simd-threads/install ${{ env.PACKAGENAME }}/simd-threads
        rm -f ${{ env.PACKAGENAME }}.zip
        zip -9 -y -r ${{ env.PACKAGENAME }}.zip ${{ env.PACKAGENAME }}
    - name: upload-zip
      uses: actions/upload-artifact@v4
      with:
        name: ${{ env.PACKAGENAME }}
        path: ${{ env.PACKAGENAME }}.zip

  windows:
    needs: [setup]
    strategy:
      matrix:
        opt:
          - { shared-lib: OFF, os: windows-2019, toolset-version: v140, id: vs2015 }
          - { shared-lib: OFF, os: windows-2019, toolset-version: v141, id: vs2017 }
          - { shared-lib: OFF, os: windows-2019, toolset-version: v142, id: vs2019 }
          - { shared-lib: OFF, os: windows-2022, toolset-version: v143, id: vs2022 }
          - { shared-lib: ON,  os: windows-2019, toolset-version: v140, id: vs2015-shared }
          - { shared-lib: ON,  os: windows-2019, toolset-version: v141, id: vs2017-shared }
          - { shared-lib: ON,  os: windows-2019, toolset-version: v142, id: vs2019-shared }
          - { shared-lib: ON,  os: windows-2022, toolset-version: v143, id: vs2022-shared }
    runs-on: ${{ matrix.opt.os }}
    env:
      PACKAGENAME: ncnn-${{ needs.setup.outputs.VERSION }}-windows-${{ matrix.opt.id }}
      UseMultiToolTask: true
      NCNN_CMAKE_OPTIONS: |
        -T ${{ matrix.opt.toolset-version }},host=x64 `
        -DCMAKE_BUILD_TYPE=Release `
        -DCMAKE_INSTALL_PREFIX=install `
        -DNCNN_VERSION_STRING="${{ needs.setup.outputs.VERSION }}" `
        -DNCNN_BUILD_EXAMPLES=OFF `
        -DNCNN_BUILD_TOOLS=ON `
        -DNCNN_BUILD_BENCHMARK=OFF `
        -DNCNN_VULKAN=ON `
        -DNCNN_SHARED_LIB=${{ matrix.opt.shared-lib }} `

    steps:
    - uses: actions/checkout@v4
      with:
        submodules: true
    - name: cache-protobuf
      id: cache-protobuf
      uses: actions/cache@v4
      with:
        path: "protobuf-install"
        key: protobuf-${{ matrix.opt.toolset-version }}-x86-x64-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-x86; cd build-x86;
        cmake -T ${{ matrix.opt.toolset-version }},host=x64 -A Win32 -DCMAKE_INSTALL_PREFIX="$env:GITHUB_WORKSPACE\protobuf-install\x86" -Dprotobuf_BUILD_TESTS=OFF -Dprotobuf_MSVC_STATIC_RUNTIME=OFF ../cmake
        cmake --build . --config Release -j 4
        cmake --build . --config Release --target install
        cd ..
        mkdir build-x64; cd build-x64;
        cmake -T ${{ matrix.opt.toolset-version }},host=x64 -A x64 -DCMAKE_INSTALL_PREFIX="$env:GITHUB_WORKSPACE\protobuf-install\x64" -Dprotobuf_BUILD_TESTS=OFF -Dprotobuf_MSVC_STATIC_RUNTIME=OFF ../cmake
        cmake --build . --config Release -j 4
        cmake --build . --config Release --target install
    - name: build-x86
      run: |
        mkdir build-x86; cd build-x86
        cmake ${{ env.NCNN_CMAKE_OPTIONS }} -A Win32 -Dprotobuf_DIR="$env:GITHUB_WORKSPACE\protobuf-install\x86\cmake" ..
        cmake --build . --config Release -j 4
        cmake --build . --config Release --target install
    - name: build-x64
      run: |
        mkdir build-x64; cd build-x64
        cmake ${{ env.NCNN_CMAKE_OPTIONS }} -A x64 -Dprotobuf_DIR="$env:GITHUB_WORKSPACE\protobuf-install\x64\cmake" ..
        cmake --build . --config Release -j 4
        cmake --build . --config Release --target install
    - name: build-arm64
      if: matrix.opt.toolset-version == 'v142' || matrix.opt.toolset-version == 'v143'
      run: |
        mkdir build-arm64; cd build-arm64
        cmake ${{ env.NCNN_CMAKE_OPTIONS }} -A arm64 ..
        cmake --build . --config Release -j 4
        cmake --build . --config Release --target install
    - name: package
      if: matrix.opt.toolset-version == 'v140' || matrix.opt.toolset-version == 'v141'
      run: |
        mkdir ${{ env.PACKAGENAME }}
        mkdir ${{ env.PACKAGENAME }}/x86
        mkdir ${{ env.PACKAGENAME }}/x64
        Copy-Item -Verbose -Recurse -Path "build-x86\install\*" -Destination "${{ env.PACKAGENAME }}\x86"
        Copy-Item -Verbose -Recurse -Path "build-x64\install\*" -Destination "${{ env.PACKAGENAME }}\x64"
        7z a -r ${{ env.PACKAGENAME }}.zip ${{ env.PACKAGENAME }}
    - name: package
      if: matrix.opt.toolset-version == 'v142' || matrix.opt.toolset-version == 'v143'
      run: |
        mkdir ${{ env.PACKAGENAME }}
        mkdir ${{ env.PACKAGENAME }}/x86
        mkdir ${{ env.PACKAGENAME }}/x64
        mkdir ${{ env.PACKAGENAME }}/arm64
        Copy-Item -Verbose -Recurse -Path "build-x86\install\*" -Destination "${{ env.PACKAGENAME }}\x86"
        Copy-Item -Verbose -Recurse -Path "build-x64\install\*" -Destination "${{ env.PACKAGENAME }}\x64"
        Copy-Item -Verbose -Recurse -Path "build-arm64\install\*" -Destination "${{ env.PACKAGENAME }}\arm64"
        7z a -r ${{ env.PACKAGENAME }}.zip ${{ env.PACKAGENAME }}
    - name: upload-zip
      uses: actions/upload-artifact@v4
      with:
        name: ${{ env.PACKAGENAME }}
        path: ${{ env.PACKAGENAME }}.zip

  apple:
    needs: [setup, macos, ios, ios-simulator, mac-catalyst, watchos, watchos-simulator, tvos, tvos-simulator, visionos, visionos-simulator]
    runs-on: macos-13
    env:
      PACKAGENAME: ncnn-${{ needs.setup.outputs.VERSION }}-apple
    steps:
    - run: sudo xcode-select --switch /Applications/Xcode_15.2.app
    - name: download
      uses: actions/download-artifact@v4
      with:
        path: artifacts

    - name: unzip
      run: |
        mkdir -p ncnn-ios
        mkdir -p ncnn-ios-vulkan
        mkdir -p ncnn-ios-simulator
        mkdir -p ncnn-ios-simulator-vulkan
        mkdir -p ncnn-mac-catalyst
        mkdir -p ncnn-mac-catalyst-vulkan
        mkdir -p ncnn-macos
        mkdir -p ncnn-macos-vulkan
        mkdir -p ncnn-tvos
        mkdir -p ncnn-tvos-vulkan
        mkdir -p ncnn-tvos-simulator
        mkdir -p ncnn-tvos-simulator-vulkan
        mkdir -p ncnn-visionos
        mkdir -p ncnn-visionos-vulkan
        mkdir -p ncnn-visionos-simulator
        mkdir -p ncnn-visionos-simulator-vulkan
        mkdir -p ncnn-watchos
        mkdir -p ncnn-watchos-simulator

        unzip -q artifacts/ncnn-${{ needs.setup.outputs.VERSION }}-ios/ncnn-${{ needs.setup.outputs.VERSION }}-ios.zip -d ncnn-ios
        unzip -q artifacts/ncnn-${{ needs.setup.outputs.VERSION }}-ios-vulkan/ncnn-${{ needs.setup.outputs.VERSION }}-ios-vulkan.zip -d ncnn-ios-vulkan
        unzip -q artifacts/ncnn-${{ needs.setup.outputs.VERSION }}-ios-simulator/ncnn-${{ needs.setup.outputs.VERSION }}-ios-simulator.zip -d ncnn-ios-simulator
        unzip -q artifacts/ncnn-${{ needs.setup.outputs.VERSION }}-ios-simulator-vulkan/ncnn-${{ needs.setup.outputs.VERSION }}-ios-simulator-vulkan.zip -d ncnn-ios-simulator-vulkan
        unzip -q artifacts/ncnn-${{ needs.setup.outputs.VERSION }}-mac-catalyst/ncnn-${{ needs.setup.outputs.VERSION }}-mac-catalyst.zip -d ncnn-mac-catalyst
        unzip -q artifacts/ncnn-${{ needs.setup.outputs.VERSION }}-mac-catalyst-vulkan/ncnn-${{ needs.setup.outputs.VERSION }}-mac-catalyst-vulkan.zip -d ncnn-mac-catalyst-vulkan
        unzip -q artifacts/ncnn-${{ needs.setup.outputs.VERSION }}-macos/ncnn-${{ needs.setup.outputs.VERSION }}-macos.zip -d ncnn-macos
        unzip -q artifacts/ncnn-${{ needs.setup.outputs.VERSION }}-macos-vulkan/ncnn-${{ needs.setup.outputs.VERSION }}-macos-vulkan.zip -d ncnn-macos-vulkan
        unzip -q artifacts/ncnn-${{ needs.setup.outputs.VERSION }}-tvos/ncnn-${{ needs.setup.outputs.VERSION }}-tvos.zip -d ncnn-tvos
        unzip -q artifacts/ncnn-${{ needs.setup.outputs.VERSION }}-tvos-vulkan/ncnn-${{ needs.setup.outputs.VERSION }}-tvos-vulkan.zip -d ncnn-tvos-vulkan
        unzip -q artifacts/ncnn-${{ needs.setup.outputs.VERSION }}-tvos-simulator/ncnn-${{ needs.setup.outputs.VERSION }}-tvos-simulator.zip -d ncnn-tvos-simulator
        unzip -q artifacts/ncnn-${{ needs.setup.outputs.VERSION }}-tvos-simulator-vulkan/ncnn-${{ needs.setup.outputs.VERSION }}-tvos-simulator-vulkan.zip -d ncnn-tvos-simulator-vulkan
        unzip -q artifacts/ncnn-${{ needs.setup.outputs.VERSION }}-visionos/ncnn-${{ needs.setup.outputs.VERSION }}-visionos.zip -d ncnn-visionos
        unzip -q artifacts/ncnn-${{ needs.setup.outputs.VERSION }}-visionos-vulkan/ncnn-${{ needs.setup.outputs.VERSION }}-visionos-vulkan.zip -d ncnn-visionos-vulkan
        unzip -q artifacts/ncnn-${{ needs.setup.outputs.VERSION }}-visionos-simulator/ncnn-${{ needs.setup.outputs.VERSION }}-visionos-simulator.zip -d ncnn-visionos-simulator
        unzip -q artifacts/ncnn-${{ needs.setup.outputs.VERSION }}-visionos-simulator-vulkan/ncnn-${{ needs.setup.outputs.VERSION }}-visionos-simulator-vulkan.zip -d ncnn-visionos-simulator-vulkan
        unzip -q artifacts/ncnn-${{ needs.setup.outputs.VERSION }}-watchos/ncnn-${{ needs.setup.outputs.VERSION }}-watchos.zip -d ncnn-watchos
        unzip -q artifacts/ncnn-${{ needs.setup.outputs.VERSION }}-watchos-simulator/ncnn-${{ needs.setup.outputs.VERSION }}-watchos-simulator.zip -d ncnn-watchos-simulator

    - name: create-xcframwork
      run: |
        rm -rf openmp.xcframework
        xcodebuild -create-xcframework \
            -framework ncnn-macos/openmp.framework \
            -framework ncnn-ios/openmp.framework \
            -framework ncnn-ios-simulator/openmp.framework \
            -framework ncnn-mac-catalyst/openmp.framework \
            -framework ncnn-watchos/openmp.framework \
            -framework ncnn-watchos-simulator/openmp.framework \
            -framework ncnn-tvos/openmp.framework \
            -framework ncnn-tvos-simulator/openmp.framework \
            -framework ncnn-visionos/openmp.framework \
            -framework ncnn-visionos-simulator/openmp.framework \
            -output openmp.xcframework

        rm -rf ncnn.xcframework
        xcodebuild -create-xcframework \
            -framework ncnn-macos/ncnn.framework \
            -framework ncnn-ios/ncnn.framework \
            -framework ncnn-ios-simulator/ncnn.framework \
            -framework ncnn-mac-catalyst/ncnn.framework \
            -framework ncnn-watchos/ncnn.framework \
            -framework ncnn-watchos-simulator/ncnn.framework \
            -framework ncnn-tvos/ncnn.framework \
            -framework ncnn-tvos-simulator/ncnn.framework \
            -framework ncnn-visionos/ncnn.framework \
            -framework ncnn-visionos-simulator/ncnn.framework \
            -output ncnn.xcframework

        rm -f ${{ env.PACKAGENAME }}.zip
        zip -9 -y -r ${{ env.PACKAGENAME }}.zip openmp.xcframework ncnn.xcframework
    - name: create-xcframwork-vulkan
      run: |
        rm -rf openmp.xcframework
        xcodebuild -create-xcframework \
            -framework ncnn-macos-vulkan/openmp.framework \
            -framework ncnn-ios-vulkan/openmp.framework \
            -framework ncnn-ios-simulator-vulkan/openmp.framework \
            -framework ncnn-mac-catalyst-vulkan/openmp.framework \
            -framework ncnn-watchos/openmp.framework \
            -framework ncnn-watchos-simulator/openmp.framework \
            -framework ncnn-tvos-vulkan/openmp.framework \
            -framework ncnn-tvos-simulator-vulkan/openmp.framework \
            -framework ncnn-visionos/openmp.framework \
            -framework ncnn-visionos-simulator/openmp.framework \
            -output openmp.xcframework

        rm -rf glslang.xcframework
        xcodebuild -create-xcframework \
            -framework ncnn-macos-vulkan/glslang.framework \
            -framework ncnn-ios-vulkan/glslang.framework \
            -framework ncnn-ios-simulator-vulkan/glslang.framework \
            -framework ncnn-mac-catalyst-vulkan/glslang.framework \
            -framework ncnn-tvos-vulkan/glslang.framework \
            -framework ncnn-tvos-simulator-vulkan/glslang.framework \
            -framework ncnn-visionos-vulkan/glslang.framework \
            -framework ncnn-visionos-simulator-vulkan/glslang.framework \
            -output glslang.xcframework

        rm -rf ncnn.xcframework
        xcodebuild -create-xcframework \
            -framework ncnn-macos-vulkan/ncnn.framework \
            -framework ncnn-ios-vulkan/ncnn.framework \
            -framework ncnn-ios-simulator-vulkan/ncnn.framework \
            -framework ncnn-mac-catalyst-vulkan/ncnn.framework \
            -framework ncnn-watchos/ncnn.framework \
            -framework ncnn-watchos-simulator/ncnn.framework \
            -framework ncnn-tvos-vulkan/ncnn.framework \
            -framework ncnn-tvos-simulator-vulkan/ncnn.framework \
            -framework ncnn-visionos-vulkan/ncnn.framework \
            -framework ncnn-visionos-simulator-vulkan/ncnn.framework \
            -output ncnn.xcframework

        rm -f ${{ env.PACKAGENAME }}-vulkan.zip
        zip -9 -y -r ${{ env.PACKAGENAME }}-vulkan.zip openmp.xcframework glslang.xcframework ncnn.xcframework
    - name: upload-zip
      uses: actions/upload-artifact@v4
      with:
        name: ${{ env.PACKAGENAME }}
        path: ${{ env.PACKAGENAME }}.zip
    - name: upload-zip-vulkan
      uses: actions/upload-artifact@v4
      with:
        name: ${{ env.PACKAGENAME }}-vulkan
        path: ${{ env.PACKAGENAME }}-vulkan.zip

  release:
    permissions:
      contents: write  # for softprops/action-gh-release to create a release
    needs: [setup, full-source, ubuntu, macos, ios, ios-simulator, mac-catalyst, watchos, watchos-simulator, tvos, tvos-simulator, android, webassembly, windows, apple]
    runs-on: ubuntu-latest
    steps:
    - name: download
      uses: actions/download-artifact@v4
      with:
        path: artifacts

    - name: create-release
      uses: softprops/action-gh-release@v2
      with:
        token: ${{ secrets.GITHUB_TOKEN }}
        tag_name: ${{ needs.setup.outputs.VERSION }}
        name: Release ${{ needs.setup.outputs.VERSION }}
        files: artifacts/*/*.zip
