Skip to content

Commit

Permalink
feat: add support for Android and iOS runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
stakemura committed Nov 12, 2023
1 parent 3464b71 commit 2726d9b
Showing 1 changed file with 99 additions and 19 deletions.
118 changes: 99 additions & 19 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,87 @@ on:
tags:
- 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10

env:
PYTHON_VERSION: '3.10.11'

jobs:
build-android:
runs-on: ubuntu-22.04
env:
# TFLite bug https://github.com/tensorflow/tensorflow/issues/61311
ANDROID_PLATFORM: android-26
ANDROID_SDK_API_LEVEL: 30
ANDROID_NDK_API_LEVEL: 26
ANDROID_BUILD_TOOLS_VERSION: 30.0.3
steps:
- uses: actions/checkout@v3
with:
repository: tensorflow/tensorflow
ref: ${{ github.ref_name }}
submodules: recursive
github-server-url: https://github.com
- uses: bazelbuild/setup-bazelisk@v2
- uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install dependencies
run: |
pip install numpy
SDKMANAGER=${ANDROID_SDK_ROOT}/cmdline-tools/latest/bin/sdkmanager
echo "y" | $SDKMANAGER "ndk;21.4.7075529"
- name: Build runtime
run: |
mkdir -p Android
export ANDROID_SDK_HOME=$ANDROID_HOME
export ANDROID_NDK_HOME=$ANDROID_SDK_ROOT/ndk/21.4.7075529
bazel build -c opt --fat_apk_cpu=arm64-v8a --cxxopt=--std=c++17 --host_crosstool_top=@bazel_tools//tools/cpp:toolchain --define=android_dexmerger_tool=d8_dexmerger --define=android_incremental_dexing_tool=d8_dexbuilder //tensorflow/lite/java:tensorflow-lite
cp -f bazel-bin/tensorflow/lite/java/tensorflow-lite.aar Android
bazel build -c opt --fat_apk_cpu=arm64-v8a --cxxopt=--std=c++17 --host_crosstool_top=@bazel_tools//tools/cpp:toolchain --define=android_dexmerger_tool=d8_dexmerger --define=android_incremental_dexing_tool=d8_dexbuilder //tensorflow/lite/java:tensorflow-lite-gpu
cp -f bazel-bin/tensorflow/lite/java/tensorflow-lite-gpu.aar Android
bazel build -c opt --config=android_arm64 --cxxopt=--std=c++17 --copt -Os --copt -DTFLITE_GPU_BINARY_RELEASE --copt -fvisibility=hidden --linkopt -s --strip always //tensorflow/lite/delegates/gpu:libtensorflowlite_gpu_gl.so
mkdir -p Android/arm64-v8a; cp -f bazel-bin/tensorflow/lite/delegates/gpu/libtensorflowlite_gpu_gl.so Android/arm64-v8a
tar cvjf tflite-runtime-${{ github.ref_name }}-android.bz2 Android
- uses: actions/upload-artifact@v3
with:
name: bin-android
path: '*.bz2'

build-ios:
runs-on: macos-12
steps:
- uses: actions/checkout@v3
with:
repository: tensorflow/tensorflow
ref: ${{ github.ref_name }}
submodules: recursive
github-server-url: https://github.com
- uses: bazelbuild/setup-bazelisk@v2
- uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install dependencies
run: |
pip install numpy
- name: Build runtime
run: |
mv tensorflow/lite/ios/BUILD.apple tensorflow/lite/ios/BUILD
mv tensorflow/lite/objc/BUILD.apple tensorflow/lite/objc/BUILD
mv tensorflow/lite/swift/BUILD.apple tensorflow/lite/swift/BUILD
mkdir -p iOS
bazel build -c opt --config=ios_arm64 --cxxopt=--std=c++17 //tensorflow/lite/ios:TensorFlowLiteC_framework
unzip -o bazel-bin/tensorflow/lite/ios/TensorFlowLiteC_framework.zip -d iOS
bazel build -c opt --config=ios_arm64 --cxxopt=--std=c++17 //tensorflow/lite/ios:TensorFlowLiteCMetal_framework
unzip -o bazel-bin/tensorflow/lite/ios/TensorFlowLiteCMetal_framework.zip -d iOS
bazel build -c opt --config=ios_arm64 --cxxopt=--std=c++17 //tensorflow/lite/ios:TensorFlowLiteCCoreML_framework
unzip -o bazel-bin/tensorflow/lite/ios/TensorFlowLiteCCoreML_framework.zip -d iOS
tar cvjf tflite-runtime-${{ github.ref_name }}-ios.bz2 iOS
- uses: actions/upload-artifact@v3
with:
name: bin-ios
path: '*.bz2'

