├── .github ├── pull_request_template.md └── workflows │ └── build.yml ├── .vscode └── settings.json ├── LICENSE └── README.md /.github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | --- 4 | 5 | ### Contribution License Agreement 6 | 7 | - [ ] By placing an "x" in the box, I hereby understand, accept and agree to be bound by the terms and conditions of the [Contribution License Agreement](https://dena.github.io/cla/). -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: Build TFLite runtime 2 | 3 | on: 4 | release: 5 | types: 6 | - published 7 | workflow_dispatch: 8 | inputs: 9 | version: 10 | description: "Semantic version (e.g., 2.19.0)" 11 | required: true 12 | release: 13 | description: "If true, release the artifact" 14 | type: boolean 15 | required: true 16 | repository: 17 | description: "Name of a target repository" 18 | default: 'tensorflow/tensorflow' 19 | required: false 20 | xnn_options: 21 | description: "XNNPack build options" 22 | default: '--define=xnn_enable_avx512amx=false --define=xnn_enable_avxvnniint8=false --define=xnn_enable_avxvnni=false --define=xnn_enable_avx512fp16=false' 23 | required: false 24 | 25 | permissions: 26 | contents: write 27 | 28 | env: 29 | VERSION: 30 | |- # Enter release tag name or version in workflow_dispatch. Recent version if not specified 31 | ${{ github.event.release.tag_name || github.event.inputs.version || '2.19.0' }} 32 | REPOSITORY: 33 | ${{ github.event.inputs.repository || 'tensorflow/tensorflow' }} 34 | 35 | jobs: 36 | build-android: 37 | runs-on: ubuntu-22.04 38 | strategy: 39 | fail-fast: false 40 | matrix: 41 | include: 42 | - config: android_arm64 43 | artifact_name: tflite-runtime-android-arm64 44 | - config: android_arm 45 | artifact_name: tflite-runtime-android-arm 46 | - config: android_x86_64 47 | artifact_name: tflite-runtime-android-x86_64 48 | - config: android_fat_aar 49 | artifact_name: tflite-runtime-android-fat-aar 50 | env: 51 | ANDROID_SDK_API_LEVEL: 31 52 | ANDROID_NDK_API_LEVEL: 26 53 | ANDROID_BUILD_TOOLS_VERSION: '31.0.0' 54 | CC: clang-17 55 | CXX: clang++-17 56 | HERMETIC_PYTHON_VERSION: 3.12 57 | steps: 58 | - uses: actions/checkout@v4 59 | with: 60 | repository: ${{ env.REPOSITORY }} 61 | ref: v${{ env.VERSION }} 62 | submodules: recursive 63 | github-server-url: https://github.com 64 | - uses: bazel-contrib/setup-bazel@0.15.0 65 | - name: Install dependencies 66 | run: | 67 | sudo apt-get remove -y gcc g++ 68 | wget https://apt.llvm.org/llvm.sh 69 | chmod u+x llvm.sh 70 | sudo ./llvm.sh 17 71 | sudo apt-get update 72 | sudo apt-get install -y mesa-common-dev libegl1-mesa-dev libgles2-mesa-dev clang-17 llvm-17 73 | - uses: nttld/setup-ndk@v1 74 | id: setup-ndk 75 | with: 76 | ndk-version: r21b 77 | add-to-path: true 78 | - name: Build shared libraries 79 | if: ${{ matrix.config != 'android_fat_aar' }} 80 | env: 81 | ANDROID_NDK_HOME: ${{ steps.setup-ndk.outputs.ndk-path }} 82 | run: | 83 | mkdir -p artifact 84 | export ANDROID_SDK_HOME=$ANDROID_HOME 85 | 86 | # Main 87 | bazel build -c opt --config=${{ matrix.config }} --cxxopt=--std=c++17 ${{ inputs.xnn_options }} tensorflow/lite/c:tensorflowlite_c 88 | cp -f bazel-bin/tensorflow/lite/c/libtensorflowlite_c.so artifact 89 | 90 | # GPU Delegate 91 | bazel build -c opt --config=${{ matrix.config }} --cxxopt=--std=c++17 ${{ inputs.xnn_options }} --copt -Os --copt -DTFLITE_GPU_BINARY_RELEASE --copt -fvisibility=hidden --linkopt -s --strip always tensorflow/lite/delegates/gpu:libtensorflowlite_gpu_delegate.so 92 | cp -f bazel-bin/tensorflow/lite/delegates/gpu/libtensorflowlite_gpu_delegate.so artifact 93 | 94 | # GL Delegate 95 | bazel build -c opt --config=${{ matrix.config }} --cxxopt=--std=c++17 ${{ inputs.xnn_options }} --copt -Os --copt -DTFLITE_GPU_BINARY_RELEASE --copt -fvisibility=hidden --linkopt -s --strip always tensorflow/lite/delegates/gpu:libtensorflowlite_gpu_gl.so 96 | cp -f bazel-bin/tensorflow/lite/delegates/gpu/libtensorflowlite_gpu_gl.so artifact 97 | 98 | # NNAPI Delegate 99 | # bazel build -c opt --config=${{ matrix.config }} --cxxopt=--std=c++17 ${{ inputs.xnn_options }} tensorflow/lite/delegates/nnapi:nnapi_delegate 100 | # cp -f bazel-bin/tensorflow/lite/delegates/nnapi/libnnapi_delegate.so artifact 101 | - name: Build AAR 102 | if: ${{ matrix.config == 'android_fat_aar' }} 103 | env: 104 | ANDROID_NDK_HOME: ${{ steps.setup-ndk.outputs.ndk-path }} 105 | run: | 106 | mkdir -p artifact 107 | export ANDROID_SDK_HOME=$ANDROID_HOME 108 | 109 | # Main 110 | bazel build -c opt --fat_apk_cpu=arm64-v8a,armeabi-v7a,x86_64 --cxxopt=--std=c++17 ${{ inputs.xnn_options }} --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 111 | cp -f bazel-bin/tensorflow/lite/java/tensorflow-lite.aar artifact 112 | 113 | # GPU Delegate 114 | bazel build -c opt --fat_apk_cpu=arm64-v8a,armeabi-v7a,x86_64 --cxxopt=--std=c++17 ${{ inputs.xnn_options }} --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 115 | cp -f bazel-bin/tensorflow/lite/java/tensorflow-lite-gpu.aar artifact 116 | - name: Compress artifact 117 | run: | 118 | mv artifact/ "${{ matrix.artifact_name }}-${{ env.VERSION }}" 119 | tar czf "${{ matrix.artifact_name }}-${{ env.VERSION }}.tgz" "${{ matrix.artifact_name }}-${{ env.VERSION }}" 120 | - uses: softprops/action-gh-release@v2 121 | if: ${{ inputs.release }} 122 | with: 123 | files: "*.tgz" 124 | tag_name: ${{ env.VERSION }} 125 | 126 | build-ios: 127 | runs-on: macos-15 128 | strategy: 129 | fail-fast: false 130 | matrix: 131 | include: 132 | - config: ios_arm64 133 | artifact_name: tflite-runtime-ios-arm64 134 | - config: ios_sim_arm64 135 | artifact_name: tflite-runtime-ios-sim-arm64 136 | - config: ios_x86_64 137 | artifact_name: tflite-runtime-ios-sim-x86_64 138 | env: 139 | HERMETIC_PYTHON_VERSION: 3.12 140 | steps: 141 | - uses: actions/checkout@v4 142 | with: 143 | repository: ${{ env.REPOSITORY }} 144 | ref: v${{ env.VERSION }} 145 | submodules: recursive 146 | github-server-url: https://github.com 147 | - uses: bazel-contrib/setup-bazel@0.15.0 148 | - name: Build runtime 149 | run: | 150 | mv tensorflow/lite/ios/BUILD.apple tensorflow/lite/ios/BUILD 151 | mv tensorflow/lite/objc/BUILD.apple tensorflow/lite/objc/BUILD 152 | mv tensorflow/lite/swift/BUILD.apple tensorflow/lite/swift/BUILD 153 | 154 | mkdir -p artifact 155 | 156 | # Main 157 | bazel build -c opt --config=${{ matrix.config }} ${{ inputs.xnn_options }} --cxxopt=--std=c++17 tensorflow/lite/ios:TensorFlowLiteC_framework 158 | unzip -o bazel-bin/tensorflow/lite/ios/TensorFlowLiteC_framework.zip -d artifact 159 | 160 | # Metal Delegate 161 | bazel build -c opt --config=${{ matrix.config }} ${{ inputs.xnn_options }} --cxxopt=--std=c++17 tensorflow/lite/ios:TensorFlowLiteCMetal_framework 162 | unzip -o bazel-bin/tensorflow/lite/ios/TensorFlowLiteCMetal_framework.zip -d artifact 163 | 164 | # CoreML Delegate 165 | bazel build -c opt --config=${{ matrix.config }} ${{ inputs.xnn_options }} --cxxopt=--std=c++17 tensorflow/lite/ios:TensorFlowLiteCCoreML_framework 166 | unzip -o bazel-bin/tensorflow/lite/ios/TensorFlowLiteCCoreML_framework.zip -d artifact 167 | 168 | mv artifact/ "${{ matrix.artifact_name }}-${{ env.VERSION }}" 169 | 7z a "${{ matrix.artifact_name }}-${{ env.VERSION }}.zip" "${{ matrix.artifact_name }}-${{ env.VERSION }}" 170 | - uses: softprops/action-gh-release@v2 171 | if: ${{ inputs.release }} 172 | with: 173 | files: "*.zip" 174 | tag_name: ${{ env.VERSION }} 175 | 176 | build-linux: 177 | runs-on: ubuntu-22.04 178 | strategy: 179 | fail-fast: false 180 | matrix: 181 | include: 182 | - config: linux 183 | artifact_name: tflite-runtime-linux-x86_64 184 | - config: elinux_aarch64 185 | artifact_name: tflite-runtime-linux-arm64 186 | env: 187 | CC: gcc-12 188 | CXX: g++-12 189 | HERMETIC_PYTHON_VERSION: 3.12 190 | steps: 191 | - uses: actions/checkout@v4 192 | with: 193 | repository: ${{ env.REPOSITORY }} 194 | ref: v${{ env.VERSION }} 195 | submodules: recursive 196 | github-server-url: https://github.com 197 | - uses: bazel-contrib/setup-bazel@0.15.0 198 | - name: Install dependencies 199 | run: | 200 | sudo apt-get remove -y gcc g++ 201 | sudo apt update 202 | sudo apt-get install -y mesa-common-dev libegl1-mesa-dev libgles2-mesa-dev gcc-12 g++-12 203 | - name: Build runtime 204 | run: | 205 | mkdir -p artifact 206 | 207 | bazel build --config=${{ matrix.config }} -c opt --define tflite_with_xnnpack=true ${{ inputs.xnn_options }} tensorflow/lite/c:tensorflowlite_c 208 | cp -f bazel-bin/tensorflow/lite/c/libtensorflowlite_c.so artifact 209 | 210 | mv artifact/ "${{ matrix.artifact_name }}-${{ env.VERSION }}" 211 | tar cfz "${{ matrix.artifact_name }}-${{ env.VERSION }}.tgz" "${{ matrix.artifact_name }}-${{ env.VERSION }}" 212 | - uses: softprops/action-gh-release@v2 213 | if: ${{ inputs.release }} 214 | with: 215 | files: "*.tgz" 216 | tag_name: ${{ env.VERSION }} 217 | 218 | build-macos: 219 | runs-on: ${{ matrix.vm }} 220 | strategy: 221 | fail-fast: false 222 | matrix: 223 | include: 224 | - config: macos 225 | cpu: x86_64 226 | artifact_name: tflite-runtime-osx-x86_64 227 | vm: macos-13 228 | - config: macos_arm64 229 | cpu: arm64 230 | artifact_name: tflite-runtime-osx-arm64 231 | vm: macos-13 232 | env: 233 | HERMETIC_PYTHON_VERSION: 3.12 234 | steps: 235 | - uses: actions/checkout@v4 236 | with: 237 | repository: ${{ env.REPOSITORY }} 238 | ref: v${{ env.VERSION }} 239 | submodules: recursive 240 | github-server-url: https://github.com 241 | - uses: bazel-contrib/setup-bazel@0.15.0 242 | - name: Install dependencies 243 | if: ${{ matrix.vm != 'macos-15' }} 244 | shell: bash 245 | run: | 246 | brew install llvm@17 \ 247 | && echo 'export PATH="/opt/homebrew/opt/llvm@17/bin:$PATH"' >> /Users/runner/.bash_profile \ 248 | && source /Users/runner/.bash_profile \ 249 | && which clang++ 250 | - name: Build runtime 251 | shell: bash 252 | run: | 253 | mkdir -p artifact 254 | 255 | # Main 256 | bazel build --config=${{ matrix.config }} --macos_cpus=${{ matrix.cpu }} --cxxopt=--std=c++17 ${{ inputs.xnn_options }} -c opt --define tflite_with_xnnpack=true tensorflow/lite/c:tensorflowlite_c 257 | cp -f bazel-bin/tensorflow/lite/c/libtensorflowlite_c.dylib artifact 258 | 259 | # Metal Delegate 260 | bazel build --config=${{ matrix.config }} --macos_cpus=${{ matrix.cpu }} --cxxopt=--std=c++17 ${{ inputs.xnn_options }} -c opt --copt -Os --copt -DTFLITE_GPU_BINARY_RELEASE --copt -fvisibility=default --linkopt -s --strip always tensorflow/lite/delegates/gpu:tensorflow_lite_gpu_dylib 261 | cp -f bazel-bin/tensorflow/lite/delegates/gpu/tensorflow_lite_gpu_dylib.dylib artifact/libtensorflowlite_metal_delegate.dylib 262 | 263 | mv artifact/ "${{ matrix.artifact_name }}-${{ env.VERSION }}" 264 | tar cfz "${{ matrix.artifact_name }}-${{ env.VERSION }}.tgz" "${{ matrix.artifact_name }}-${{ env.VERSION }}" 265 | - uses: actions/upload-artifact@v4 266 | with: 267 | name: ${{ matrix.artifact_name }} 268 | path: ${{ matrix.artifact_name }}-${{ env.VERSION }} 269 | retention-days: 1 270 | - uses: softprops/action-gh-release@v2 271 | if: ${{ inputs.release }} 272 | with: 273 | files: "*.tgz" 274 | tag_name: ${{ env.VERSION }} 275 | 276 | build-macos-universal: 277 | needs: [build-macos] 278 | runs-on: macos-15 279 | steps: 280 | - uses: actions/download-artifact@v4 281 | - name: Build universal binary 282 | run: | 283 | mkdir -p artifact 284 | lipo -create -output artifact/libtensorflowlite_c.dylib "tflite-runtime-osx-x86_64/libtensorflowlite_c.dylib" "tflite-runtime-osx-arm64/libtensorflowlite_c.dylib" 285 | lipo -create -output artifact/libtensorflowlite_metal_delegate.dylib "tflite-runtime-osx-x86_64/libtensorflowlite_metal_delegate.dylib" "tflite-runtime-osx-arm64/libtensorflowlite_metal_delegate.dylib" 286 | mv artifact/ "tflite-runtime-osx-universal2-${{ env.VERSION }}" 287 | tar cfz "tflite-runtime-osx-universal2-${{ env.VERSION }}.tgz" "tflite-runtime-osx-universal2-${{ env.VERSION }}" 288 | - uses: softprops/action-gh-release@v2 289 | if: ${{ inputs.release }} 290 | with: 291 | files: "*.tgz" 292 | tag_name: ${{ env.VERSION }} 293 | 294 | build-windows: 295 | # Using windows-2019 as build is broken on windows-latest runner due to another 296 | # See: https://github.com/bazelbuild/bazel/issues/18592 297 | runs-on: windows-2019 298 | strategy: 299 | fail-fast: false 300 | matrix: 301 | include: 302 | - config: windows_x86_64 303 | cpu: x86_64 304 | artifact_name: tflite-runtime-win-x86_64 305 | env: 306 | HERMETIC_PYTHON_VERSION: 3.12 307 | steps: 308 | - uses: actions/checkout@v4 309 | with: 310 | repository: ${{ env.REPOSITORY }} 311 | ref: v${{ env.VERSION }} 312 | submodules: recursive 313 | github-server-url: https://github.com 314 | - uses: bazel-contrib/setup-bazel@0.15.0 315 | - name: Build runtime 316 | shell: bash 317 | run: | 318 | mkdir -p artifact 319 | 320 | # Main 321 | bazel build --cxxopt=/std:c++20 -c opt --define tflite_with_xnnpack=true ${{ inputs.xnn_options }} tensorflow/lite/c:tensorflowlite_c 322 | cp -f bazel-bin/tensorflow/lite/c/tensorflowlite_c.dll artifact 323 | 324 | mv artifact/ "${{ matrix.artifact_name }}-${{ env.VERSION }}" 325 | 7z a "${{ matrix.artifact_name }}-${{ env.VERSION }}.zip" "${{ matrix.artifact_name }}-${{ env.VERSION }}" 326 | - uses: softprops/action-gh-release@v2 327 | if: ${{ inputs.release }} 328 | with: 329 | files: "*.zip" 330 | tag_name: ${{ env.VERSION }} 331 | 332 | release: 333 | needs: [build-android, build-ios, build-linux, build-macos-universal, build-windows] 334 | runs-on: ubuntu-latest 335 | steps: 336 | - uses: softprops/action-gh-release@v2 337 | if: ${{ inputs.release }} 338 | with: 339 | name: TFLite Runtime v${{ env.VERSION }} 340 | tag_name: ${{ env.VERSION }} 341 | target_commitish: ${{ github.sha }} 342 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "editor.autoIndent": "advanced" 3 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 DeNA Co., Ltd. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # tflite-runtime-builder 2 | 3 | Build [TensorFlow Lite](https://www.tensorflow.org/lite) runtime with GitHub Actions 4 | 5 | ## Supported Platforms 6 | 7 | You can download the archived files of the runtime binaries from [Releases](https://github.com/DeNA/tflite-runtime-builder/releases). 8 | 9 | | Platform | Type | ABI | Archived file | 10 | |----------|--------|-------------|---------------------------------------| 11 | | Android | .so | armeabi-v7a | `tflite-runtime-android-arm-*.tgz` | 12 | | Android | .so | arm64-v8a | `tflite-runtime-android-arm64-*.tgz` | 13 | | Android | .so | x86_64 | `tflite-runtime-android_x86_64-*.tgz` | 14 | | Android | .aar | armeabi-v7, aarm64-v8a, x86_64 | `tflite-runtime-android-fat-aar-*.tgz` | 15 | | iOS | .framework | arm64 | `tflite-runtime-ios-arm64-*.zip` | 16 | | iOS Sim | .framework | arm64 | `tflite-runtime-ios-sim-arm64-*.zip` | 17 | | iOS Sim | .framework | x86_64 | `tflite-runtime-ios-sim-x86_64-*.zip` | 18 | | Linux | .so | AArch64 | `tflite-runtime-linux-arm64-*.tgz` | 19 | | Linux | .so | x86_64 | `tflite-runtime-linux-x86_64-*.tgz` | 20 | | macOS | .dylib | universal (arm64, x86_64) | `tflite-runtime-osx-universal2-*.tgz` | 21 | | macOS | .dylib | arm64 | `tflite-runtime-osx-arm64-*.tgz` | 22 | | macOS | .dylib | x86_64 | `tflite-runtime-osx-x86_64-*.tgz` | 23 | | Windows | .dll | x86_64 | `tflite-runtime-win-x86_64-*.zip` | 24 | 25 | ## License 26 | 27 | MIT License 28 | 29 | ## How to contribute 30 | 31 | Open an issue or create a pull request. 32 | --------------------------------------------------------------------------------