Skip to content

Build minimal ONNX Runtime #1

Build minimal ONNX Runtime

Build minimal ONNX Runtime #1

Workflow file for this run

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-22.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-22.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-22.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-22.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-22.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
- 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