forked from tari-project/tari
-
Notifications
You must be signed in to change notification settings - Fork 0
365 lines (333 loc) · 15.4 KB
/
build_libffis.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
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
---
name: Build ffi libraries
'on':
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]*'
branches:
- 'build-ffis-*'
schedule:
- cron: '05 00 * * *'
env:
CARGO_UNSTABLE_SPARSE_REGISTRY: true
TARI_NETWORK_CHANGELOG: 'development'
TOOLCHAIN: 'stable'
## Must be a JSon string
BUILD_LIBFFIS: '["minotari_wallet_ffi","minotari_chat_ffi"]'
# BUILD_LIBFFIS: '["minotari_chat_ffi"]'
matrix-json-file: '.github/workflows/build_libffis.json'
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
matrix-prep:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
libffiss: ${{ steps.set-matrix.outputs.libffiss }}
steps:
- uses: actions/checkout@v4
- name: Set Matrix from JSon file
id: set-matrix
run: |
## build all targets images
# matrix=$( jq -s -c .[] .github/workflows/build_libffis_workflow.json )
matrix=$( jq -s -c .[] ${{ env.matrix-json-file }} )
#
## build only single target image
# matrix_selection=$( jq -c '.[] | select( ."runs-on" == "macos-latest" )' ${{ env.matrix-json-file }} )
# matrix_selection=$( jq -c '.[] | select( ."runs-on" == "macos-latest" )' ${{ env.matrix-json-file }} )
#
## buid select target images - build_enabled
# matrix_selection=$( jq -c '.[] | select( ."build_enabled" != false )' ${{ env.matrix-json-file }} )
#
## Setup json array
# matrix=$(echo ${matrix_selection} | jq -s -c)
#
## Setup the json build matrix
# matrix=$(echo ${matrix_selection} | jq -s -c '{"builds": .}')
#
echo "matrix=${matrix}" >> $GITHUB_OUTPUT
echo "libffiss=${BUILD_LIBFFIS}" >> $GITHUB_OUTPUT
matrix-check:
# Debug matrix
if: ${{ false }}
runs-on: ubuntu-latest
needs: matrix-prep
steps:
- name: Install json2yaml
run: |
sudo npm install -g json2yaml
- name: Check matrix definition
run: |
matrix='${{ needs.matrix-prep.outputs.matrix }}'
echo $matrix
echo $matrix | jq .
echo $matrix | json2yaml
libffiss='${{ needs.matrix-prep.outputs.libffiss }}'
echo $libffiss
echo $libffiss | jq .
echo $libffiss | json2yaml
builds:
needs: matrix-prep
strategy:
fail-fast: false
matrix:
libffis: ${{ fromJson(needs.matrix-prep.outputs.libffiss) }}
builds: ${{ fromJson(needs.matrix-prep.outputs.matrix) }}
runs-on: ${{ matrix.builds.runs-on }}
steps:
- name: Checkout source code
uses: actions/checkout@v4
- name: Declare TestNet for tags
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
shell: bash
run: |
source buildtools/multinet_envs.sh ${{ github.ref_name }}
echo ${TARI_NETWORK}
echo ${TARI_NETWORK_CHANGELOG}
echo "TARI_NETWORK=${TARI_NETWORK}" >> $GITHUB_ENV
echo "TARI_NETWORK_CHANGELOG=${TARI_NETWORK_CHANGELOG}" >> $GITHUB_ENV
- name: Declare Android/iOS envs
shell: bash
run: |
if [[ "${{ matrix.builds.target }}" =~ "android" ]]; then
echo "CFLAGS=-DMDB_USE_ROBUST=0" >> $GITHUB_ENV
echo "TARGET_PLATFORM=android" >> $GITHUB_ENV
else
echo "TARGET_PLATFORM=ios" >> $GITHUB_ENV
if [[ "${{ matrix.builds.target }}" =~ "-sim" ]]; then
echo "TARGET_SIM=-sim" >> $GITHUB_ENV
fi
fi
# Strip begining
tempEnv="${{ matrix.builds.target }}"
echo "TARGET_ARCH=${tempEnv/-*/}" >> $GITHUB_ENV
# Strip outside of *_X_*
tempEnv="${{ matrix.libffis }}"
tempEnv=${tempEnv#*_}
echo "TARGET_NAME=${tempEnv%_*}" >> $GITHUB_ENV
- name: Setup Rust toolchain
uses: dtolnay/rust-toolchain@master
with:
components: rustfmt, clippy
toolchain: ${{ env.TOOLCHAIN }}
targets: ${{ matrix.builds.target }}
# Don't use caches for binary builds when releasing. Start from a clean slate.
- name: Cache cargo files and outputs
if: ${{ ! startsWith(github.ref, 'refs/tags/v') }}
uses: Swatinem/rust-cache@v2
- name: Build ${{ matrix.libffis }} libraries
shell: bash
run: |
# rustup target list
# rustup toolchain list
# rustup show
if [ "${{ matrix.builds.cross }}" == "true" ]; then
cargo install cross
cross build --lib --release --locked \
--package ${{ matrix.libffis }} \
--target=${{ matrix.builds.target }}
else
rustup target add ${{ matrix.builds.target }}
# rustup toolchain install stable-aarch64-unknown-linux-gnu --force-non-host
cargo build --lib --release --locked \
--package ${{ matrix.libffis }} \
--target=${{ matrix.builds.target }}
fi
- name: Prepare ${{ matrix.libffis }} libraries
shell: bash
run: |
mkdir -p "${{ runner.temp }}/lib${{ matrix.libffis }}-${{ env.TARGET_PLATFORM }}-${{ env.TARGET_ARCH }}${{ env.TARGET_SIM }}"
cd "${{ runner.temp }}/lib${{ matrix.libffis }}-${{ env.TARGET_PLATFORM }}-${{ env.TARGET_ARCH }}${{ env.TARGET_SIM }}"
cp -v "$GITHUB_WORKSPACE/target/${{ matrix.builds.target }}/release/lib${{ matrix.libffis }}.a" "lib${{ matrix.libffis }}.${{ env.TARGET_PLATFORM }}_${{ env.TARGET_ARCH }}${{ env.TARGET_SIM }}.a"
cp -v "$GITHUB_WORKSPACE/base_layer/${{ env.TARGET_NAME }}_ffi/${{ env.TARGET_NAME }}.h" lib${{ matrix.libffis }}.h
if [ -f "$GITHUB_WORKSPACE/changelog-${{ env.TARI_NETWORK_CHANGELOG }}.md" ]; then
cp -v "$GITHUB_WORKSPACE/changelog-${{ env.TARI_NETWORK_CHANGELOG }}.md" .
TARI_NETWORK_CHANGELOG_FILE=lib${{ matrix.libffis }}-${{ env.TARGET_PLATFORM }}-${{ env.TARGET_ARCH }}${{ env.TARGET_SIM }}/changelog-${{ env.TARI_NETWORK_CHANGELOG }}.md
echo ${TARI_NETWORK_CHANGELOG_FILE}
fi
cd ..
shasum -a 256 \
"lib${{ matrix.libffis }}-${{ env.TARGET_PLATFORM }}-${{ env.TARGET_ARCH }}${{ env.TARGET_SIM }}/lib${{ matrix.libffis }}.${{ env.TARGET_PLATFORM }}_${{ env.TARGET_ARCH }}${{ env.TARGET_SIM }}.a" \
"lib${{ matrix.libffis }}-${{ env.TARGET_PLATFORM }}-${{ env.TARGET_ARCH }}${{ env.TARGET_SIM }}/lib${{ matrix.libffis }}.h" \
"${TARI_NETWORK_CHANGELOG_FILE}" \
> "lib${{ matrix.libffis }}-${{ env.TARGET_PLATFORM }}-${{ env.TARGET_ARCH }}${{ env.TARGET_SIM }}/lib${{ matrix.libffis }}.${{ env.TARGET_PLATFORM }}_${{ env.TARGET_ARCH }}${{ env.TARGET_SIM }}.sha256"
ls -alhtR "${{ runner.temp }}/lib${{ matrix.libffis }}-${{ env.TARGET_PLATFORM }}-${{ env.TARGET_ARCH }}${{ env.TARGET_SIM }}"
- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
name: lib${{ matrix.libffis }}-${{ env.TARGET_PLATFORM }}-${{ env.TARGET_ARCH }}${{ env.TARGET_SIM }}
path: ${{ runner.temp }}/lib${{ matrix.libffis }}-${{ env.TARGET_PLATFORM }}-${{ env.TARGET_ARCH }}${{ env.TARGET_SIM }}
ios_assemble:
name: Assemble iOS multiArch for ${{ matrix.libffis }}"
# Limits to only iOS builds
runs-on: macos-latest
needs: [matrix-prep, builds]
strategy:
fail-fast: false
matrix:
libffis: ${{ fromJson(needs.matrix-prep.outputs.libffiss) }}
steps:
- name: Install macOS dependencies
run: brew install coreutils
- name: Download iOS libffiss for ${{ matrix.libffis }}
uses: actions/download-artifact@v3
with:
# wildcard downloads not supported yet ( minotari_*_ffi-ios-* )
# name: ${{ matrix.libffis }}-ios
path: libffiss
- name: Verify checksums
shell: bash
working-directory: libffiss
run: |
ls -alhtR
find . -name "*.sha256" -type f -print | xargs cat >> libffiss.txt.sha256-verify
cat libffiss.txt.sha256-verify
sha256sum -c libffiss.txt.sha256-verify
- name: Assemble iOS universal libffis
shell: bash
working-directory: libffiss
run: |
ls -alhtR
mkdir lib${{ matrix.libffis }}-ios-universal
cp -v "lib${{ matrix.libffis }}-ios-x86_64/lib${{ matrix.libffis }}.h" \
lib${{ matrix.libffis }}-ios-universal/
echo "Check for changelog"
if [ -f lib${{ matrix.libffis }}-ios-x86_64/changelog-*.md ]; then
echo "Changelog found"
envChangelogFull=$(ls lib${{ matrix.libffis }}-ios-x86_64/changelog-*.md)
echo ${envChangelogFull}
# Strip suffix
#envChangelog=${envChangelogFull::-3}
envChangelog=${envChangelogFull:0:${#envChangelogFull}-3}
echo ${envChangelog}
# Strip prefix
TARI_NETWORK_CHANGELOG=${envChangelog##*/changelog-}
echo ${TARI_NETWORK_CHANGELOG}
cp -v "lib${{ matrix.libffis }}-ios-x86_64/changelog-${TARI_NETWORK_CHANGELOG}.md" \
lib${{ matrix.libffis }}-ios-universal/
TARI_NETWORK_CHANGELOG_FILE=lib${{ matrix.libffis }}-ios-universal/changelog-${TARI_NETWORK_CHANGELOG}.md
echo ${TARI_NETWORK_CHANGELOG_FILE}
else
echo "No changelog found"
fi
lipo -create \
"lib${{ matrix.libffis }}-ios-x86_64/lib${{ matrix.libffis }}.ios_x86_64.a" \
"lib${{ matrix.libffis }}-ios-aarch64/lib${{ matrix.libffis }}.ios_aarch64.a" \
-output "lib${{ matrix.libffis }}-ios-universal/lib${{ matrix.libffis }}.ios_universal.a"
shasum -a 256 \
"lib${{ matrix.libffis }}-ios-universal/lib${{ matrix.libffis }}.ios_universal.a" \
"lib${{ matrix.libffis }}-ios-universal/lib${{ matrix.libffis }}.h" "${TARI_NETWORK_CHANGELOG_FILE}" \
> "lib${{ matrix.libffis }}-ios-universal/lib${{ matrix.libffis }}.ios_universal.sha256"
ls -alhtR
- name: Upload iOS universal libffis artifacts
uses: actions/upload-artifact@v3
with:
name: lib${{ matrix.libffis }}-ios-universal
path: libffiss/lib${{ matrix.libffis }}-ios-universal
- name: Assemble iOS libffis xcframework
shell: bash
working-directory: libffiss
run: |
ls -alhtR
mkdir lib${{ matrix.libffis }}-ios-universal-sim
lipo -create \
"lib${{ matrix.libffis }}-ios-x86_64/lib${{ matrix.libffis }}.ios_x86_64.a" \
"lib${{ matrix.libffis }}-ios-aarch64-sim/lib${{ matrix.libffis }}.ios_aarch64-sim.a" \
-output "lib${{ matrix.libffis }}-ios-universal-sim/lib${{ matrix.libffis }}.ios_universal-sim.a"
mkdir lib${{ matrix.libffis }}-ios-xcframework
echo "Check for changelog"
if [ -f lib${{ matrix.libffis }}-ios-x86_64/changelog-*.md ]; then
echo "Changelog found"
envChangelogFull=$(ls lib${{ matrix.libffis }}-ios-x86_64/changelog-*.md)
echo ${envChangelogFull}
# Strip suffix
#envChangelog=${envChangelogFull::-3}
envChangelog=${envChangelogFull:0:${#envChangelogFull}-3}
echo ${envChangelog}
# Strip prefix
TARI_NETWORK_CHANGELOG=${envChangelog##*/changelog-}
echo ${TARI_NETWORK_CHANGELOG}
cp -v "lib${{ matrix.libffis }}-ios-x86_64/changelog-${TARI_NETWORK_CHANGELOG}.md" \
lib${{ matrix.libffis }}-ios-xcframework/
TARI_NETWORK_CHANGELOG_FILE=lib${{ matrix.libffis }}-ios-xcframework/changelog-${TARI_NETWORK_CHANGELOG}.md
echo ${TARI_NETWORK_CHANGELOG_FILE}
else
echo "No changelog found"
fi
xcodebuild -create-xcframework \
-library "lib${{ matrix.libffis }}-ios-universal-sim/lib${{ matrix.libffis }}.ios_universal-sim.a" \
-headers "lib${{ matrix.libffis }}-ios-x86_64/lib${{ matrix.libffis }}.h" \
-library "lib${{ matrix.libffis }}-ios-aarch64/lib${{ matrix.libffis }}.ios_aarch64.a" \
-headers "lib${{ matrix.libffis }}-ios-aarch64/lib${{ matrix.libffis }}.h" \
-output lib${{ matrix.libffis }}-ios-xcframework/lib${{ matrix.libffis }}_ios.xcframework
shasum -a 256 \
"lib${{ matrix.libffis }}-ios-xcframework/lib${{ matrix.libffis }}_ios.xcframework/Info.plist" \
"lib${{ matrix.libffis }}-ios-xcframework/lib${{ matrix.libffis }}_ios.xcframework/ios-arm64/Headers" \
"lib${{ matrix.libffis }}-ios-xcframework/lib${{ matrix.libffis }}_ios.xcframework/ios-arm64/lib${{ matrix.libffis }}.ios_aarch64.a" \
"lib${{ matrix.libffis }}-ios-xcframework/lib${{ matrix.libffis }}_ios.xcframework/ios-arm64_x86_64-simulator/Headers" \
"lib${{ matrix.libffis }}-ios-xcframework/lib${{ matrix.libffis }}_ios.xcframework/ios-arm64_x86_64-simulator/lib${{ matrix.libffis }}.ios_universal-sim.a" \
"${TARI_NETWORK_CHANGELOG_FILE}" \
> "lib${{ matrix.libffis }}-ios-xcframework/lib${{ matrix.libffis }}.ios_xcframework.sha256"
ls -alhtR
- name: Upload iOS xcframework libffis artifacts
uses: actions/upload-artifact@v3
with:
name: lib${{ matrix.libffis }}-ios-xcframework
path: libffiss/lib${{ matrix.libffis }}-ios-xcframework
create_release:
name: Create release for ffi libraries
runs-on: ubuntu-latest
needs: [matrix-prep, builds, ios_assemble]
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
steps:
- name: Download all ffi libraries
uses: actions/download-artifact@v3
with:
path: libffiss
- name: Verify checksums
shell: bash
working-directory: libffiss
run: |
ls -alhtR
find . -name "*.sha256" -type f -print | xargs cat >> libffiss.txt.sha256-verify
cat libffiss.txt.sha256-verify
sha256sum -c libffiss.txt.sha256-verify
rm -fv ibffiss.txt.sha256-verify
- name: Archive iOS xcframework(s)
shell: bash
working-directory: libffiss
run: |
# Spaces are important - string to array
FFI_DIRS=( $(echo ${BUILD_LIBFFIS} | jq -r '.[]') )
mkdir -p releases
for FFI_DIR in "${FFI_DIRS[@]}"; do
echo "xcframework for ${FFI_DIR}"
if [ -d lib${FFI_DIR}-ios-xcframework ]; then
7z a lib${FFI_DIR}.ios-xcframework.zip lib${FFI_DIR}-ios-xcframework/*
rm -fvr lib${FFI_DIR}-ios-xcframework
shasum -a 256 \
"lib${FFI_DIR}.ios-xcframework.zip" \
> "lib${FFI_DIR}.ios-xcframework.zip.sha256"
mv -v lib${FFI_DIR}.ios-xcframework.zip* releases
fi
done
- name: Release preparation from assets
shell: bash
working-directory: libffiss
run: |
find . -regextype posix-extended -regex '.*\.(a|h|md|sha256)' -type f \
-not \( -path "./releases" -prune \) \
-exec cp -fv {} ./releases/ \;
ls -alhtR
- name: Create release
uses: ncipollo/release-action@v1
with:
artifacts: "libffiss/releases/*"
token: ${{ secrets.GITHUB_TOKEN }}
prerelease: true
draft: true
allowUpdates: true
updateOnlyUnreleased: true
replacesArtifacts: true