Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iOSビルドの追加 #13

Merged
merged 15 commits into from
Apr 9, 2023
94 changes: 51 additions & 43 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,32 @@ jobs:
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
result_dir: build/Linux
release_config: Release
- artifact_name: onnxruntime-linux-arm64-cpu
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
result_dir: build/Linux
release_config: Release
- artifact_name: onnxruntime-ios-arm64-cpu
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
result_dir: build/iOS/Release
release_config: Release-iphoneos
- artifact_name: onnxruntime-ios-sim-arm64-cpu
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
result_dir: build/iOS/Release
release_config: Release-iphonesimulator
- artifact_name: onnxruntime-ios-sim-x86_64-cpu
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
result_dir: build/iOS/Release
release_config: Release-iphonesimulator

env:
ONNXRUNTIME_VERSION: v1.14.1
Expand Down Expand Up @@ -62,7 +79,7 @@ jobs:
key: ${{ matrix.artifact_name }}-${{ env.ONNXRUNTIME_VERSION }}-cache-v1-${{ hashFiles('matrix.json') }}

- name: Install build dependencies
if: steps.cache-build-result.outputs.cache-hit != 'true'
if: steps.cache-build-result.outputs.cache-hit != 'true' && startsWith(matrix.os, 'ubuntu')
run: |
sudo apt-get update
sudo apt-get install -y \
Expand All @@ -76,15 +93,15 @@ jobs:

# ONNX Runtime v1.14.1 requires CMake 3.24 or higher.
- name: Install CMake
if: steps.cache-build-result.outputs.cache-hit != 'true'
if: steps.cache-build-result.outputs.cache-hit != 'true' && startsWith(matrix.os, 'ubuntu')
env:
CMAKE_VERSION: 3.24.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'
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
Expand All @@ -96,55 +113,46 @@ jobs:
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'
env:
CC: ${{ env.ARCH_PREFIX }}gcc-${{ matrix.cc_version }}
CXX: ${{ env.ARCH_PREFIX }}g++-${{ matrix.cxx_version }}
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 }}

- name: Organize artifact
shell: bash
run: |
mkdir artifact

# copy shared lib
mkdir artifact/lib

NAME=$(basename ${{ matrix.result_dir }}/libonnxruntime.so.*)
cp "${{ matrix.result_dir }}/${NAME}" artifact/lib/
ln -s "${NAME}" artifact/lib/libonnxruntime.so

# copy header files
mkdir artifact/include

readarray -t HEADERS <<EOF
onnxruntime/core/session/onnxruntime_c_api.h
onnxruntime/core/session/onnxruntime_cxx_api.h
onnxruntime/core/session/onnxruntime_cxx_inline.h
onnxruntime/core/providers/cpu/cpu_provider_factory.h
onnxruntime/core/session/onnxruntime_session_options_config_keys.h
onnxruntime/core/session/onnxruntime_run_options_config_keys.h
onnxruntime/core/framework/provider_options.h
EOF

for path in "${HEADERS[@]}"; do
cp "include/${path}" ./artifact/include/
done

# copy docs & license
cp VERSION_NUMBER ./artifact/
cp LICENSE ./artifact/
cp ThirdPartyNotices.txt ./artifact/
cp docs/Privacy.md ./artifact/
cp README.md ./artifact/

echo "$(git rev-parse HEAD)" >> ./artifact/GIT_COMMIT_ID
# コピー先artifactを予め削除しておく
rm -r ${{ matrix.result_dir }}/${{ matrix.artifact_name }} || true
Hiroshiba marked this conversation as resolved.
Show resolved Hide resolved
rm -r ./artifact || true
# バージョンにはvが必要ないので取り除く
ONNXRUNTIME_VERSION=${{ env.ONNXRUNTIME_VERSION }}
ONNXRUNTIME_VERSION=${ONNXRUNTIME_VERSION:1}
# Set library name
if [[ ${{ matrix.artifact_name }} == onnxruntime-linux-* ]]; then
ONNXRUNTIME_NAME=libonnxruntime.so.$ONNXRUNTIME_VERSION
elif [[ ${{ matrix.artifact_name }} == onnxruntime-ios-* ]]; then
ONNXRUNTIME_NAME=libonnxruntime.$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
Expand Down