forked from zingolabs/zingo-mobile
-
Notifications
You must be signed in to change notification settings - Fork 1
206 lines (175 loc) · 7.09 KB
/
android-build.yaml
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
name: Build
on:
workflow_call:
inputs:
cache-key:
required: true
type: string
arch:
required: true
type: string
env:
CACHE-KEY: ${{ inputs.cache-key }}
ARCH: ${{ inputs.arch }}
REPO-OWNER: ${{ github.repository_owner }}
jobs:
android-check-build-cache:
name: Check build cache
runs-on: macos-13
outputs:
native-cache-found: ${{ steps.native-set-cache-found.outputs.native-cache-found }}
kotlin-cache-found: ${{ steps.kotlin-set-cache-found.outputs.kotlin-cache-found }}
steps:
- name: Set envs for zingolib CI
if: ${{ contains(github.repository, 'zingolib') }}
run: echo "REPO-OWNER=zingolabs" >> $GITHUB_ENV
- name: Checkout repository
uses: actions/checkout@v4
with:
repository: ${{ env.REPO-OWNER }}/zingo-mobile
- name: Check if native rust cache exists
id: native-check-build-cache
uses: actions/cache/restore@v4
with:
path: android/app/src/main/jniLibs/${{ env.ARCH }}
key: native-android-uniffi-${{ env.ARCH }}-${{ env.CACHE-KEY }}
lookup-only: true
- name: Set cache-found
id: native-set-cache-found
run: echo "native-cache-found=${{ steps.native-check-build-cache.outputs.cache-hit }}" >> $GITHUB_OUTPUT
- name: Check if kotlin uniffi cache exists
id: kotlin-check-build-cache
uses: actions/cache/restore@v4
with:
path: android/app/build/generated/source/uniffi/debug/java/uniffi/zingo
key: kotlin-android-uniffi-${{ env.ARCH }}-${{ env.CACHE-KEY }}
lookup-only: true
- name: Set cache-found
id: kotlin-set-cache-found
run: echo "kotlin-cache-found=${{ steps.kotlin-check-build-cache.outputs.cache-hit }}" >> $GITHUB_OUTPUT
android-build:
name: Build native rust & kotlin uniffi
needs: android-check-build-cache
if: ${{ needs.android-check-build-cache.outputs.native-cache-found != 'true' || needs.android-check-build-cache.outputs.kotlin-cache-found != 'true' }}
runs-on: ubuntu-22.04
container:
image: zingodevops/android_builder:010
env:
RUSTUP_HOME: /root/.rustup
steps:
- name: Set envs for zingolib CI
if: ${{ contains(github.repository, 'zingolib') }}
run: echo "REPO-OWNER=zingolabs" >> $GITHUB_ENV
- name: Checkout repository
uses: actions/checkout@v4
with:
repository: ${{ env.REPO-OWNER }}/zingo-mobile
- name: Cargo update for zingolib CI
if: ${{ contains(github.repository, 'zingolib') }}
run: |
echo "zingolib_ref=$(echo ${GITHUB_REF} | sed 's/\//\\\//g')" >> $GITHUB_ENV
sed -i "/^zingolib/ s/branch = \"dev\"/rev = \"${{ env.zingolib_ref }}\"/" "rust/lib/Cargo.toml"
if cat rust/lib/Cargo.toml | grep "^zingolib" | grep -q "branch"; then exit 1; fi
cd rust
cargo update -p zingolib --aggressive
- name: Cargo cache
uses: Swatinem/rust-cache@v2
with:
workspaces: rust
- name: Cargo default nightly
run: rustup default nightly
- name: AWS libcrypto rust building
run: cargo install --force --locked bindgen-cli
- name: Cargo uniffi kotlin
working-directory: ./rust/lib
run: |
cargo run --release --features=uniffi/cli --bin uniffi-bindgen \
generate ./src/zingo.udl --language kotlin \
--out-dir ../../android/app/build/generated/source/uniffi/debug/java
- name: Upload kotlin uniffi
uses: actions/upload-artifact@v4
with:
name: kotlin-android-uniffi-${{ env.ARCH }}-${{ env.CACHE-KEY }}
path: android/app/build/generated/source/uniffi/debug/java/uniffi/zingo/zingo.kt
- name: Set envs for x86_64
if: ${{ env.ARCH == 'x86_64' }}
run: |
echo "TARGET=x86_64-linux-android" >> $GITHUB_ENV
echo "CC=x86_64-linux-android" >> $GITHUB_ENV
echo "OPENSSL_PATH=x86_64" >> $GITHUB_ENV
- name: Set envs for x86
if: ${{ env.ARCH == 'x86' }}
run: |
echo "TARGET=i686-linux-android" >> $GITHUB_ENV
echo "CC=i686-linux-android" >> $GITHUB_ENV
echo "OPENSSL_PATH=x86" >> $GITHUB_ENV
- name: Set envs for arm64-v8a
if: ${{ env.ARCH == 'arm64-v8a' }}
run: |
echo "TARGET=aarch64-linux-android" >> $GITHUB_ENV
echo "CC=aarch64-linux-android" >> $GITHUB_ENV
echo "OPENSSL_PATH=aarch64" >> $GITHUB_ENV
- name: Set envs for armeabi-v7a
if: ${{ env.ARCH == 'armeabi-v7a' }}
run: |
echo "TARGET=armv7-linux-androideabi" >> $GITHUB_ENV
echo "CC=armv7a-linux-androideabi" >> $GITHUB_ENV
echo "OPENSSL_PATH=armv7" >> $GITHUB_ENV
- name: Cargo NDK
run: cargo install --version ^3 cargo-ndk
- name: Cargo build
working-directory: ./rust/lib
run: |
cargo ndk \
--target ${{ env.TARGET }} build \
--release -Z build-std
env:
AR: llvm-ar
LD: ld
RANLIB: llvm-ranlib
CC: ${{ env.CC }}24-clang
OPENSSL_DIR: /opt/openssl-3.3.1/${{ env.OPENSSL_PATH }}
CARGO_FEATURE_STD: true
- name: LLVM Strip
working-directory: ./rust/target
run: llvm-strip ./${{ env.TARGET }}/release/libzingo.so
- name: Rename the rust lib for uniffi compatibility
working-directory: ./rust/target/${{ env.TARGET }}/release
run: mv ./libzingo.so ./libuniffi_zingo.so
- name: Upload native rust
uses: actions/upload-artifact@v4
with:
name: native-android-uniffi-${{ env.ARCH }}-${{ env.CACHE-KEY }}
path: rust/target/${{ env.TARGET }}/release/libuniffi_zingo.so
cache-native-android-uniffi:
name: Cache native rust
needs: android-build
runs-on: macos-13
steps:
- name: Set envs for zingolib CI
if: ${{ contains(github.repository, 'zingolib') }}
run: echo "REPO-OWNER=zingolabs" >> $GITHUB_ENV
- name: Checkout repository
uses: actions/checkout@v4
with:
repository: ${{ env.REPO-OWNER }}/zingo-mobile
- name: Download native rust
uses: actions/download-artifact@v4
with:
name: native-android-uniffi-${{ env.ARCH }}-${{ env.CACHE-KEY }}
path: android/app/src/main/jniLibs/${{ env.ARCH }}
- name: Cache native rust
uses: actions/cache/save@v4
with:
path: android/app/src/main/jniLibs/${{ env.ARCH }}
key: native-android-uniffi-${{ env.ARCH }}-${{ env.CACHE-KEY }}
- name: Download kotlin uniffi
uses: actions/download-artifact@v4
with:
name: kotlin-android-uniffi-${{ env.ARCH }}-${{ env.CACHE-KEY }}
path: android/app/build/generated/source/uniffi/debug/java/uniffi/zingo
- name: Cache kotlin uniffi
uses: actions/cache/save@v4
with:
path: android/app/build/generated/source/uniffi/debug/java/uniffi/zingo
key: kotlin-android-uniffi-${{ env.ARCH }}-${{ env.CACHE-KEY }}