diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 0000000..c891e4e --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,7 @@ + + +--- + +### Contribution License Agreement + +- [ ] By placing an "x" in the box, I hereby understand, accept and agree to be bound by the terms and conditions of the [Contribution License Agreement](https://dena.github.io/cla/). \ No newline at end of file diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3aa4980..1066aad 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,431 +1,280 @@ -name: Build C++ Shared Library - -on: - push: - branches: - # - main - release: - types: - - published - workflow_dispatch: - inputs: - version: - description: "バージョン情報(A.BB.C / A.BB.C-preview.D)" - required: true - release: - description: "リリースするかどうか" - type: boolean - -env: - ONNXRUNTIME_VERSION: - |- # releaseタグ名か、workflow_dispatchでのバージョン名が入る。無指定なら適当なバージョン - ${{ github.event.release.tag_name || github.event.inputs.version || '1.16.3' }} - RELEASE: - |- # releaseタグ名か、workflow_dispatchでのreleaseフラグがあればリリースする - ${{ github.event.release.tag_name != '' || github.event.inputs.release == 'true' }} - -defaults: - run: - shell: bash - -jobs: - build-onnxruntime: - strategy: - fail-fast: false - matrix: - include: - - artifact_name: onnxruntime-win-x64 - os: windows-2022 - build_opts: --cmake_extra_defines CMAKE_SYSTEM_NAME=Windows CMAKE_SYSTEM_PROCESSOR=x86_64 --config Release --parallel --compile_no_warning_as_error --update --build --build_shared_lib - result_dir: build/Release - release_config: Release - - artifact_name: onnxruntime-win-x64-gpu - os: windows-2022 - cuda_version: 11.8.0 - # Windowsの場合デフォルトのパッケージ群では不十分であるため、必要そうなパッケージを指定する。ただしいくつかは不要かもしれない - cuda_sub_packages: '["cudart", "cuobjdump", "nvcc", "nvdisasm", "thrust", "cublas_dev", "cufft_dev", "curand_dev", "cusolver_dev", "cusparse_dev", "visual_studio_integration"]' - cudnn_url: https://developer.download.nvidia.com/compute/redist/cudnn/v8.5.0/local_installers/11.7/cudnn-windows-x86_64-8.5.0.96_cuda11-archive.zip - build_opts: --cmake_extra_defines CMAKE_SYSTEM_NAME=Windows CMAKE_SYSTEM_PROCESSOR=x86_64 --config Release --parallel --compile_no_warning_as_error --update --build --build_shared_lib --use_dml --use_cuda --cuda_version 11.8 - result_dir: build/Release - release_config: Release - - artifact_name: onnxruntime-win-x86 - os: windows-2022 - build_opts: --x86 --cmake_extra_defines CMAKE_SYSTEM_NAME=Windows CMAKE_SYSTEM_PROCESSOR=x86 --config Release --parallel --compile_no_warning_as_error --update --build --build_shared_lib - result_dir: build/Release - release_config: Release - - artifact_name: onnxruntime-linux-x64 - os: ubuntu-20.04 - build_opts: --cmake_extra_defines CMAKE_SYSTEM_NAME=Linux CMAKE_SYSTEM_PROCESSOR=x86_64 --config Release --parallel --compile_no_warning_as_error --update --build --build_shared_lib - result_dir: build - release_config: Release - - artifact_name: onnxruntime-linux-x64-gpu - os: ubuntu-20.04 - cuda_version: 11.8.0 - cuda_sub_packages: "[]" # デフォルト - cudnn_url: https://developer.download.nvidia.com/compute/redist/cudnn/v8.2.4/cudnn-11.4-linux-x64-v8.2.4.15.tgz - build_opts: --cmake_extra_defines CMAKE_SYSTEM_NAME=Linux CMAKE_SYSTEM_PROCESSOR=x86_64 --config Release --parallel --compile_no_warning_as_error --update --build --build_shared_lib --use_cuda - result_dir: build - release_config: Release - - artifact_name: onnxruntime-linux-armhf - os: ubuntu-20.04 - cc_version: "9" - cxx_version: "9" - linux_cross_arch: arm-linux-gnueabihf - symlink_workaround: true - build_opts: --arm --cmake_extra_defines CMAKE_SYSTEM_NAME=Linux CMAKE_SYSTEM_PROCESSOR=armv7l --config Release --parallel --compile_no_warning_as_error --update --build --build_shared_lib - result_dir: build - release_config: Release - - artifact_name: onnxruntime-linux-arm64 - os: ubuntu-20.04 - cc_version: "9" - cxx_version: "9" - linux_cross_arch: aarch64-linux-gnu - symlink_workaround: true - build_opts: --arm64 --cmake_extra_defines CMAKE_SYSTEM_NAME=Linux CMAKE_SYSTEM_PROCESSOR=aarch64 --config Release --parallel --compile_no_warning_as_error --update --build --build_shared_lib - result_dir: build - release_config: Release - - artifact_name: onnxruntime-osx-arm64 - os: macos-11 - build_opts: --cmake_extra_defines CMAKE_SYSTEM_NAME=Darwin CMAKE_OSX_ARCHITECTURES=arm64 --config Release --parallel --compile_no_warning_as_error --update --build --build_shared_lib - result_dir: build - release_config: Release - - artifact_name: onnxruntime-osx-x86_64 - os: macos-11 - build_opts: --cmake_extra_defines CMAKE_SYSTEM_NAME=Darwin CMAKE_OSX_ARCHITECTURES=x86_64 --config Release --parallel --compile_no_warning_as_error --update --build --build_shared_lib - result_dir: build - release_config: Release - - artifact_name: onnxruntime-android-x64 - os: ubuntu-20.04 - build_opts: --android_abi x86_64 --cmake_extra_defines CMAKE_SYSTEM_NAME=Android CMAKE_SYSTEM_PROCESSOR=x86_64 --config Release --parallel --compile_no_warning_as_error --update --build --build_shared_lib --android - result_dir: build - release_config: Release - - artifact_name: onnxruntime-android-arm64 - os: ubuntu-20.04 - build_opts: --android_abi arm64-v8a --cmake_extra_defines CMAKE_SYSTEM_NAME=Android CMAKE_SYSTEM_PROCESSOR=aarch64 --config Release --parallel --compile_no_warning_as_error --update --build --build_shared_lib --android - result_dir: build - release_config: Release - - artifact_name: onnxruntime-ios-arm64 - os: macos-12 - build_opts: --config Release --parallel --compile_no_warning_as_error --update --build --build_shared_lib --skip_tests --use_xcode --ios --ios_sysroot iphoneos --osx_arch arm64 --apple_deploy_target 16.0 - build_opts_workaround_protoc: --path_to_protoc_exe /usr/local/opt/protobuf@21/bin/protoc - result_dir: build/Release - release_config: Release-iphoneos - - artifact_name: onnxruntime-ios-sim-arm64 - os: macos-12 - build_opts: --config Release --parallel --compile_no_warning_as_error --update --build --build_shared_lib --skip_tests --use_xcode --ios --ios_sysroot iphonesimulator --osx_arch arm64 --apple_deploy_target 16.0 - build_opts_workaround_protoc: --path_to_protoc_exe /usr/local/opt/protobuf@21/bin/protoc - result_dir: build/Release - release_config: Release-iphonesimulator - - artifact_name: onnxruntime-ios-sim-x86_64 - os: macos-12 - build_opts: --config Release --parallel --compile_no_warning_as_error --update --build --build_shared_lib --skip_tests --use_xcode --ios --ios_sysroot iphonesimulator --osx_arch x86_64 --apple_deploy_target 16.0 - build_opts_workaround_protoc: --path_to_protoc_exe /usr/local/opt/protobuf@21/bin/protoc - result_dir: build/Release - release_config: Release-iphonesimulator - - env: - # prefix usage: "", "arm-linux-gnueabihf-" => "gcc-8", "arm-linux-gnueabihf-gcc-8" (command name) - # suffix usage: "", "-arm-linux-gnueabihf" => "gcc-8", "gcc-8-arm-linux-gnueabihf" (package name) - ARCH_PREFIX: "${{ (matrix.linux_cross_arch != '' && matrix.linux_cross_arch) || '' }}${{ (matrix.linux_cross_arch != '' && '-') || '' }}" - ARCH_SUFFIX: "${{ (matrix.linux_cross_arch != '' && '-') || '' }}${{ (matrix.linux_cross_arch != '' && matrix.linux_cross_arch) || '' }}" - - runs-on: ${{ matrix.os }} - - steps: - - uses: actions/setup-python@v4 - with: - python-version: "3.10" - - - name: Version check (semver) - run: | - VERSION="${{ env.ONNXRUNTIME_VERSION }}" - if [[ $VERSION =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)(-([0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*))?(\+([0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*))?$ ]]; then - echo "Version: $VERSION" - else - echo "$VERSION is not a valid semver." - exit 1 - fi - - - name: Checkout - uses: actions/checkout@v3 - with: - repository: microsoft/onnxruntime - submodules: true - ref: v${{ env.ONNXRUNTIME_VERSION }} - - - name: Dump matrix context - env: - MATRIX_CONTEXT: ${{ toJSON(matrix) }} - run: echo "$MATRIX_CONTEXT" > matrix.json - - - name: Cache build result - id: cache-build-result - uses: actions/cache@v3 - with: - path: build/ - key: ${{ matrix.artifact_name }}-v${{ env.ONNXRUNTIME_VERSION }}-cache-${{ hashFiles('matrix.json') }} - - - - name: Install tree - if: steps.cache-build-result.outputs.cache-hit != 'true' && runner.os == 'Windows' - uses: msys2/setup-msys2@v2 - with: - install: tree - - - name: Install tree for debug - if: steps.cache-build-result.outputs.cache-hit != 'true' && runner.os == 'macOS' - run: brew install tree - - - name: Install build dependencies on ubuntu - if: steps.cache-build-result.outputs.cache-hit != 'true' && startsWith(matrix.os, 'ubuntu') && matrix.linux_cross_arch - run: | - sudo apt-get update - sudo apt-get install -y \ - build-essential \ - git \ - wget \ - qemu-user-binfmt \ - gcc-${{ matrix.cc_version }}${{ env.ARCH_SUFFIX }} \ - g++-${{ matrix.cxx_version }}${{ env.ARCH_SUFFIX }} - - - name: Install build dependencies on macos - if: steps.cache-build-result.outputs.cache-hit != 'true' && startsWith(matrix.os, 'macos') - run: | - # Workaround for protoc https://github.com/microsoft/onnxruntime/issues/16238#issuecomment-1590398821 - brew install protobuf@21 - - # ONNX Runtime v1.16.1 requires CMake 3.27 or higher. - - name: Install CMake - if: steps.cache-build-result.outputs.cache-hit != 'true' && startsWith(matrix.os, 'ubuntu') - env: - CMAKE_VERSION: 3.27.7 - run: | - wget -O cmake.sh "https://github.com/Kitware/CMake/releases/download/v${{ env.CMAKE_VERSION }}/cmake-${{ env.CMAKE_VERSION }}-linux-x86_64.sh" - sudo bash cmake.sh --skip-license --prefix=/usr/local - - - name: Set up CUDA - if: steps.cache-build-result.outputs.cache-hit != 'true' && matrix.cuda_version && matrix.cudnn_url - uses: Jimver/cuda-toolkit@v0.2.11 - with: - cuda: ${{ matrix.cuda_version }} - sub-packages: ${{ matrix.cuda_sub_packages }} - method: network - - - name: Set `$CUDA_HOME` - if: steps.cache-build-result.outputs.cache-hit != 'true' && matrix.cuda_version && matrix.cudnn_url - run: echo "CUDA_HOME=$CUDA_PATH" >> "$GITHUB_ENV" - - - name: Set up cuDNN - if: steps.cache-build-result.outputs.cache-hit != 'true' && matrix.cuda_version && matrix.cudnn_url - run: | - mkdir download - - if [ ${{ runner.os }} = Windows ]; then - curl -L "${{ matrix.cudnn_url }}" > download/cudnn.zip - unzip download/cudnn.zip -d download - rm download/cudnn.zip - else - curl -L "${{ matrix.cudnn_url }}" > download/cudnn.tar.gz - tar xvf download/cudnn.tar.gz -C download/ - rm download/cudnn.tar.gz - fi - - cudnn_path=$(find download -maxdepth 1 -name 'cudnn-*') - : "${cudnn_path:=./download/cuda}" # https://developer.download.nvidia.com/compute/redist/cudnn/v8.2.4/cudnn-11.4-linux-x64-v8.2.4.15.tgz - if [ ${{ runner.os }} = Windows ]; then - cudnn_path=$(cygpath -wa "$cudnn_path") - else - cudnn_path=$(realpath "$cudnn_path") - fi - - echo "CUDNN_HOME=$cudnn_path" >> "$GITHUB_ENV" - - - name: Configure build environment for non-x86_64 Linux - if: steps.cache-build-result.outputs.cache-hit != 'true' && startsWith(matrix.os, 'ubuntu') && matrix.linux_cross_arch - run: | - # Required for arm build - # https://github.com/microsoft/onnxruntime/issues/4189#issuecomment-642528278 - echo 'string(APPEND CMAKE_C_FLAGS " -latomic")' >> cmake/CMakeLists.txt - echo 'string(APPEND CMAKE_CXX_FLAGS " -latomic")' >> cmake/CMakeLists.txt - - # Prevent Exec Format Error during cross-compiling - if ${{ matrix.symlink_workaround }}; then - find /usr/${{ matrix.linux_cross_arch }}/lib -name '*.so*' -exec sudo ln -s {} /usr/lib/${{ matrix.linux_cross_arch }}/ ';' - sudo ln -s /usr/${{ matrix.linux_cross_arch }}/lib/ld-linux-*.so* /usr/lib/ - fi - - # Set environment variable CC / CXX - echo "CC=${{ env.ARCH_PREFIX }}gcc-${{ matrix.cc_version }}" >> "$GITHUB_ENV" - echo "CXX=${{ env.ARCH_PREFIX }}g++-${{ matrix.cxx_version }}" >> "$GITHUB_ENV" - - - name: Build ONNX Runtime - if: steps.cache-build-result.outputs.cache-hit != 'true' - run: | - # add --arm for gcc-8: https://github.com/microsoft/onnxruntime/issues/4189 - # skip test: https://github.com/microsoft/onnxruntime/issues/2436 - # ONNX Runtime v1.9.0 requires CMAKE_SYSTEM_PROCESSOR, https://github.com/microsoft/onnxruntime/releases/tag/v1.9.0 - # Both CMAKE_SYSTEM_NAME and CMAKE_SYSTEM_PROCESSOR are required. - python ./tools/ci_build/build.py --build_dir ./build ${{ matrix.build_opts }} ${{ matrix.build_opts_workaround_protoc }} - - - name: Inspect the build directory for debug - - if: steps.cache-build-result.outputs.cache-hit != 'true' - run: | - if [ ${{ runner.os }} = Windows ]; then - tree() { - msys2.cmd -c "tree $1" - } - fi - tree build - - - name: Organize artifact - run: | - # コピー先artifactを予め削除しておく - rm -rf ${{ matrix.result_dir }}/${{ matrix.artifact_name }} - rm -rf ./artifact - # Set library name - if [[ ${{ matrix.artifact_name }} == onnxruntime-win-* ]]; then - ONNXRUNTIME_NAME=onnxruntime.dll - elif [[ ${{ matrix.artifact_name }} == onnxruntime-linux-* ]]; then - ONNXRUNTIME_NAME=libonnxruntime.so.${{ env.ONNXRUNTIME_VERSION }} - elif [[ ${{ matrix.artifact_name }} == onnxruntime-android-* ]]; then - ONNXRUNTIME_NAME=libonnxruntime.so - elif [[ ${{ matrix.artifact_name }} == onnxruntime-osx-* ]] || [[ ${{ matrix.artifact_name }} == onnxruntime-ios-* ]]; then - ONNXRUNTIME_NAME=libonnxruntime.${{ env.ONNXRUNTIME_VERSION }}.dylib - else - echo "Unknown target found : ${{ matrix.artifact_name }}" - return 1 - fi - if [ ${{ runner.os }} = Windows ]; then - # https://github.com/microsoft/onnxruntime/blob/v1.16.3/tools/ci_build/github/azure-pipelines/templates/c-api-artifacts-package-and-publish-steps-windows.yml#L34-L72 - # ただし、ortクレートには.pdbとinclude/は不要なので入れない。 - mkdir -p ./${{ matrix.result_dir }}/${{ matrix.artifact_name }}/lib - git rev-parse HEAD > ./${{ matrix.result_dir }}/${{ matrix.artifact_name }}/GIT_COMMIT_ID - cp ./{docs/Privacy.md,LICENSE,README.md,ThirdPartyNotices.txt,VERSION_NUMBER} \ - ./${{ matrix.result_dir }}/${{ matrix.artifact_name }}/ - cp ./${{ matrix.result_dir }}/${{ matrix.release_config }}/onnxruntime.{dll,lib} \ - ./${{ matrix.result_dir }}/${{ matrix.artifact_name }}/lib/ - if [ -f ./${{ matrix.result_dir }}/${{ matrix.release_config }}/onnxruntime_providers_cuda.dll ]; then - cp ./${{ matrix.result_dir }}/${{ matrix.release_config }}//onnxruntime_providers_{cuda,shared}.{dll,lib} \ - ./${{ matrix.result_dir }}/${{ matrix.artifact_name }}/lib/ - fi - else - ./tools/ci_build/github/linux/copy_strip_binary.sh \ - -r ${{ matrix.result_dir }} \ - -a ${{ matrix.artifact_name }} \ - -l $ONNXRUNTIME_NAME \ - -c ${{ matrix.release_config }} \ - -s "$(pwd)" \ - -t "$(git rev-parse HEAD)" - fi - mv ${{ matrix.result_dir }}/${{ matrix.artifact_name }} ./artifact/ - - - name: Upload artifact - uses: actions/upload-artifact@v4 - with: - name: ${{ matrix.artifact_name }} - path: artifact/* - - - name: Generate RELEASE_NAME - if: env.RELEASE == 'true' - run: | - echo "RELEASE_NAME=${{ matrix.artifact_name }}-${{ env.ONNXRUNTIME_VERSION }}" >> $GITHUB_ENV - - - name: Rearchive artifact - if: env.RELEASE == 'true' - run: | - mv artifact/ "${{ env.RELEASE_NAME }}" - tar cfz "${{ env.RELEASE_NAME }}.tgz" "${{ env.RELEASE_NAME }}/" - - - name: Upload to Release - if: env.RELEASE == 'true' - uses: svenstaro/upload-release-action@v2 - with: - repo_token: ${{ secrets.GITHUB_TOKEN }} - tag: ${{ env.ONNXRUNTIME_VERSION }} # ==> github.event.release.tag_name - file: ${{ env.RELEASE_NAME }}.tgz - - build-xcframework: - needs: build-onnxruntime - runs-on: macos-12 - steps: - - name: Generate RELEASE_NAME and ONNXRUNTIME_BASENAME - run: | - echo "RELEASE_NAME=onnxruntime-ios-xcframework-${{ env.ONNXRUNTIME_VERSION }}" >> $GITHUB_ENV - echo "ONNXRUNTIME_BASENAME=libonnxruntime.${{ env.ONNXRUNTIME_VERSION }}.dylib" >> "$GITHUB_ENV" - - - uses: actions/checkout@v3 - - - uses: actions/download-artifact@v4 - with: - name: onnxruntime-ios-arm64 - path: artifact/onnxruntime-aarch64-apple-ios - - - uses: actions/download-artifact@v4 - with: - name: onnxruntime-ios-sim-arm64 - path: artifact/onnxruntime-aarch64-apple-ios-sim - - - uses: actions/download-artifact@v4 - with: - name: onnxruntime-ios-sim-x86_64 - path: artifact/onnxruntime-x86_64-apple-ios - - - name: Remove no version notation dylib - run: | - rm -f artifact/onnxruntime-x86_64-apple-ios/lib/*onnxruntime.dylib - rm -f artifact/onnxruntime-aarch64-apple-ios-sim/lib/*onnxruntime.dylib - rm -f artifact/onnxruntime-aarch64-apple-ios/lib/*onnxruntime.dylib - - - name: Create aarch64 Framework - run: | - mkdir -p "Framework-aarch64" - cp -vr xcframework/Frameworks/aarch64/ Framework-aarch64/ - - lipo -create "artifact/onnxruntime-aarch64-apple-ios/lib/${{ env.ONNXRUNTIME_BASENAME }}" \ - -output "Framework-aarch64/onnxruntime.framework/onnxruntime" - - - name: Change aarch64 @rpath - run: | - install_name_tool -id "@rpath/onnxruntime.framework/onnxruntime" \ - "Framework-aarch64/onnxruntime.framework/onnxruntime" - - - name: Create fat binary - run: | - mkdir -p "artifact/onnxruntime-sim" - lipo -create "artifact/onnxruntime-x86_64-apple-ios/lib/${{ env.ONNXRUNTIME_BASENAME }}" \ - "artifact/onnxruntime-aarch64-apple-ios-sim/lib/${{ env.ONNXRUNTIME_BASENAME }}" \ - -output "artifact/onnxruntime-sim/onnxruntime" - - - name: Create sim Framework - run: | - mkdir -p "Framework-sim" - cp -vr xcframework/Frameworks/sim/ Framework-sim/ - cp -v "artifact/onnxruntime-sim/onnxruntime" \ - "Framework-sim/onnxruntime.framework/onnxruntime" - - - name: Change sim @rpath - run: | - install_name_tool -id "@rpath/onnxruntime.framework/onnxruntime" \ - "Framework-sim/onnxruntime.framework/onnxruntime" - - - name: Create XCFramework - run: | - mkdir -p "artifact/${{ env.ONNXRUNTIME_BASENAME }}" - xcodebuild -create-xcframework \ - -framework Framework-sim/onnxruntime.framework \ - -framework Framework-aarch64/onnxruntime.framework \ - -output "artifact/${{ env.ONNXRUNTIME_BASENAME }}/onnxruntime.xcframework" - - - name: Archive artifact - run: | - cd artifact/${{ env.ONNXRUNTIME_BASENAME }} - 7z a "../../${{ env.RELEASE_NAME }}.zip" "onnxruntime.xcframework" - - - name: Upload to Release - if: env.RELEASE == 'true' - uses: svenstaro/upload-release-action@v2 - with: - repo_token: ${{ secrets.GITHUB_TOKEN }} - tag: ${{ env.ONNXRUNTIME_VERSION }} # ==> github.event.release.tag_name - file: ${{ env.RELEASE_NAME }}.zip +name: Build minimal ONNX Runtime + +on: + release: + types: + - published + workflow_dispatch: + inputs: + version: + description: "Semantic version (e.g., 1.17.0)" + required: true + repository: + description: "Name of a target repository" + default: 'microsoft/onnxruntime' + required: false + +env: + ORT_PYTHON_VERSION: '3.10' + VERSION: + |- # Enter release tag name or version in workflow_dispatch. Recent version if not specified + ${{ github.event.release.tag_name || github.event.inputs.version || '1.17.0' }} + REPOSITORY: + ${{ github.event.inputs.repository || 'microsoft/onnxruntime' }} + +defaults: + run: + shell: bash + +jobs: + build: + strategy: + fail-fast: false + matrix: + include: + - artifact_name: onnxruntime-win-x64-minimal + os: windows-2022 + build_opts: --minimal_build --disable_ml_ops --enable_reduced_operator_type_support --cmake_extra_defines CMAKE_SYSTEM_NAME=Windows CMAKE_SYSTEM_PROCESSOR=x86_64 + result_dir: build/Release + release_config: Release + - artifact_name: onnxruntime-linux-x64-minimal + os: ubuntu-20.04 + build_opts: --minimal_build --disable_ml_ops --enable_reduced_operator_type_support --cmake_extra_defines CMAKE_SYSTEM_NAME=Linux CMAKE_SYSTEM_PROCESSOR=x86_64 + result_dir: build + release_config: Release + - artifact_name: onnxruntime-linux-armhf-minimal + os: ubuntu-20.04 + cc_version: "10" + cxx_version: "10" + linux_cross_arch: arm-linux-gnueabihf + symlink_workaround: true + build_opts: --minimal_build --disable_ml_ops --enable_reduced_operator_type_support --arm --cmake_extra_defines CMAKE_SYSTEM_NAME=Linux CMAKE_SYSTEM_PROCESSOR=armv7l + result_dir: build + release_config: Release + - artifact_name: onnxruntime-linux-arm64-minimal + os: ubuntu-20.04 + cc_version: "10" + cxx_version: "10" + linux_cross_arch: aarch64-linux-gnu + symlink_workaround: true + build_opts: --minimal_build --disable_ml_ops --enable_reduced_operator_type_support --arm64 --cmake_extra_defines CMAKE_SYSTEM_NAME=Linux CMAKE_SYSTEM_PROCESSOR=aarch64 + result_dir: build + release_config: Release + - artifact_name: onnxruntime-osx-arm64-minimal + os: macos-12 + build_opts: --minimal_build --disable_ml_ops --enable_reduced_operator_type_support --cmake_extra_defines CMAKE_SYSTEM_NAME=Darwin CMAKE_OSX_ARCHITECTURES=arm64 + result_dir: build + release_config: Release + - artifact_name: onnxruntime-osx-x86_64-minimal + os: macos-12 + build_opts: --minimal_build --disable_ml_ops --enable_reduced_operator_type_support --cmake_extra_defines CMAKE_SYSTEM_NAME=Darwin CMAKE_OSX_ARCHITECTURES=x86_64 + result_dir: build + release_config: Release + - artifact_name: onnxruntime-osx-universal2-minimal + os: macos-12 + build_opts: --minimal_build --disable_ml_ops --enable_reduced_operator_type_support --cmake_extra_defines CMAKE_SYSTEM_NAME=Darwin CMAKE_OSX_ARCHITECTURES="x86_64;arm64" + result_dir: build + release_config: Release + - artifact_name: onnxruntime-android-x86_64-minimal + os: ubuntu-20.04 + build_opts: --minimal_build=extended --use_nnapi --disable_ml_ops --disable_exceptions --disable_rtti --enable_reduced_operator_type_support --android_abi x86_64 --cmake_extra_defines CMAKE_SYSTEM_NAME=Android CMAKE_SYSTEM_PROCESSOR=x86_64 --android + result_dir: build + release_config: Release + - artifact_name: onnxruntime-android-arm64-minimal + os: ubuntu-20.04 + build_opts: --minimal_build=extended --use_nnapi --disable_ml_ops --disable_exceptions --disable_rtti --enable_reduced_operator_type_support --android_abi arm64-v8a --cmake_extra_defines CMAKE_SYSTEM_NAME=Android CMAKE_SYSTEM_PROCESSOR=aarch64 --android + result_dir: build + release_config: Release + + env: + # prefix usage: "", "arm-linux-gnueabihf-" => "gcc-8", "arm-linux-gnueabihf-gcc-8" (command name) + # suffix usage: "", "-arm-linux-gnueabihf" => "gcc-8", "gcc-8-arm-linux-gnueabihf" (package name) + ARCH_PREFIX: "${{ (matrix.linux_cross_arch != '' && matrix.linux_cross_arch) || '' }}${{ (matrix.linux_cross_arch != '' && '-') || '' }}" + ARCH_SUFFIX: "${{ (matrix.linux_cross_arch != '' && '-') || '' }}${{ (matrix.linux_cross_arch != '' && matrix.linux_cross_arch) || '' }}" + + runs-on: ${{ matrix.os }} + + steps: + - uses: actions/checkout@v4 + with: + repository: ${{ env.REPOSITORY }} + ref: v${{ env.VERSION }} + submodules: recursive + github-server-url: https://github.com + + - name: Checkout builder + uses: actions/checkout@v4 + with: + path: builder + + - name: Apply patch + run: | + git apply --ignore-whitespace --reject --whitespace=fix --verbose ./builder/1_17_patch.patch + + - uses: actions/setup-python@v5 + with: + python-version: ${{ env.ORT_PYTHON_VERSION }} + + - name: Install build dependencies on ubuntu + if: startsWith(matrix.os, 'ubuntu') && matrix.linux_cross_arch + run: | + sudo apt-get update + sudo apt-get install -y \ + build-essential \ + git \ + wget \ + qemu-user-binfmt \ + gcc-${{ matrix.cc_version }}${{ env.ARCH_SUFFIX }} \ + g++-${{ matrix.cc_version }}${{ env.ARCH_SUFFIX }} + + - name: Install build dependencies on macos + if: startsWith(matrix.os, 'macos') + run: | + pip install --no-cache-dir flatbuffers + + # ONNX Runtime v1.16.1 requires CMake 3.27 or higher. + - name: Install CMake + if: startsWith(matrix.os, 'ubuntu') + env: + CMAKE_VERSION: 3.27.7 + run: | + wget -O cmake.sh "https://github.com/Kitware/CMake/releases/download/v${{ env.CMAKE_VERSION }}/cmake-${{ env.CMAKE_VERSION }}-linux-x86_64.sh" + sudo bash cmake.sh --skip-license --prefix=/usr/local + + - name: Configure build environment for non-x86_64 Linux + if: startsWith(matrix.os, 'ubuntu') && matrix.linux_cross_arch + run: | + # Required for arm build + # https://github.com/microsoft/onnxruntime/issues/4189#issuecomment-642528278 + echo 'string(APPEND CMAKE_C_FLAGS " -latomic")' >> cmake/CMakeLists.txt + echo 'string(APPEND CMAKE_CXX_FLAGS " -latomic")' >> cmake/CMakeLists.txt + + # Prevent Exec Format Error during cross-compiling + if ${{ matrix.symlink_workaround }}; then + find /usr/${{ matrix.linux_cross_arch }}/lib -name '*.so*' -exec sudo ln -s {} /usr/lib/${{ matrix.linux_cross_arch }}/ ';' + sudo ln -s /usr/${{ matrix.linux_cross_arch }}/lib/ld-linux-*.so* /usr/lib/ + fi + + # Set environment variable CC / CXX + echo "CC=${{ env.ARCH_PREFIX }}gcc-${{ matrix.cc_version }}" >> "$GITHUB_ENV" + echo "CXX=${{ env.ARCH_PREFIX }}g++-${{ matrix.cxx_version }}" >> "$GITHUB_ENV" + + - name: Configure to use latest Android NDK + if: startsWith(matrix.os, 'ubuntu') && startsWith(matrix.artifact_name, 'onnxruntime-android') + run: | + # https://github.com/actions/runner-images/blob/main/images/ubuntu/Ubuntu2004-Readme.md#environment-variables-2 + echo "ANDROID_NDK_HOME=$ANDROID_NDK_LATEST_HOME" >> "$GITHUB_ENV" + + - name: Build ONNX Runtime + run: | + python ./tools/ci_build/build.py --build_dir ./build ${{ matrix.build_opts }} --config Release --parallel --compile_no_warning_as_error --update --build --build_shared_lib --skip_tests + + - name: Organize artifact + run: | + # Set library name + if [[ ${{ matrix.artifact_name }} == onnxruntime-win-* ]]; then + ONNXRUNTIME_NAME=onnxruntime.dll + elif [[ ${{ matrix.artifact_name }} == onnxruntime-linux-* ]]; then + ONNXRUNTIME_NAME=libonnxruntime.so.${{ env.VERSION }} + elif [[ ${{ matrix.artifact_name }} == onnxruntime-android-* ]]; then + ONNXRUNTIME_NAME=libonnxruntime.so + elif [[ ${{ matrix.artifact_name }} == onnxruntime-osx-* ]]; then + ONNXRUNTIME_NAME=libonnxruntime.${{ env.VERSION }}.dylib + else + echo "Unknown target found : ${{ matrix.artifact_name }}" + return 1 + fi + ./tools/ci_build/github/linux/copy_strip_binary.sh \ + -r ${{ matrix.result_dir }} \ + -a ${{ matrix.artifact_name }} \ + -l $ONNXRUNTIME_NAME \ + -c ${{ matrix.release_config }} \ + -s "$(pwd)" \ + -t "$(git rev-parse HEAD)" + mv ${{ matrix.result_dir }}/${{ matrix.artifact_name }} "${{ matrix.artifact_name }}-${{ env.VERSION }}" + tar cfz "${{ matrix.artifact_name }}-${{ env.VERSION }}.tgz" "${{ matrix.artifact_name }}-${{ env.VERSION }}/" + + - name: Upload to Release + uses: svenstaro/upload-release-action@v2 + with: + file: "*.tgz" + tag: ${{ env.VERSION }} + overwrite: true + file_glob: true + + build-aar: + strategy: + fail-fast: false + matrix: + include: + - artifact_name: onnxruntime-android-aar-minimal + os: ubuntu-22.04 + build_settings: tools/ci_build/github/android/default_mobile_aar_build_settings.json + build_variant: mobile + release_config: Release + + runs-on: ${{ matrix.os }} + + steps: + - uses: actions/checkout@v4 + with: + repository: ${{ env.REPOSITORY }} + ref: v${{ env.VERSION }} + submodules: recursive + github-server-url: https://github.com + + - name: Build ONNX Runtime + run: | + python tools/android_custom_build/build_custom_android_package.py --build_settings ${{ matrix.build_settings }} --config ${{ matrix.release_config }} --onnxruntime_branch_or_tag v${{ env.VERSION }} ./build + mv "./build/output/aar_out/Release/com/microsoft/onnxruntime/onnxruntime-${{ matrix.build_variant }}/${{ env.VERSION }}/" "${{ matrix.artifact_name }}-${{ env.VERSION }}" + tar cfz "${{ matrix.artifact_name }}-${{ env.VERSION }}.tgz" "${{ matrix.artifact_name }}-${{ env.VERSION }}/" + + - name: Upload to Release + uses: svenstaro/upload-release-action@v2 + with: + file: "*.tgz" + tag: ${{ env.VERSION }} + overwrite: true + file_glob: true + + build-xcframework: + strategy: + fail-fast: false + matrix: + include: + - artifact_name: onnxruntime-ios-xcframework-minimal + os: macos-12 + build_settings: tools/ci_build/github/apple/default_mobile_ios_framework_build_settings.json + release_config: MinSizeRel + + runs-on: ${{ matrix.os }} + + steps: + - uses: actions/checkout@v4 + with: + repository: ${{ env.REPOSITORY }} + ref: v${{ env.VERSION }} + submodules: recursive + github-server-url: https://github.com + + - uses: actions/setup-python@v5 + with: + python-version: ${{ env.ORT_PYTHON_VERSION }} + + - name: Install build dependencies on macos + run: | + pip install --no-cache-dir flatbuffers + + - name: Build ONNX Runtime + run: | + python tools/ci_build/github/apple/build_apple_framework.py ${{ matrix.build_settings }} --config ${{ matrix.release_config }} + mv build/apple_framework/framework_out/ "${{ matrix.artifact_name }}-${{ env.VERSION }}" + 7z a "${{ matrix.artifact_name }}-${{ env.VERSION }}.zip" "${{ matrix.artifact_name }}-${{ env.VERSION }}" + + - name: Upload to Release + uses: svenstaro/upload-release-action@v2 + with: + file: "*.zip" + tag: ${{ env.VERSION }} + overwrite: true + file_glob: true diff --git a/1_17_patch.patch b/1_17_patch.patch new file mode 100644 index 0000000..2484f67 --- /dev/null +++ b/1_17_patch.patch @@ -0,0 +1,22 @@ +diff --git a/tools/ci_build/build.py b/tools/ci_build/build.py +index 31f242cce..c42ba9386 100644 +--- a/tools/ci_build/build.py ++++ b/tools/ci_build/build.py +@@ -987,6 +987,8 @@ def generate_build_tree( + disable_optional_type = "optional" in types_to_disable + disable_sparse_tensors = "sparsetensor" in types_to_disable + ++ is_x86_64_build = not (args.android or args.ios or args.build_wasm or args.arm or args.arm64 or args.arm64ec) ++ + cmake_args += [ + "-Donnxruntime_RUN_ONNX_TESTS=" + ("ON" if args.enable_onnx_tests else "OFF"), + "-Donnxruntime_GENERATE_TEST_REPORTS=ON", +@@ -1569,7 +1571,7 @@ def generate_build_tree( + "-pipe", + "-ggdb3", + ] +- if is_linux() and platform.machine() == "x86_64": ++ if is_linux() and is_x86_64_build: + # The following flags needs GCC 8 and newer + cflags += ["-fstack-clash-protection", "-fcf-protection"] + cxxflags = cflags.copy() diff --git a/LICENSE b/LICENSE index fe22e76..496f05a 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,8 @@ MIT License Copyright (c) 2021 VOICEVOX +Copyright (c) 2021 other contributors +Copyright (c) 2024 DeNA Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 151b4f8..81e2cfd 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,32 @@ # onnxruntime-builder -VOICEVOX COREで利用するonnxruntimeのビルドを行うリポジトリ -## ビルド +Build [**minimal** ONNX Runtime](https://onnxruntime.ai/docs/build/custom.html#minimal-build) with GitHub Actions. -Github Actions から workflow_dispatch を起動。 +This repository is derived from [VOICEVOX/onnxruntime-builder](https://github.com/VOICEVOX/onnxruntime-builder). -## リリース +## Supported Platforms -Releases からタグを指定して Publish releases 。 +You can download the archived files of the runtime binaries from [Releases](https://github.com/stakemura/onnxruntime-builder/releases). + +| Platform | Type | ABI | Archived file | +|----------|--------|-------------|---------------------------------------| +| Android | .so | armeabi-v7a | `onnxruntime-runtime-android-arm-*.tgz` | +| Android | .so | arm64-v8a | `onnxruntime-runtime-android-arm64-*.tgz` | +| Android | .so | x86_64 | `onnxruntime-runtime-android-x86_64-*.tgz` | +| Android | .aar | armeabi-v7, aarm64-v8a, x86_64 | `onnxruntime-runtime-android-aar-*.tgz` | +| iOS | .xcframework | arm64, x86_64 | `onnxruntime-runtime-ios-xcframework-*.zip`| +| Linux | .so | armv7l | `onnxruntime-runtime-linux-armhf-*.tgz` | +| Linux | .so | aarch64 | `onnxruntime-runtime-linux-arm64-*.tgz` | +| Linux | .so | x64 | `onnxruntime-runtime-linux-x64-*.tgz` | +| macOS | .dylib | universal (arm64, x86_64) | `onnxruntime-runtime-osx-universal2-*.tgz` | +| macOS | .dylib | arm64 | `onnxruntime-runtime-osx-arm64-*.tgz` | +| macOS | .dylib | x86_64 | `onnxruntime-runtime-osx-x86_64-*.tgz` | +| Windows | .dll | x64 | `onnxruntime-runtime-win-x64-*.tgz` | + +## License + +MIT License + +## How to contribute + +Open an issue or create a pull request. diff --git a/xcframework/Frameworks/aarch64/onnxruntime.framework/Info.plist b/xcframework/Frameworks/aarch64/onnxruntime.framework/Info.plist deleted file mode 100644 index be5bf54..0000000 --- a/xcframework/Frameworks/aarch64/onnxruntime.framework/Info.plist +++ /dev/null @@ -1,55 +0,0 @@ - - - - - BuildMachineOSBuild - 23B81 - CFBundleDevelopmentRegion - en - CFBundleExecutable - onnxruntime - CFBundleIdentifier - jp.hiroshiba.voicevox.onnxruntime - CFBundleInfoDictionaryVersion - 6.0 - CFBundleName - onnxruntime - CFBundlePackageType - FMWK - CFBundleShortVersionString - 1.0 - CFBundleSupportedPlatforms - - iPhoneOS - - CFBundleVersion - 1 - DTCompiler - com.apple.compilers.llvm.clang.1_0 - DTPlatformBuild - 21C52 - DTPlatformName - iphoneos - DTPlatformVersion - 17.2 - DTSDKBuild - 21C52 - DTSDKName - iphoneos17.2 - DTXcode - 1510 - DTXcodeBuild - 15C65 - MinimumOSVersion - 16.0 - UIDeviceFamily - - 1 - 2 - - UIRequiredDeviceCapabilities - - arm64 - - - diff --git a/xcframework/Frameworks/aarch64/onnxruntime.framework/Modules/module.modulemap b/xcframework/Frameworks/aarch64/onnxruntime.framework/Modules/module.modulemap deleted file mode 100644 index 3d3962a..0000000 --- a/xcframework/Frameworks/aarch64/onnxruntime.framework/Modules/module.modulemap +++ /dev/null @@ -1,5 +0,0 @@ -framework module onnxruntime { - export * - - module * { export * } -} diff --git a/xcframework/Frameworks/sim/onnxruntime.framework/Info.plist b/xcframework/Frameworks/sim/onnxruntime.framework/Info.plist deleted file mode 100644 index a6e8e87..0000000 --- a/xcframework/Frameworks/sim/onnxruntime.framework/Info.plist +++ /dev/null @@ -1,51 +0,0 @@ - - - - - BuildMachineOSBuild - 23B81 - CFBundleDevelopmentRegion - en - CFBundleExecutable - onnxruntime - CFBundleIdentifier - jp.hiroshiba.voicevox.onnxruntime - CFBundleInfoDictionaryVersion - 6.0 - CFBundleName - onnxruntime - CFBundlePackageType - FMWK - CFBundleShortVersionString - 1.0 - CFBundleSupportedPlatforms - - iPhoneSimulator - - CFBundleVersion - 1 - DTCompiler - com.apple.compilers.llvm.clang.1_0 - DTPlatformBuild - 21C52 - DTPlatformName - iphonesimulator - DTPlatformVersion - 17.2 - DTSDKBuild - 21C52 - DTSDKName - iphonesimulator17.2 - DTXcode - 1510 - DTXcodeBuild - 15C65 - MinimumOSVersion - 16.0 - UIDeviceFamily - - 1 - 2 - - - diff --git a/xcframework/Frameworks/sim/onnxruntime.framework/Modules/module.modulemap b/xcframework/Frameworks/sim/onnxruntime.framework/Modules/module.modulemap deleted file mode 100644 index 3d3962a..0000000 --- a/xcframework/Frameworks/sim/onnxruntime.framework/Modules/module.modulemap +++ /dev/null @@ -1,5 +0,0 @@ -framework module onnxruntime { - export * - - module * { export * } -} diff --git a/xcframework/README.md b/xcframework/README.md deleted file mode 100644 index 3dda8f3..0000000 --- a/xcframework/README.md +++ /dev/null @@ -1,6 +0,0 @@ -# xcframeworkフォルダの内容について -## Frameworks - -iOS向けの配布ライブラリXCFramework内のFrameworkを作るための雛形です。 -雛形は端末用とシミュレータ用の2種類です。 -