-
Notifications
You must be signed in to change notification settings - Fork 12
369 lines (337 loc) · 16.9 KB
/
build.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
366
367
368
369
name: Build
on:
push:
branches:
- release/*
- feature/*
- develop
- main
pull_request:
branches:
- release/*
- feature/*
- develop
- main
jobs:
build:
runs-on: macos-latest
continue-on-error: true
strategy:
matrix:
build-target:
# radix-engine-toolkit Crate
- crate: radix-engine-toolkit
target-triple: aarch64-apple-darwin
custom-linker: ""
custom-compiler: /usr/local/opt/llvm/bin/clang
custom-archiver: /usr/local/opt/llvm/bin/llvm-ar
- crate: radix-engine-toolkit
target-triple: x86_64-apple-ios
custom-linker: ""
custom-compiler: /usr/local/opt/llvm/bin/clang
custom-archiver: /usr/local/opt/llvm/bin/llvm-ar
- crate: radix-engine-toolkit
target-triple: x86_64-apple-darwin
custom-linker: ""
custom-compiler: /usr/local/opt/llvm/bin/clang
custom-archiver: /usr/local/opt/llvm/bin/llvm-ar
- crate: radix-engine-toolkit
target-triple: aarch64-apple-ios
custom-linker: ""
custom-compiler: /usr/local/opt/llvm/bin/clang
custom-archiver: /usr/local/opt/llvm/bin/llvm-ar
- crate: radix-engine-toolkit
target-triple: aarch64-apple-ios-sim
custom-linker: ""
custom-compiler: /usr/local/opt/llvm/bin/clang
custom-archiver: /usr/local/opt/llvm/bin/llvm-ar
- crate: radix-engine-toolkit
target-triple: x86_64-pc-windows-gnu
custom-linker: ""
custom-compiler: x86_64-w64-mingw32-gcc
custom-archiver: x86_64-w64-mingw32-ar
- crate: radix-engine-toolkit
target-triple: x86_64-unknown-linux-gnu
custom-linker: x86_64-unknown-linux-gnu-gcc
custom-compiler: /usr/local/opt/llvm/bin/clang
custom-archiver: /usr/local/opt/llvm/bin/llvm-ar
- crate: radix-engine-toolkit
target-triple: aarch64-unknown-linux-gnu
custom-linker: aarch64-unknown-linux-gnu-gcc
custom-compiler: aarch64-unknown-linux-gnu-gcc
custom-archiver: aarch64-unknown-linux-gnu-gcc-ar
- crate: radix-engine-toolkit
target-triple: i686-unknown-linux-gnu
custom-linker: i686-unknown-linux-gnu-gcc
custom-compiler: i686-unknown-linux-gnu-gcc
custom-archiver: i686-unknown-linux-gnu-gcc-ar
- crate: radix-engine-toolkit
target-triple: wasm32-unknown-unknown
custom-linker: ""
custom-compiler: /usr/local/opt/llvm/bin/clang
custom-archiver: /usr/local/opt/llvm/bin/llvm-ar
- crate: radix-engine-toolkit
target-triple: aarch64-linux-android
custom-linker: /usr/local/share/android-ndk/toolchains/llvm/prebuilt/darwin-x86_64/bin/aarch64-linux-android21-clang
custom-compiler: /usr/local/share/android-ndk/toolchains/llvm/prebuilt/darwin-x86_64/bin/aarch64-linux-android21-clang
custom-archiver: /usr/local/share/android-ndk/toolchains/llvm/prebuilt/darwin-x86_64/bin/llvm-ar
- crate: radix-engine-toolkit
target-triple: armv7-linux-androideabi
custom-linker: /usr/local/share/android-ndk/toolchains/llvm/prebuilt/darwin-x86_64/bin/armv7a-linux-androideabi19-clang
custom-compiler: /usr/local/share/android-ndk/toolchains/llvm/prebuilt/darwin-x86_64/bin/armv7a-linux-androideabi19-clang
custom-archiver: /usr/local/share/android-ndk/toolchains/llvm/prebuilt/darwin-x86_64/bin/llvm-ar
- crate: radix-engine-toolkit
target-triple: i686-linux-android
custom-linker: /usr/local/share/android-ndk/toolchains/llvm/prebuilt/darwin-x86_64/bin/i686-linux-android19-clang
custom-compiler: /usr/local/share/android-ndk/toolchains/llvm/prebuilt/darwin-x86_64/bin/i686-linux-android19-clang
custom-archiver: /usr/local/share/android-ndk/toolchains/llvm/prebuilt/darwin-x86_64/bin/llvm-ar
# radix-engine-toolkit-uniffi Crate
- crate: radix-engine-toolkit-uniffi
target-triple: aarch64-apple-darwin
custom-linker: ""
custom-compiler: /usr/local/opt/llvm/bin/clang
custom-archiver: /usr/local/opt/llvm/bin/llvm-ar
- crate: radix-engine-toolkit-uniffi
target-triple: x86_64-apple-ios
custom-linker: ""
custom-compiler: /usr/local/opt/llvm/bin/clang
custom-archiver: /usr/local/opt/llvm/bin/llvm-ar
- crate: radix-engine-toolkit-uniffi
target-triple: x86_64-apple-darwin
custom-linker: ""
custom-compiler: /usr/local/opt/llvm/bin/clang
custom-archiver: /usr/local/opt/llvm/bin/llvm-ar
- crate: radix-engine-toolkit-uniffi
target-triple: aarch64-apple-ios
custom-linker: ""
custom-compiler: /usr/local/opt/llvm/bin/clang
custom-archiver: /usr/local/opt/llvm/bin/llvm-ar
- crate: radix-engine-toolkit-uniffi
target-triple: aarch64-apple-ios-sim
custom-linker: ""
custom-compiler: /usr/local/opt/llvm/bin/clang
custom-archiver: /usr/local/opt/llvm/bin/llvm-ar
- crate: radix-engine-toolkit-uniffi
target-triple: x86_64-pc-windows-gnu
custom-linker: ""
custom-compiler: x86_64-w64-mingw32-gcc
custom-archiver: x86_64-w64-mingw32-ar
- crate: radix-engine-toolkit-uniffi
target-triple: x86_64-unknown-linux-gnu
custom-linker: x86_64-unknown-linux-gnu-gcc
custom-compiler: /usr/local/opt/llvm/bin/clang
custom-archiver: /usr/local/opt/llvm/bin/llvm-ar
- crate: radix-engine-toolkit-uniffi
target-triple: aarch64-unknown-linux-gnu
custom-linker: aarch64-unknown-linux-gnu-gcc
custom-compiler: aarch64-unknown-linux-gnu-gcc
custom-archiver: aarch64-unknown-linux-gnu-gcc-ar
- crate: radix-engine-toolkit-uniffi
target-triple: i686-unknown-linux-gnu
custom-linker: i686-unknown-linux-gnu-gcc
custom-compiler: i686-unknown-linux-gnu-gcc
custom-archiver: i686-unknown-linux-gnu-gcc-ar
- crate: radix-engine-toolkit-uniffi
target-triple: aarch64-linux-android
custom-linker: /usr/local/share/android-ndk/toolchains/llvm/prebuilt/darwin-x86_64/bin/aarch64-linux-android21-clang
custom-compiler: /usr/local/share/android-ndk/toolchains/llvm/prebuilt/darwin-x86_64/bin/aarch64-linux-android21-clang
custom-archiver: /usr/local/share/android-ndk/toolchains/llvm/prebuilt/darwin-x86_64/bin/llvm-ar
- crate: radix-engine-toolkit-uniffi
target-triple: armv7-linux-androideabi
custom-linker: /usr/local/share/android-ndk/toolchains/llvm/prebuilt/darwin-x86_64/bin/armv7a-linux-androideabi19-clang
custom-compiler: /usr/local/share/android-ndk/toolchains/llvm/prebuilt/darwin-x86_64/bin/armv7a-linux-androideabi19-clang
custom-archiver: /usr/local/share/android-ndk/toolchains/llvm/prebuilt/darwin-x86_64/bin/llvm-ar
- crate: radix-engine-toolkit-uniffi
target-triple: i686-linux-android
custom-linker: /usr/local/share/android-ndk/toolchains/llvm/prebuilt/darwin-x86_64/bin/i686-linux-android19-clang
custom-compiler: /usr/local/share/android-ndk/toolchains/llvm/prebuilt/darwin-x86_64/bin/i686-linux-android19-clang
custom-archiver: /usr/local/share/android-ndk/toolchains/llvm/prebuilt/darwin-x86_64/bin/llvm-ar
steps:
- uses: FranzDiebold/github-env-vars-action@v2
- name: Checkout
uses: actions/checkout@v3
- name: Install Build Dependencies
run: |
brew tap SergioBenitez/osxct
brew install llvm
brew install x86_64-unknown-linux-gnu
brew install mingw-w64
brew install --cask android-ndk
brew tap messense/macos-cross-toolchains
brew install aarch64-unknown-linux-gnu
brew install i686-unknown-linux-gnu
- name: Install Rust Toolchain
run: |
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs -o rustup.sh
chmod +x rustup.sh
./rustup.sh -y
rustup update
rustup toolchain install nightly
- name: Install Rust Targets
run: |
rustup target install ${{ matrix.build-target.target-triple }}
rustup +nightly target install ${{ matrix.build-target.target-triple }}
rustup component add rust-src --toolchain nightly-x86_64-apple-darwin
- name: Building Toolkit
run: |
(
export CURRENT_DIRECTORY=$(pwd)
export CRATE_PATH="$CURRENT_DIRECTORY/${{matrix.build-target.crate}}"
cd $CRATE_PATH
export LINKER_ENVIRONMENT_VARIABLE="CARGO_TARGET_"$(echo ${{ matrix.build-target.target-triple }} | tr '[:lower:]' '[:upper:]' | sed 's/-/_/g')"_LINKER"
if [ ! -z "${{ matrix.build-target.custom-linker }}" ]
then
export $LINKER_ENVIRONMENT_VARIABLE=${{ matrix.build-target.custom-linker }}
fi
export CC=${{ matrix.build-target.custom-compiler }}
export AR=${{ matrix.build-target.custom-archiver }}
cargo +nightly build \
-Z build-std=std,panic_abort \
-Z build-std-features=panic_immediate_abort \
--target ${{ matrix.build-target.target-triple }} \
--release
unset $LINKER_ENVIRONMENT_VARIABLE
export CC="/usr/local/opt/llvm/bin/clang"
export AR="/usr/local/opt/llvm/bin/llvm-ar"
if [ "${{matrix.build-target.crate}}" == "radix-engine-toolkit" ]; then
INCLUDE_DIRECTORY_PATH="$CRATE_PATH/target/${{ matrix.build-target.target-triple }}/release/include"
mkdir $INCLUDE_DIRECTORY_PATH
rustup default nightly
cbindgen \
--lang c \
--config cbindgen.toml \
--output "$INCLUDE_DIRECTORY_PATH/libradix_engine_toolkit.h"
rustup default stable
echo "module RadixEngineToolkit {" > "$INCLUDE_DIRECTORY_PATH/module.modulemap"
echo " umbrella header \"libradix_engine_toolkit.h\"" >> "$INCLUDE_DIRECTORY_PATH/module.modulemap"
echo " export *" >> "$INCLUDE_DIRECTORY_PATH/module.modulemap"
echo "}" >> "$INCLUDE_DIRECTORY_PATH/module.modulemap"
fi
(
BUILD_PATH="$CRATE_PATH/target/${{ matrix.build-target.target-triple }}/release"
cd $BUILD_PATH
BUILD_ARTIFACTS_PATH=$(find . -type f \( -name "*.a" -o -name "*.dylib" -o -name "*.dll" -o -name "*.so" -o -name "*.d" -o -name "*.wasm" \) -maxdepth 1)
if [ "${{matrix.build-target.crate}}" == "radix-engine-toolkit" ]; then
tar -czf "./${{ matrix.build-target.target-triple }}.tar.gz" $BUILD_ARTIFACTS_PATH ./include
else
tar -czf "./${{ matrix.build-target.target-triple }}.tar.gz" $BUILD_ARTIFACTS_PATH
fi
)
)
- name: Upload Build Artifacts
uses: actions/upload-artifact@v3
with:
name: "${{ matrix.build-target.crate }}-${{ matrix.build-target.target-triple }}"
path: "./${{matrix.build-target.crate}}/target/${{ matrix.build-target.target-triple }}/release/${{ matrix.build-target.target-triple }}.tar.gz"
create-uniffi-bindings:
needs: [build]
runs-on: macos-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- uses: actions/download-artifact@v3
with:
path: artifacts
- name: Extracting the Library
run: |
mkdir extracted
cd radix-engine-toolkit-uniffi-x86_64-apple-darwin
tar -xvzf x86_64-apple-darwin.tar.gz --directory="../extracted"
working-directory: artifacts
- name: Generate the Bindings
run: |
cargo run \
--manifest-path="../../uniffi-bindgen/Cargo.toml" -- \
generate ../../radix-engine-toolkit-uniffi/src/radix_engine_toolkit_uniffi.udl \
--language swift \
--out-dir ./output \
--lib-file ./libradix_engine_toolkit_uniffi.a
cargo run \
--manifest-path="../../uniffi-bindgen/Cargo.toml" -- \
generate ../../radix-engine-toolkit-uniffi/src/radix_engine_toolkit_uniffi.udl \
--language kotlin \
--out-dir ./output \
--lib-file ./libradix_engine_toolkit_uniffi.a
working-directory: artifacts/extracted
- name: Compress Artifacts
run: |
tar -czf "./UniFFI-Bindings.tar.gz" ./output
working-directory: artifacts/extracted
- name: Upload Bindings
uses: actions/upload-artifact@v3
with:
name: "UniFFI-Bindings"
path: "./artifacts/extracted/UniFFI-Bindings.tar.gz"
build-test-kit:
needs: [build]
runs-on: macos-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Run Generator
run: cargo run
working-directory: generator
- name: Compress Generated
run: tar -czf "./test-kit.tar.gz" ./output
working-directory: generator
- name: Upload Generated Artifacts
uses: actions/upload-artifact@v3
with:
name: "test-kit.tar.gz"
path: "./generator/test-kit.tar.gz"
publish-swift-spm:
needs: [build, create-uniffi-bindings]
runs-on: macos-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- uses: actions/download-artifact@v3
with:
path: artifacts
- name: Build XCFramework
working-directory: artifacts
run: |
# The name of the crate that we will be creating the XCFramework and the bindings for.
CRATE_NAME="radix-engine-toolkit-uniffi"
# The name of the directory to write the extracted libraries in.
EXTRACTED="extracted"
mkdir $EXTRACTED
# Extract the UniFFI Bindings
mkdir $EXTRACTED/UniFFI-Bindings
tar -xvzf "UniFFI-Bindings/UniFFI-Bindings.tar.gz" --directory="./$EXTRACTED/UniFFI-Bindings"
# Creating the include directory - this will be used in the XCFramework build steps
mkdir $EXTRACTED/include
cp $EXTRACTED/UniFFI-Bindings/output/radix_engine_toolkit_uniffiFFI.modulemap $EXTRACTED/include/module.moduplemap
cp $EXTRACTED/UniFFI-Bindings/output/radix_engine_toolkit_uniffiFFI.h $EXTRACTED/include/radix_engine_toolkit_uniffiFFI.h
# Extract the builds of the targets that we need. All of them have a common known pattern which
# we depend on for the extraction: `${CRATE_NAME}-${TARGET_TRIPLE}`.
for TARGET_TRIPLE in "aarch64-apple-darwin" "x86_64-apple-darwin" "aarch64-apple-ios-sim" "x86_64-apple-ios" "aarch64-apple-ios"
do
# Create a new directory for the target
mkdir $EXTRACTED/$TARGET_TRIPLE;
BUILD_ARTIFACT="$CRATE_NAME-$TARGET_TRIPLE"
tar -xvzf "$BUILD_ARTIFACT/$TARGET_TRIPLE.tar.gz" --directory="./$EXTRACTED/$TARGET_TRIPLE"
done
rm -rf ./$EXTRACTED/*.tar.gz
# Using Lipo to combine some of the libraries into fat libraries.
mkdir ./$EXTRACTED/macos-arm64_x86_64/
mkdir ./$EXTRACTED/ios-simulator-arm64_x86_64
lipo -create \
"./$EXTRACTED/aarch64-apple-darwin/libradix_engine_toolkit_uniffi.a" \
"./$EXTRACTED/x86_64-apple-darwin/libradix_engine_toolkit_uniffi.a" \
-o "./$EXTRACTED/macos-arm64_x86_64/libradix_engine_toolkit_uniffi.a"
lipo -create \
"./$EXTRACTED/aarch64-apple-ios-sim/libradix_engine_toolkit_uniffi.a" \
"./$EXTRACTED/x86_64-apple-ios/libradix_engine_toolkit_uniffi.a" \
-o "./$EXTRACTED/ios-simulator-arm64_x86_64/libradix_engine_toolkit_uniffi.a"
# Creating the XCFramework
xcodebuild -create-xcframework \
-library "./$EXTRACTED/aarch64-apple-ios/libradix_engine_toolkit_uniffi.a" \
-headers "./$EXTRACTED/include" \
-library "./$EXTRACTED/macos-arm64_x86_64/libradix_engine_toolkit_uniffi.a" \
-headers "./$EXTRACTED/include" \
-library "./$EXTRACTED/ios-simulator-arm64_x86_64/libradix_engine_toolkit_uniffi.a" \
-headers "./$EXTRACTED/include" \
-output "./$EXTRACTED/RadixEngineToolkitUniFFI.xcframework"
# TODO: We have now built the XCFramework and we're ready to build a Swift package of it
# + the UniFFI bindings