Skip to content

Commit

Permalink
update android builder
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminwan committed Jan 6, 2024
1 parent 4aa5d16 commit e27799d
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 16 deletions.
37 changes: 29 additions & 8 deletions .github/workflows/android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:

env:
ONNX_VERSION: v1.15.1
PKG_NAME: onnxruntime-1.15.1-${{ matrix.list.arch }}
PKG_NAME_PREFIX: onnxruntime-1.15.1-${{ matrix.list.arch }}

steps:
# Setup JDK 11
Expand Down Expand Up @@ -64,14 +64,24 @@ jobs:
- name: 7zip
run: |
mv onnxruntime-${{ env.ONNX_VERSION }}/build-${{ matrix.list.arch }}/install ${{ matrix.list.arch }}
7z a ${{ env.PKG_NAME }}.7z ${{ matrix.list.arch }}
7z a ${{ env.PKG_NAME_PREFIX }}-shared.7z ${{ matrix.list.arch }}
rm -r -f ${{ matrix.list.arch }}
mv onnxruntime-${{ env.ONNX_VERSION }}/build-${{ matrix.list.arch }}/install-static ${{ matrix.list.arch }}
7z a ${{ env.PKG_NAME_PREFIX }}-static.7z ${{ matrix.list.arch }}
rm -r -f ${{ matrix.list.arch }}
# 上传artifact
- name: upload
uses: actions/upload-artifact@v3
with:
name: ${{ env.PKG_NAME }}
path: ${{ env.PKG_NAME }}.7z
name: ${{ env.PKG_NAME_PREFIX }}-shared
path: ${{ env.PKG_NAME_PREFIX }}-shared.7z

- name: upload
uses: actions/upload-artifact@v3
with:
name: ${{ env.PKG_NAME_PREFIX }}-static
path: ${{ env.PKG_NAME_PREFIX }}-static.7z

