-
Notifications
You must be signed in to change notification settings - Fork 238
130 lines (118 loc) · 4.57 KB
/
cmake_android_linux_x86_64.yml
File metadata and controls
130 lines (118 loc) · 4.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
name: "cmake-android-linux"
on:
push:
branches:
- main
pull_request:
branches:
- main
schedule:
- cron: "0 10 * * *" # Run at 2am PST (10am UTC) every day to refresh the cache.
workflow_dispatch:
inputs:
REFRESH_CACHE:
description: 'Refresh cache to remove unused files'
type: boolean
default: true
permissions:
contents: read
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
cancel-in-progress: true
jobs:
presubmit:
name: "Presubmit-Android-Linux"
runs-on: LiteRT_Linux_x64
permissions:
actions: write
contents: write
env:
CMAKE_BUILD_PARALLEL_LEVEL: 6
GH_TOKEN: ${{ github.token }}
REFRESH_CACHE: ${{ github.event_name == 'schedule' ||
(github.event_name == 'workflow_dispatch' && inputs.REFRESH_CACHE) }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: recursive
- name: Set up cache keys
id: cache-keys
run: |
CACHE_RESTORE_KEY_1="${{ github.workflow }}"
CACHE_RESTORE_KEY_0="$CACHE_RESTORE_KEY_1-${{ hashFiles('**/CMakeLists.txt', '**/*.cmake') }}"
CACHE_RESTORE_KEY_HEAD="$CACHE_RESTORE_KEY_0-${{ github.event.pull_request.base.sha }}"
CACHE_KEY="$CACHE_RESTORE_KEY_0-${{ github.sha }}"
echo "CACHE_RESTORE_KEY_1=$CACHE_RESTORE_KEY_1" >> "$GITHUB_OUTPUT"
echo "CACHE_RESTORE_KEY_0=$CACHE_RESTORE_KEY_0" >> "$GITHUB_OUTPUT"
echo "CACHE_RESTORE_KEY_HEAD=$CACHE_RESTORE_KEY_HEAD" >> "$GITHUB_OUTPUT"
echo "CACHE_KEY=$CACHE_KEY" >> "$GITHUB_OUTPUT"
- name: Clean build outputs if cache is being refreshed.
if: env.REFRESH_CACHE == 'true'
run: |
rm -rf litert/cmake_build_android_arm64
rm -rf host_flatc_build
- name: Restore cmake cache if cache is not being refreshed.
id: cmake-cache
if: env.REFRESH_CACHE != 'true'
uses: actions/cache/restore@v4
with:
path: |
litert/cmake_build_android_arm64
host_flatc_build
key: ${{ steps.cache-keys.outputs.CACHE_KEY }}
restore-keys: |
${{ steps.cache-keys.outputs.CACHE_RESTORE_KEY_HEAD }}
${{ steps.cache-keys.outputs.CACHE_RESTORE_KEY_0 }}-
${{ steps.cache-keys.outputs.CACHE_RESTORE_KEY_1 }}-
- name: Check cache hit
run: |
echo "Cache Hit: ${{ steps.cmake-cache.outputs.cache-hit }}"
echo "Cache Primary Key: ${{ steps.cmake-cache.outputs.cache-primary-key }}"
echo "Cache Matched Key: ${{ steps.cmake-cache.outputs.cache-matched-key }}"
- name: Setup CMake 3.28.3
uses: jwlawson/actions-setup-cmake@v2
with:
cmake-version: "3.28.3"
- name: Ensure clang toolchain
run: |
if ! command -v clang >/dev/null 2>&1; then
sudo apt-get update
sudo apt-get install -y clang
fi
clang --version
- name: Install Android NDK r27
id: setup-ndk
uses: nttld/setup-ndk@v1
with:
ndk-version: r27
- name: Export ANDROID_NDK_HOME
run: echo "ANDROID_NDK_HOME=${{ steps.setup-ndk.outputs.ndk-path }}" >> "$GITHUB_ENV"
- name: Configure host flatbuffers tools
run: cmake --preset android-arm64 -DCMAKE_POLICY_VERSION_MINIMUM=3.5
working-directory: litert
- name: Locate host flatc
id: host-tools
run: |
HOST_DIR="$(cd ../host_flatc_build/_deps/flatbuffers-build && pwd)"
echo "dir=$HOST_DIR" >> "$GITHUB_OUTPUT"
working-directory: litert
- name: Configure Android build
run: cmake --preset android-arm64 -DCMAKE_POLICY_VERSION_MINIMUM=3.5 -DTFLITE_HOST_TOOLS_DIR="${{ steps.host-tools.outputs.dir }}"
working-directory: litert
- name: Build Android artifacts
run: cmake --build cmake_build_android_arm64 --parallel
working-directory: litert
- name: Remove cache if cache is being refreshed.
if: env.REFRESH_CACHE == 'true'
continue-on-error: true
run: gh cache delete ${{ steps.cache-keys.outputs.CACHE_KEY }}
- name: Save cmake cache if it's new or being refreshed.
uses: actions/cache/save@v4
if: env.REFRESH_CACHE == 'true' || steps.cmake-cache.outputs.cache-hit != 'true'
with:
path: |
litert/cmake_build_android_arm64
host_flatc_build
key: ${{ steps.cache-keys.outputs.CACHE_KEY }}