Build minimal ONNX Runtime #13
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build minimal ONNX Runtime | |
on: | |
release: | |
types: | |
- published | |
workflow_dispatch: | |
inputs: | |
version: | |
description: "Semantic version (e.g., 1.18.1)" | |
required: true | |
repository: | |
description: "Name of a target repository" | |
default: 'microsoft/onnxruntime' | |
required: false | |
env: | |
ORT_PYTHON_VERSION: '3.10' | |
TARGET_LIBRARY: 'onnxruntime' | |
ONNXRUNTIME_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.18.1' }} | |
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 | |
--enable_msvc_static_runtime | |
--cmake_extra_defines | |
CMAKE_SYSTEM_NAME=Windows | |
CMAKE_SYSTEM_PROCESSOR=x86_64 # required for `cpuinfo` | |
result_dir: build/Release | |
release_config: Release | |
- artifact_name: onnxruntime-win-x86-minimal | |
os: windows-2022 | |
build_opts: |- | |
--minimal_build | |
--disable_ml_ops | |
--enable_reduced_operator_type_support | |
--enable_msvc_static_runtime | |
--x86 | |
--cmake_extra_defines | |
CMAKE_SYSTEM_NAME=Windows | |
CMAKE_SYSTEM_PROCESSOR=x86 # required for `cpuinfo` | |
result_dir: build/Release | |
release_config: Release | |
- artifact_name: onnxruntime-linux-x64-minimal | |
os: ubuntu-20.04 | |
cmake_arch: linux-x86_64 | |
build_opts: |- | |
--minimal_build | |
--disable_ml_ops | |
--enable_reduced_operator_type_support | |
--cmake_extra_defines | |
CMAKE_SYSTEM_NAME=Linux | |
CMAKE_SYSTEM_PROCESSOR=x86_64 # required for `cpuinfo` | |
result_dir: build | |
release_config: Release | |
# - artifact_name: onnxruntime-linux-armhf-minimal | |
# os: ubuntu-22.04-arm | |
# cmake_arch: linux-aarch64 | |
# build_opts: |- | |
# --minimal_build | |
# --disable_ml_ops | |
# --enable_reduced_operator_type_support | |
# --arm | |
# --cmake_extra_defines | |
# CMAKE_SYSTEM_NAME=Linux | |
# CMAKE_SYSTEM_PROCESSOR=armv7l # required for `cpuinfo` | |
# result_dir: build | |
# release_config: Release | |
- artifact_name: onnxruntime-linux-arm64-minimal | |
os: ubuntu-22.04-arm | |
cmake_arch: linux-aarch64 | |
build_opts: |- | |
--minimal_build | |
--disable_ml_ops | |
--enable_reduced_operator_type_support | |
--arm64 | |
--cmake_extra_defines | |
CMAKE_SYSTEM_NAME=Linux | |
CMAKE_SYSTEM_PROCESSOR=aarch64 # required for `cpuinfo` | |
result_dir: build | |
release_config: Release | |
- artifact_name: onnxruntime-osx-arm64-minimal | |
os: macos-13 | |
build_opts: |- | |
--minimal_build | |
--disable_ml_ops | |
--enable_reduced_operator_type_support | |
--cmake_extra_defines | |
CMAKE_SYSTEM_NAME=Darwin | |
CMAKE_OSX_ARCHITECTURES=arm64 | |
CMAKE_SYSTEM_PROCESSOR=aarch64 # required for `cpuinfo` | |
result_dir: build | |
release_config: Release | |
- artifact_name: onnxruntime-osx-x86_64-minimal | |
os: macos-13 | |
build_opts: |- | |
--minimal_build | |
--disable_ml_ops | |
--enable_reduced_operator_type_support | |
--cmake_extra_defines | |
CMAKE_SYSTEM_NAME=Darwin | |
CMAKE_OSX_ARCHITECTURES=x86_64 | |
CMAKE_SYSTEM_PROCESSOR=x86_64 # required for `cpuinfo` | |
result_dir: build | |
release_config: Release | |
- artifact_name: onnxruntime-osx-universal2-minimal | |
os: macos-13 | |
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-22.04 | |
cmake_arch: linux-x86_64 | |
build_opts: |- | |
--minimal_build=extended | |
--use_nnapi | |
--disable_ml_ops | |
--disable_exceptions | |
--disable_rtti | |
--enable_reduced_operator_type_support | |
--android | |
--android_abi x86_64 | |
--cmake_extra_defines | |
CMAKE_SYSTEM_NAME=Android | |
CMAKE_SYSTEM_PROCESSOR=x86_64 # required for `cpuinfo` | |
result_dir: build | |
release_config: Release | |
- artifact_name: onnxruntime-android-arm64-minimal | |
os: ubuntu-22.04 | |
cmake_arch: linux-x86_64 | |
build_opts: |- | |
--minimal_build=extended | |
--use_nnapi | |
--disable_ml_ops | |
--disable_exceptions | |
--disable_rtti | |
--enable_reduced_operator_type_support | |
--android | |
--android_abi arm64-v8a | |
--cmake_extra_defines | |
CMAKE_SYSTEM_NAME=Android | |
CMAKE_SYSTEM_PROCESSOR=aarch64 # required for `cpuinfo` | |
result_dir: build | |
release_config: Release | |
runs-on: ${{ matrix.os }} | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
repository: ${{ env.REPOSITORY }} | |
ref: v${{ env.ONNXRUNTIME_VERSION }} | |
submodules: recursive | |
github-server-url: https://github.com | |
- name: Checkout builder | |
uses: actions/checkout@v4 | |
with: | |
path: builder | |
- uses: actions/setup-python@v5 | |
with: | |
python-version: ${{ env.ORT_PYTHON_VERSION }} | |
- 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$CMAKE_VERSION/cmake-$CMAKE_VERSION-${{ matrix.cmake_arch }}.sh" | |
sudo bash cmake.sh --skip-license --prefix=/usr/local | |
- 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: | | |
build_opts=( | |
${{ matrix.build_opts }} | |
) | |
python ./tools/ci_build/build.py \ | |
--build_dir ./build \ | |
--config Release \ | |
--update \ | |
--build \ | |
--parallel \ | |
--build_shared_lib \ | |
--compile_no_warning_as_error \ | |
--skip_tests \ | |
"${build_opts[@]}" | |
- name: Organize artifact | |
run: | | |
# Set library name | |
ARTIFACT_NAME=${{ matrix.artifact_name }} | |
if [[ "$ARTIFACT_NAME" == "$TARGET_LIBRARY"-win-* ]]; then | |
# FIXME: この分岐はもう使わないのでは? | |
onnxruntime_filename=$TARGET_LIBRARY.dll | |
elif [[ "$ARTIFACT_NAME" == "$TARGET_LIBRARY"-linux-* ]]; then | |
onnxruntime_filename="lib$TARGET_LIBRARY.so.$ONNXRUNTIME_VERSION" | |
elif [[ "$ARTIFACT_NAME" == "$TARGET_LIBRARY"-android-* ]]; then | |
onnxruntime_filename="lib$TARGET_LIBRARY.so" | |
elif [[ "$ARTIFACT_NAME" == "$TARGET_LIBRARY"-osx-* ]] || [[ "$ARTIFACT_NAME" == "$TARGET_LIBRARY"-ios-* ]]; then | |
onnxruntime_filename="lib$TARGET_LIBRARY.$ONNXRUNTIME_VERSION.dylib" | |
else | |
echo "Unknown target found : ${{ matrix.artifact_name }}" | |
return 1 | |
fi | |
# PDBファイル, Privacy.md, include/は不要なので省く | |
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 | |
mkdir -p ./${{ matrix.result_dir }}/${{ matrix.artifact_name }}/lib | |
git rev-parse HEAD > ./${{ matrix.result_dir }}/${{ matrix.artifact_name }}/GIT_COMMIT_ID | |
cp ./{LICENSE,README.md,ThirdPartyNotices.txt,VERSION_NUMBER} \ | |
./${{ matrix.result_dir }}/${{ matrix.artifact_name }}/ | |
cp ./${{ matrix.result_dir }}/${{ matrix.release_config }}/"$TARGET_LIBRARY".{dll,lib} \ | |
./${{ matrix.result_dir }}/${{ matrix.artifact_name }}/lib/ | |
if [ -f ./${{ matrix.result_dir }}/${{ matrix.release_config }}/"$TARGET_LIBRARY"_providers_cuda.dll ]; then | |
cp ./${{ matrix.result_dir }}/${{ matrix.release_config }}/"$TARGET_LIBRARY"_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_filename" \ | |
-c ${{ matrix.release_config }} \ | |
-s "$(pwd)" \ | |
-t "$(git rev-parse HEAD)" | |
rm -r ${{ matrix.result_dir }}/${{ matrix.artifact_name }}/{Privacy.md,include} | |
fi | |
mv ${{ matrix.result_dir }}/${{ matrix.artifact_name }} "${{ matrix.artifact_name }}-$ONNXRUNTIME_VERSION" | |
tar cfz "${{ matrix.artifact_name }}-$ONNXRUNTIME_VERSION.tgz" "${{ matrix.artifact_name }}-$ONNXRUNTIME_VERSION/" | |
- name: Upload to Release | |
uses: svenstaro/upload-release-action@v2 | |
with: | |
file: "*.tgz" | |
tag: ${{ env.ONNXRUNTIME_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.ONNXRUNTIME_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$ONNXRUNTIME_VERSION" ./build | |
mv "./build/output/aar_out/Release/com/microsoft/onnxruntime/onnxruntime-${{ matrix.build_variant }}/$ONNXRUNTIME_VERSION/" "${{ matrix.artifact_name }}-$ONNXRUNTIME_VERSION" | |
tar cfz "${{ matrix.artifact_name }}-$ONNXRUNTIME_VERSION.tgz" "${{ matrix.artifact_name }}-$ONNXRUNTIME_VERSION/" | |
- name: Upload to Release | |
uses: svenstaro/upload-release-action@v2 | |
with: | |
file: "*.tgz" | |
tag: ${{ env.ONNXRUNTIME_VERSION }} | |
overwrite: true | |
file_glob: true | |
build-xcframework: | |
strategy: | |
fail-fast: false | |
matrix: | |
include: | |
- artifact_name: onnxruntime-ios-xcframework-minimal | |
os: macos-13 | |
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.ONNXRUNTIME_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 }}-$ONNXRUNTIME_VERSION" | |
7z a "${{ matrix.artifact_name }}-$ONNXRUNTIME_VERSION.zip" "${{ matrix.artifact_name }}-$ONNXRUNTIME_VERSION" | |
- name: Upload to Release | |
uses: svenstaro/upload-release-action@v2 | |
with: | |
file: "*.zip" | |
tag: ${{ env.ONNXRUNTIME_VERSION }} | |
overwrite: true | |
file_glob: true |