release:
needs: [ android ]
Expand Down Expand Up @@ -122,13 +132,24 @@ jobs:
- name: merge
run: |
mkdir onnxruntime-android
mv artifacts/*/*.7z artifacts/
find artifacts/*.7z -exec 7z x {} -aoa -oonnxruntime-android \;
mv artifacts/*/*-shared.7z artifacts/
find artifacts/*-shared.7z -exec 7z x {} -aoa -oonnxruntime-android \;
pushd onnxruntime-android
echo "message(\"OnnxRuntime Path: \${CMAKE_CURRENT_LIST_DIR}/\${ANDROID_ABI}\")" > OnnxRuntimeWrapper.cmake
echo "set(OnnxRuntime_DIR \"\${CMAKE_CURRENT_LIST_DIR}/\${ANDROID_ABI}\")" >> OnnxRuntimeWrapper.cmake
popd
7z a ${{ env.PKG_NAME }}-shared.7z onnxruntime-android
rm -r -f onnxruntime-android
mkdir onnxruntime-android
mv artifacts/*/*-static.7z artifacts/
find artifacts/*-static.7z -exec 7z x {} -aoa -oonnxruntime-android \;
pushd onnxruntime-android
echo "message(\"OnnxRuntime Path: \${CMAKE_CURRENT_LIST_DIR}/\${ANDROID_ABI}\")" > OnnxRuntimeWrapper.cmake
echo "set(OnnxRuntime_DIR \"\${CMAKE_CURRENT_LIST_DIR}/\${ANDROID_ABI}\")" >> OnnxRuntimeWrapper.cmake
popd
7z a ${{ env.PKG_NAME }}.7z onnxruntime-android
7z a ${{ env.PKG_NAME }}-static.7z onnxruntime-android
rm -r -f onnxruntime-android
find artifacts/*-static.7z -exec rm {} \;
# 创建release 上传release
# https://github.com/marketplace/actions/create-release
Expand All @@ -138,7 +159,7 @@ jobs:
prerelease: false
name: onnxruntime ${{ github.ref }}
bodyFile: release.md
artifacts: ${{ env.PKG_NAME }}.7z
artifacts: ${{ env.PKG_NAME }}-shared.7z,${{ env.PKG_NAME }}-static.7z
allowUpdates: true
artifactContentType: application/x-7z-compressed
token: ${{ secrets.GITHUB_TOKEN }}
38 changes: 30 additions & 8 deletions build-onnxruntime-android.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,35 @@
# build onnxruntime by benjaminwan
# CMakeFiles/onnxruntime.dir/link.txt/link/lib*.a

function createConfig() {
echo "set(OnnxRuntime_INCLUDE_DIRS \"\${CMAKE_CURRENT_LIST_DIR}/include\")" >install/OnnxRuntimeConfig.cmake
echo "include_directories(\${OnnxRuntime_INCLUDE_DIRS})" >>install/OnnxRuntimeConfig.cmake
echo "link_directories(\${CMAKE_CURRENT_LIST_DIR}/lib)" >>install/OnnxRuntimeConfig.cmake
echo "set(OnnxRuntime_LIBS onnxruntime)" >>install/OnnxRuntimeConfig.cmake
echo "add_library(\${OnnxRuntime_LIBS} SHARED IMPORTED)" >>install/OnnxRuntimeConfig.cmake
echo "set_target_properties(\${OnnxRuntime_LIBS} PROPERTIES IMPORTED_LOCATION \${CMAKE_CURRENT_LIST_DIR}/lib/libonnxruntime.so)" >>install/OnnxRuntimeConfig.cmake
function collectLibs() {
# create shared lib config
echo "set(OnnxRuntime_INCLUDE_DIRS \"\${CMAKE_CURRENT_LIST_DIR}/include\")" >install/OnnxRuntimeConfig.cmake
echo "include_directories(\${OnnxRuntime_INCLUDE_DIRS})" >>install/OnnxRuntimeConfig.cmake
echo "link_directories(\${CMAKE_CURRENT_LIST_DIR}/lib)" >>install/OnnxRuntimeConfig.cmake
echo "set(OnnxRuntime_LIBS onnxruntime)" >>install/OnnxRuntimeConfig.cmake
echo "add_library(\${OnnxRuntime_LIBS} SHARED IMPORTED)" >>install/OnnxRuntimeConfig.cmake
echo "set_target_properties(\${OnnxRuntime_LIBS} PROPERTIES IMPORTED_LOCATION \${CMAKE_CURRENT_LIST_DIR}/lib/libonnxruntime.so)" >>install/OnnxRuntimeConfig.cmake

# static lib
mkdir -p install-static/lib
cp -r install/include install-static
link=$(cat CMakeFiles/onnxruntime.dir/link.txt)
regex="lib.*.a$"
libs=""
for var in $link; do
if [[ ${var} =~ ${regex} ]]; then
echo cp ${var} install-static/lib
cp ${var} install-static/lib
name=$(echo $var | grep -E ${regex} -o)
name=${name#lib}
name=${name%.a}
libs="${libs} ${name}"
fi
done
echo "set(OnnxRuntime_INCLUDE_DIRS \"\${CMAKE_CURRENT_LIST_DIR}/include\")" > install-static/OnnxRuntimeConfig.cmake
echo "include_directories(\${OnnxRuntime_INCLUDE_DIRS})" >> install-static/OnnxRuntimeConfig.cmake
echo "link_directories(\${CMAKE_CURRENT_LIST_DIR}/lib)" >> install-static/OnnxRuntimeConfig.cmake
echo "set(OnnxRuntime_LIBS $libs)" >> install-static/OnnxRuntimeConfig.cmake
}

function cmakeParams() {
Expand All @@ -22,7 +44,7 @@ function cmakeParams() {
../cmake
cmake --build . --config Release -j $NUM_THREADS
cmake --build . --config Release --target install
createConfig
collectLibs
popd
}

Expand Down

0 comments on commit e27799d

Please sign in to comment.