Skip to content

iOSのApp Storeへの申請を通るようにした (#25) #74

iOSのApp Storeへの申請を通るようにした (#25)

iOSのApp Storeへの申請を通るようにした (#25) #74

Workflow file for this run

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.15.1' }}
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-linux-armhf
os: ubuntu-20.04
cc_version: "8"
cxx_version: "8"
arch: arm-linux-gnueabihf
symlink_workaround: true
build_opts: --arm --cmake_extra_defines CMAKE_SYSTEM_NAME=Linux CMAKE_SYSTEM_PROCESSOR=armv7l --config Release --parallel --update --build --build_shared_lib
result_dir: build/Linux
release_config: Release
- artifact_name: onnxruntime-linux-arm64
os: ubuntu-20.04
cc_version: "8"
cxx_version: "8"
arch: aarch64-linux-gnu
symlink_workaround: true
build_opts: --arm64 --cmake_extra_defines CMAKE_SYSTEM_NAME=Linux CMAKE_SYSTEM_PROCESSOR=aarch64 --config Release --parallel --update --build --build_shared_lib
result_dir: build/Linux
release_config: Release
- artifact_name: onnxruntime-ios-arm64
os: macos-12
build_opts: --config Release --parallel --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/iOS/Release
release_config: Release-iphoneos
- artifact_name: onnxruntime-ios-sim-arm64
os: macos-12
build_opts: --config Release --parallel --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/iOS/Release
release_config: Release-iphonesimulator
- artifact_name: onnxruntime-ios-sim-x86_64
os: macos-12
build_opts: --config Release --parallel --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/iOS/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.arch != '' && matrix.arch) || '' }}${{ (matrix.arch != '' && '-') || '' }}"
ARCH_SUFFIX: "${{ (matrix.arch != '' && '-') || '' }}${{ (matrix.arch != '' && matrix.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@v2
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@v2
with:
path: build/
key: ${{ matrix.artifact_name }}-v${{ env.ONNXRUNTIME_VERSION }}-cache-v1-${{ hashFiles('matrix.json') }}
- name: Install build dependencies on ubuntu
if: steps.cache-build-result.outputs.cache-hit != 'true' && startsWith(matrix.os, 'ubuntu')
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.15.1 requires CMake 3.26 or higher.
- name: Install CMake
if: steps.cache-build-result.outputs.cache-hit != 'true' && startsWith(matrix.os, 'ubuntu')
env:
CMAKE_VERSION: 3.26.4
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
if: steps.cache-build-result.outputs.cache-hit != 'true' && startsWith(matrix.os, 'ubuntu')
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.arch }}/lib -name '*.so*' -exec sudo ln -s {} /usr/lib/${{ matrix.arch }}/ ';'
sudo ln -s /usr/${{ matrix.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.
bash ./build.sh ${{ matrix.build_opts }} ${{ matrix.build_opts_workaround_protoc }}
- name: Organize artifact
run: |
# コピー先artifactを予め削除しておく
rm -rf ${{ matrix.result_dir }}/${{ matrix.artifact_name }}
rm -rf ./artifact
# Set library name
if [[ ${{ matrix.artifact_name }} == onnxruntime-linux-* ]]; then
ONNXRUNTIME_NAME=libonnxruntime.so.${{ env.ONNXRUNTIME_VERSION }}
elif [[ ${{ matrix.artifact_name }} == onnxruntime-ios-* ]]; then
ONNXRUNTIME_NAME=libonnxruntime.${{ env.ONNXRUNTIME_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 }} ./artifact/
- name: Upload artifact
uses: actions/upload-artifact@v2
with:
name: ${{ matrix.artifact_name }}
path: artifact/*
retention-days: 14
- 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@v2
with:
name: onnxruntime-ios-arm64
path: artifact/onnxruntime-aarch64-apple-ios
- uses: actions/download-artifact@v2
with:
name: onnxruntime-ios-sim-arm64
path: artifact/onnxruntime-aarch64-apple-ios-sim
- uses: actions/download-artifact@v2
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