-
Notifications
You must be signed in to change notification settings - Fork 23
345 lines (336 loc) · 11.6 KB
/
rust.yml
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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
name: Rust
on:
push:
branches:
- master
tags:
- '[0-9]+.[0-9]+.[0-9]+'
pull_request:
env:
SDK_BUILD_TOOLS_VERSION: '34.0.0'
NDK_VERSION: '25.2.9519653'
ANDROID_PLATFORM: '34'
jobs:
format:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Setup Rust
uses: dtolnay/rust-toolchain@v1
with:
toolchain: stable
components: rustfmt
- uses: Swatinem/rust-cache@v2
- name: Format
run: cargo fmt --all -- --check
docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Setup Rust
uses: dtolnay/rust-toolchain@v1
with:
toolchain: nightly
targets: x86_64-linux-android
components: rust-docs
- uses: Swatinem/rust-cache@v2
- name: Documentation
env:
DOCS_RS: 1
run: cargo doc --target x86_64-linux-android --features java-interface,doc-cfg
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Setup JDK
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 17
- name: Setup Android SDK
uses: android-actions/setup-android@v3
with:
log-accepted-android-sdk-licenses: false
packages: build-tools;${{ env.SDK_BUILD_TOOLS_VERSION }} ndk;${{ env.NDK_VERSION }} platforms;android-${{ env.ANDROID_PLATFORM }}
- name: Config Android NDK
env:
TRIPLE: x86_64-linux-android
run: |
echo "$ANDROID_SDK_ROOT/ndk/$NDK_VERSION/toolchains/llvm/prebuilt/linux-x86_64/bin" >> $GITHUB_PATH
for var in ANDROID_NDK ANDROID_NDK_HOME ANDROID_NDK_LATEST_HOME ANDROID_NDK_ROOT NDK_HOME; do
echo "$var=$ANDROID_SDK_ROOT/ndk/$NDK_VERSION" >> $GITHUB_ENV
done
TRIPLE_ENV=$(echo $TRIPLE | tr '-' '_')
echo "CC_${TRIPLE_ENV}=${TRIPLE}21-clang" >> $GITHUB_ENV
echo "CXX_${TRIPLE_ENV}=${TRIPLE}21-clang++" >> $GITHUB_ENV
echo "AR_${TRIPLE_ENV}=llvm-ar" >> $GITHUB_ENV
- uses: dtolnay/rust-toolchain@v1
with:
toolchain: nightly
target: x86_64-linux-android
components: clippy
- uses: Swatinem/rust-cache@v2
- run: cargo clippy --all --features java-interface --all-targets --target x86_64-linux-android
build:
needs:
- format
- docs
- check
- cargo-ndk
runs-on: ubuntu-latest
strategy:
fail-fast: ${{ github.event_name == 'pull_request' || startsWith(github.ref, 'refs/tags/') }}
matrix:
rust:
- stable
- nightly
profile:
- debug
- release
target:
- armv7-linux-androideabi
- aarch64-linux-android
- i686-linux-android
- x86_64-linux-android
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Setup JDK
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 17
- name: Setup Android SDK
uses: android-actions/setup-android@v3
with:
log-accepted-android-sdk-licenses: false
packages: build-tools;${{ env.SDK_BUILD_TOOLS_VERSION }} ndk;${{ env.NDK_VERSION }} platforms;android-${{ env.ANDROID_PLATFORM }}
- name: Config Android NDK
run: |
echo "$ANDROID_SDK_ROOT/ndk/$NDK_VERSION/toolchains/llvm/prebuilt/linux-x86_64/bin" >> $GITHUB_PATH
for var in ANDROID_NDK ANDROID_NDK_HOME ANDROID_NDK_LATEST_HOME ANDROID_NDK_ROOT NDK_HOME; do
echo "$var=$ANDROID_SDK_ROOT/ndk/$NDK_VERSION" >> $GITHUB_ENV
done
- name: Setup Rust ${{ matrix.rust }} [${{ matrix.target }}]
uses: dtolnay/rust-toolchain@v1
with:
toolchain: ${{ matrix.rust }}
target: ${{ matrix.target }}
components: rustfmt
- name: Setup Cargo ndk
uses: actions/cache@v4
with:
path: ~/.cargo/bin/cargo-ndk
key: ${{ runner.os }}-cargo-ndk
- uses: Swatinem/rust-cache@v2
- name: Prepare config
id: config
run: |
echo "android-target=$(case "${{ matrix.target }}" in
armv7-linux-androideabi) printf armeabi-v7a;;
aarch64-linux-android) printf arm64-v8a;;
i686-linux-android) printf x86;;
x86_64-linux-android) printf x86_64;;
esac)" >> $GITHUB_OUTPUT
if [[ "${{ matrix.target }}" =~ "64" ]]; then
echo "android-api=21" >> $GITHUB_OUTPUT
else
echo "android-api=19" >> $GITHUB_OUTPUT
fi
if [[ "${{ matrix.profile }}" == "release" ]]; then
echo "cargo-args=--release" >> $GITHUB_OUTPUT
else
echo "cargo-args=" >> $GITHUB_OUTPUT
fi
- name: Build target ${{ matrix.target }}
run: cargo ndk --platform ${{ steps.config.outputs.android-api }} --target ${{ steps.config.outputs.android-target }} --bindgen -- build ${{ steps.config.outputs.cargo-args }} --features generate-bindings
- name: Get latest build path
id: result
run: |
echo "build-path=$(ls -td target/${{ matrix.target }}/${{ matrix.profile }}/build/oboe-sys-*/ | head -1)" >> $GITHUB_OUTPUT
- name: Copy bindings
if: matrix.rust == 'stable' && matrix.profile == 'release'
run: |
mkdir -p bindings
cp ${{ steps.result.outputs.build-path }}out/bindings.rs bindings/bindings_$(echo ${{ matrix.target }} | sed -r 's/^([^-]+).*$/\1/').rs
- name: Upload bindings
if: matrix.rust == 'stable' && matrix.profile == 'release'
uses: actions/upload-artifact@v4
with:
name: bindings-${{ matrix.target }}
path: bindings
overwrite: true
- name: Archive library
if: matrix.rust == 'stable'
run: tar -czf liboboe-ext_${{ matrix.target }}_${{ matrix.profile }}.tar.gz -C ${{ steps.result.outputs.build-path }}/out/library liboboe-ext.a
- name: Upload library
if: matrix.rust == 'stable'
uses: actions/upload-artifact@v4
with:
name: library-${{ matrix.target }}-${{ matrix.profile }}
path: liboboe-ext_${{ matrix.target }}_${{ matrix.profile }}.tar.gz
overwrite: true
update-bindings:
if: ${{ !startsWith(github.ref, 'refs/tags/') }}
needs:
- build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Download bindings
uses: actions/download-artifact@v4
with:
pattern: bindings-*
merge-multiple: true
path: sys/src
- name: Create Pull Request
uses: peter-evans/create-pull-request@v6
with:
base: ${{ github.head_ref }}
commit-message: Updated bindings
branch: update-bindings
delete-branch: true
title: Update bindings
body: |
Bindings should be updated to be consistent with latest changes
build-demo:
needs:
- build
- cargo-mobile2
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Setup JDK
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 17
- name: Setup Android SDK
uses: android-actions/setup-android@v3
with:
log-accepted-android-sdk-licenses: false
packages: build-tools;${{ env.SDK_BUILD_TOOLS_VERSION }} ndk;${{ env.NDK_VERSION }} platforms;android-${{ env.ANDROID_PLATFORM }}
- name: Config Android NDK
run: |
echo "$ANDROID_SDK_ROOT/ndk/$NDK_VERSION/toolchains/llvm/prebuilt/linux-x86_64/bin" >> $GITHUB_PATH
for var in ANDROID_NDK ANDROID_NDK_HOME ANDROID_NDK_LATEST_HOME ANDROID_NDK_ROOT NDK_HOME; do
echo "$var=$ANDROID_SDK_ROOT/ndk/$NDK_VERSION" >> $GITHUB_ENV
done
- name: Setup Rust
uses: dtolnay/rust-toolchain@v1
with:
toolchain: stable
targets: armv7-linux-androideabi aarch64-linux-android i686-linux-android x86_64-linux-android
- name: Setup Cargo mobile
uses: actions/cache@v4
with:
path: |
~/.cargo/bin/cargo-android
~/.cargo/bin/cargo-mobile
~/.cargo/.cargo-mobile2
key: ${{ runner.os }}-cargo-mobile2
- uses: Swatinem/rust-cache@v2
- name: Create signing key
run: |
if [ -z "${{ secrets.APK_KEYSTORE_PASSWORD }}" ]; then
# create temporary keystore to sign apk
rm -f demo/release.keystore
keytool -genkey -dname "cn=Nobrand, ou=RnD, o=example.com, c=US" -v -keystore demo/release.keystore -alias demo -keyalg RSA -keysize 2048 -validity 20000 -storepass android
else
# use existing keystore to sign apk
sed -i 's/keystore_password = "android"/keystore_password = "${{ secrets.APK_KEYSTORE_PASSWORD }}"/' demo/Cargo.toml
fi
- name: Init demo apk
run: |
cd demo && cargo mobile init && sed -ri 's/((compile|target)Sdk *= *)33/\134/g' gen/android/app/build.gradle.kts
- name: Build demo apk
run: cd demo && cargo mobile android apk build --release --split-per-abi
- name: Upload demo apk
uses: actions/upload-artifact@v4
with:
name: apk
path: demo/gen/android/app/build/outputs/apk/*/release/*.apk
release:
if: github.repository == 'katyo/oboe-rs' && startsWith(github.ref, 'refs/tags/')
needs:
- build
- build-demo
runs-on: ubuntu-latest
steps:
- name: Download libraries
uses: actions/download-artifact@v4
with:
pattern: library-*
merge-multiple: true
- name: Download demo
uses: actions/download-artifact@v4
with:
name: apk
- name: Create release
uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
files: |
*.tar.gz
*.apk
#prerelease: true
#draft: true
fail_on_unmatched_files: true
publish:
if: github.repository == 'katyo/oboe-rs' && startsWith(github.ref, 'refs/tags/')
needs:
- release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Setup Rust
uses: dtolnay/rust-toolchain@v1
with:
toolchain: stable
- name: Publish crates
uses: katyo/publish-crates@v1
with:
registry-token: ${{ secrets.CRATES_TOKEN }}
args: --no-verify
#dry-run: true
cargo-ndk:
runs-on: ubuntu-latest
steps:
- name: Prepare cache
uses: actions/cache@v4
id: cache
with:
path: ~/.cargo/bin/cargo-ndk
key: ${{ runner.os }}-cargo-ndk
- name: Setup cargo ndk
if: steps.cache.outputs.cache-hit != 'true'
run: cargo install cargo-ndk --force
cargo-mobile2:
runs-on: ubuntu-latest
steps:
- name: Prepare cache
uses: actions/cache@v4
id: cache
with:
path: |
~/.cargo/bin/cargo-android
~/.cargo/bin/cargo-mobile
~/.cargo/.cargo-mobile2
key: ${{ runner.os }}-cargo-mobile2
- name: Setup cargo mobile2
if: steps.cache.outputs.cache-hit != 'true'
run: cargo install cargo-mobile2