build-linux:
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
with:
Expand All @@ -19,21 +97,25 @@ jobs:
- uses: bazelbuild/setup-bazelisk@v2
- uses: actions/setup-python@v4
with:
python-version: '3.10'
python-version: ${{ env.PYTHON_VERSION }}
- name: Install dependencies
run: |
pip3 install numpy
pip install numpy
- name: Build runtime
run: |
mkdir -p Linux
bazel build -c opt --define tflite_with_xnnpack=true tensorflow/lite/c:tensorflowlite_c
mkdir -p Linux/x86_64; cp -f bazel-bin/tensorflow/lite/c/libtensorflowlite_c.so Linux/x86_64
bazel build --config=elinux_aarch64 -c opt --define tflite_with_xnnpack=true tensorflow/lite/c:tensorflowlite_c
mkdir -p Linux/arm64; cp -f bazel-bin/tensorflow/lite/c/libtensorflowlite_c.so Linux/arm64
tar cvjf tflite-runtime-${{ github.ref_name }}-linux.bz2 Linux
- uses: actions/upload-artifact@v3
with:
name: bin-linux
path: |
bazel-bin/tensorflow/lite/c/*.so
path: '*.bz2'

build-macos:
runs-on: macos-latest
runs-on: macos-12
steps:
- uses: actions/checkout@v3
with:
Expand All @@ -44,22 +126,23 @@ jobs:
- uses: bazelbuild/setup-bazelisk@v2
- uses: actions/setup-python@v4
with:
python-version: '3.10'
python-version: ${{ env.PYTHON_VERSION }}
- name: Install dependencies
run: |
pip3 install numpy
pip install numpy
- name: Build runtime
run: |
mkdir -p macOS
bazel build --config=macos --cpu=darwin -c opt --define tflite_with_xnnpack=true tensorflow/lite/c:tensorflowlite_c
mkdir -p x86_64; cp -f bazel-bin/tensorflow/lite/c/libtensorflowlite_c.dylib x86_64
bazel build --config=macos_arm64 --cpu=darwin_arm64 -c opt --define tflite_with_xnnpack=true tensorflow/lite/c:tensorflowlite_c
mkdir -p arm64; cp -f bazel-bin/tensorflow/lite/c/libtensorflowlite_c.dylib arm64
lipo -create -output libtensorflowlite_c.dylib x86_64/libtensorflowlite_c.dylib arm64/libtensorflowlite_c.dylib
lipo -create -output macOS/libtensorflowlite_c.dylib x86_64/libtensorflowlite_c.dylib arm64/libtensorflowlite_c.dylib
tar cvjf tflite-runtime-${{ github.ref_name }}-macos.bz2 macOS
- uses: actions/upload-artifact@v3
with:
name: bin-macos
path: |
libtensorflowlite_c.dylib
path: '*.bz2'

build-windows:
# TODO(soon): Using windows-2019 as build is broken on windows-latest runner due to another
Expand All @@ -73,30 +156,27 @@ jobs:
submodules: recursive
github-server-url: https://github.com
- uses: bazelbuild/setup-bazelisk@v2
- uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Install dependencies
run: |
pip3 install numpy
- name: Build runtime
shell: bash
run: |
mkdir -p Windows
bazel build -c opt --define tflite_with_xnnpack=true tensorflow/lite/c:tensorflowlite_c
cp -f bazel-bin/tensorflow/lite/c/tensorflowlite_c.dll Windows
tar cvjf tflite-runtime-${{ github.ref_name }}-windows.bz2 Windows
- uses: actions/upload-artifact@v3
with:
name: bin-windows
path: |
bazel-bin/tensorflow/lite/c/*.dll
path: '*.bz2'

release:
needs: [build-linux, build-macos, build-windows]
needs: [build-android, build-ios, build-linux, build-macos, build-windows]
runs-on: ubuntu-latest
permissions: write-all
steps:
- uses: actions/download-artifact@v3
with:
path: '.'
- uses: softprops/action-gh-release@v1
with:
files: '**/*'

0 comments on commit 2726d9b

Please sign in to comment.