-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbdk-rep-build
executable file
·447 lines (382 loc) · 13.7 KB
/
bdk-rep-build
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
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
#!/bin/sh
set -e
bdkrepbuild__build() {
VERSION=$4
target=$3
library=$2
# check if the library to be built has been passed to the script
if [ -z "$2" ]; then
echo "❌ You did not specify a library to build! ❌"
usage="
USAGE
$ ./bdk-rep-build build <library> <target>
EXAMPLE
$ ./bdk-rep-build build bolt-dart x86_64-unknown-linux-gnu"
echo "$usage"
exit 1
fi
case "$2" in
"bdk-flutter" | "boltz-dart" | "lwk-dart")
parent_folder="$(pwd)/src"
lib_folder="$(pwd)/src/$2"
supported_libraries_keys=("bdk-flutter" "boltz-dart" "lwk-dart")
supported_libraries_urls=("https://github.com/LtbLightning/bdk-flutter.git" "https://github.com/SatoshiPortal/boltz-dart.git" "https://github.com/SatoshiPortal/lwk-dart.git")
# Function to get the repository URL
get_repo_url() {
local library_name="$1"
for i in "${!supported_libraries_keys[@]}"; do
if [[ "${supported_libraries_keys[i]}" == "$library_name" ]]; then
echo "${supported_libraries_urls[i]}"
return
fi
done
echo "Library not found"
exit 1
}
repo_url=$(get_repo_url $2)
if [[ -d "$lib_folder" ]]; then
if [[ -d "$lib_folder/.git" ]]; then
cd "$lib_folder" || exit 1
git fetch origin
# Check if local branch is behind
if [[ $(git status -uno | grep "Your branch is behind") ]]; then
git pull origin "$(git rev-parse --abbrev-ref HEAD)"
else
:
fi
else
rm -rf "$lib_folder"
cd $parent_folder
git clone "$repo_url"
cd $lib_folder
fi
else
cd $parent_folder
for subfolder in "$parent_folder"/*/; do
if [[ -d "$subfolder" ]]; then
rm -rf "$subfolder"
fi
done
git clone "$repo_url"
cd $lib_folder
fi
##Check out the passed tag version
git fetch --tags > /dev/null 2>&1
VALID_TAGS=$(git tag)
if [[ -n "$VERSION" ]]; then
if ! echo "$VALID_TAGS" | grep -q "^$VERSION$"; then
echo "❌ Invalid release tag '$VERSION' passed! Valid release tags:"
echo "$VALID_TAGS"
exit 1
fi
git switch --detach $VERSION
echo "You're building repo for version $VERSION"
else
echo "No version specified. Buildng at the lastest release tag of $library."
git fetch --tags
latest_tag=$(git describe --tags "$(git rev-list --tags --max-count=1)")
if [ -z "$latest_tag" ]; then
echo "❌ No tags found in the repository."
exit 1
fi
VERSION=$latest_tag
fi
;;
*)
echo "❌ Error: $2 is not a supported library. ❌"
supported_libraries="
Supported libraries are:
- lwk-dart
- bdk-flutter
- lwk-dart
"
echo "$supported_libraries"
exit 1
;;
esac
if [ -z "$3" ]; then
echo "❌ You did not specify a build target! ❌"
usage="
USAGE
$ ./bdk-rep-build build <library> <target>
EXAMPLE
$ ./bdk-rep-build build bolt-dart x86_64-unknown-linux-gnu
"
echo "$usage"
exit 1 # Exit script with error code
fi
cd ../../
if [ "$target" == "ios" ]; then
ios_targets=("aarch64-apple-ios" "x86_64-apple-ios" "aarch64-apple-ios-sim")
for trgt in "${ios_targets[@]}"; do
echo "🟡 Starting $trgt build"
. ./configs.sh
. "./build-scripts/$trgt.sh" "$library" "$VERSION"
done
elif [ "$target" == "android" ]; then
android_targets=("aarch64-linux-android" "armv7-linux-androideabi" "i686-linux-android" "x86_64-linux-android")
for trgt in "${android_targets[@]}"; do
echo "🟡 Starting $trgt build"
target=$trgt
. ./configs.sh
. "./build-scripts/$trgt.sh" "$library" "$VERSION"
done
elif [ "$target" == "linux" ]; then
linux_targets=("x86_64-unknown-linux-gnu" "aarch64-unknown-linux-gnu")
for trgt in "${linux_targets[@]}"; do
target=$trgt
echo "🟡 Starting $trgt build"
. ./configs.sh
. "./build-scripts/$trgt.sh" "$library" "$VERSION"
done
elif [ "$target" == "macos" ]; then
macos_targets=("x86_64-apple-darwin" "aarch64-apple-darwin")
for trgt in "${macos_targets[@]}"; do
echo "🟡 Starting $trgt build"
. ./configs.sh
. "./build-scripts/$trgt.sh" "$library" "$VERSION"
done
elif [ "$target" == "all" ]; then
echo "Building for all targets"
all_targets=(
"x86_64-unknown-linux-gnu" "aarch64-unknown-linux-gnu"
"armv7-linux-androideabi" "aarch64-linux-android" "i686-linux-android"
"x86_64-linux-android" "x86_64-apple-darwin"
"aarch64-apple-darwin" "aarch64-apple-ios" "aarch64-apple-ios-sim"
"x86_64-apple-ios"
)
for trgt in "${all_targets[@]}"; do
target=$trgt
echo "🟡 Starting $trgt build"
. ./configs.sh
. "./build-scripts/$trgt.sh" "$library" "$VERSION"
done
else
# For other targets, run the normal build process
case "$3" in
"x86_64-unknown-linux-gnu" | "aarch64-unknown-linux-gnu" | \
"armv7-linux-androideabi" | "aarch64-linux-android" | "i686-linux-android" | \
"x86_64-linux-android" | "x86_64-pc-windows-msvc" | "x86_64-apple-darwin" | \
"aarch64-apple-darwin" | "aarch64-apple-ios" | "aarch64-apple-ios-sim" | \
"x86_64-apple-ios")
;;
*)
echo "❌ Error: $3 is not a supported build target. ❌"
supported_targets="
Supported targets are:
-x86_64-unknown-linux-gnu
-aarch64-unknown-linux-gnu
-armv7-linux-androideabi
-aarch64-linux-android
-i686-linux-android
-x86_64-linux-android
-x86_64-pc-windows-msvc
-x86_64-apple-darwin
-aarch64-apple-darwin
-aarch64-apple-ios
-aarch64-apple-ios-sim
-x86_64-apple-ios
"
echo "$supported_targets"
exit 1
;;
esac
. ./configs.sh
echo "🟡 Starting $target build"
. "./build-scripts/$target.sh" "$library" "$VERSION"
fi
}
bdkrepbuild__help_build(){
help="
Create a binaries for specific target
USAGE
$ ./bdk-rep-build build <library> <target>
EXAMPLE
$ ./bdk-rep-build build bolt-dart x86_64-unknown-linux-gnu
"
echo "$help"
}
bdkrepbuild__verify(){
VERSION=$4
target=$3
library=$2
# check if the library to be built has been passed to the script
if [ -z "$2" ]; then
echo "❌ You did not specify a library to verify! ❌"
usage="
USAGE
$ ./bdk-rep-build verify <library> <target>
EXAMPLE
$ ./bdk-rep-build verify bolt-dart x86_64-unknown-linux-gnu
"
echo "$usage"
exit 1
fi
case "$2" in
"bdk-flutter" | "boltz-dart" | "lwk-dart")
;;
*)
echo "❌ Error: $2 is not a supported library. ❌"
supported_libraries="
Supported libraries are:
- lwk-dart
- bdk-flutter
- lwk-dart
"
echo "$supported_libraries"
exit 1
;;
esac
if [ -z "$3" ]; then
echo "❌ You did not specify a target to verify! ❌"
usage="
USAGE
$ ./bdk-rep-build verify <library> <target>
EXAMPLE
$ ./bdk-rep-build verify boltz-dart x86_64-unknown-linux-gnu
"
echo "$usage"
exit 1 # Exit script with error code
fi
case "$3" in
"x86_64-unknown-linux-gnu" | "aarch64-unknown-linux-gnu" | \
"armv7-linux-androideabi" | "aarch64-linux-android" | "i686-linux-android" | \
"x86_64-linux-android" | "x86_64-pc-windows-msvc" | "x86_64-apple-darwin" | \
"aarch64-apple-darwin" | "aarch64-apple-ios" | "aarch64-apple-ios-sim" | \
"x86_64-apple-ios")
;;
*)
echo "❌ Error: $3 is not a supported target you can verify. ❌"
supported_targets="
Supported targets are:
-x86_64-unknown-linux-gnu
-aarch64-unknown-linux-gnu
-armv7-linux-androideabi
-aarch64-linux-android
-i686-linux-android
-x86_64-linux-android
-x86_64-pc-windows-msvc
-x86_64-apple-darwin
-aarch64-apple-darwin
-aarch64-apple-ios
-aarch64-apple-ios-sim
-x86_64-apple-ios
"
echo "$supported_targets"
exit 1
;;
esac
cd src/$library/rust
package_name_line=$(grep -m 1 -E '^name = .*' Cargo.toml)
if [ ! -z "$package_name_line" ]; then
package_name=$(echo "$package_name_line" | cut -d '=' -f2 | tr -d '[:space:]' | sed 's/^"//' | sed 's/"$//')
else
echo "Error: Could not find 'name' in [package] section"
exit 1
fi
echo $package_name
cd ../../../
case "$target" in
"x86_64-unknown-linux-gnu") binary_name="x86_64-unknown-linux-gnu_lib$package_name.so" ;;
"aarch64-unknown-linux-gnu") binary_name="aarch64-unknown-linux-gnu_lib$package_name.so" ;;
"x86_64-apple-darwin") binary_name="x86_64-apple-darwin_lib$package_name.a" ;;
"aarch64-apple-darwin") binary_name="aarch64-apple-darwin_lib$package_name.a" ;;
"aarch64-apple-ios") binary_name="aarch64-apple-ios_lib$package_name.a" ;;
"aarch64-apple-ios-sim") binary_name="aarch64-apple-ios-sim_lib$package_name.a" ;;
"x86_64-apple-ios") binary_name="x86_64-apple-ios_lib$package_name.a" ;;
"aarch64-linux-android") binary_name="aarch64-linux-android_lib$package_name.so" ;;
"i686-linux-android") binary_name="i686-linux-android_lib$package_name.so" ;;
"x86_64-linux-android") binary_name="x86_64-linux-android_lib$package_name.so" ;;
"armv7-linux-androideabi") binary_name="armv7-linux-androideabi_lib$package_name.so" ;;
*) echo "Error: Unsupported target '$target'"; exit 1 ;;
esac
# Set variables
REPO="hkarani/$library"
DESTINATION="release/published/$library/$VERSION/$target"
mkdir -p $DESTINATION # Change this to your desired location
case "$library" in
"bdk-flutter") repo_name="LtbLightning/bdk-flutter" ;;
"boltz-dart") repo_name="SatoshiPortal/boltz-dart" ;;
"lwk-dart") repo_name="SatoshiPortal/lwk-dart" ;;
*)
echo "Error: Unsupported library '$library'"
exit 1
;;
esac
FILE_URL1=""
# Fetch the filename dynamically
FILE_URL="https://github.com/$REPO/releases/download/$VERSION/$binary_name"
# Check if a file was found
if [[ -z "$FILE_URL" ]]; then
echo "No matching file found for target: $target"
echo $FILE_URL
exit 1
fi
# Extract filename
FILENAME=$(basename "$FILE_URL")
# Download the file
curl -L -o "$DESTINATION/$FILENAME" "$FILE_URL" >/dev/null 2>&1
downloaded_file="$(cd "$DESTINATION" && pwd)/$FILENAME"
# target="$2"
# export $target
. ./verifier.sh $library $target $downloaded_file $VERSION
}
bdkrepbuild__help_verify() {
help="
Verify a build for a specific target
USAGE
$ ./bdk-rep-build verify <library> <target>
EXAMPLE
$ ./bdk-rep-build verify boltz-dart x86_64-unknown-linux-gnu
"
echo "$help"
}
bdkrepbuild__help(){
if [ $# -eq 2 ]; then
call "bdkrepbuild__$1_$2" "$@"
exit 0
fi
help="
____ ____ _ __ ____ _____ ____ ____ _ _ ___ _ ____
| __ )| _ \| |/ / | _ \| ____| _ \ | __ )| | | |_ _| | | _ \
| _ \| | | | ' /_____| |_) | _| | |_) |____| _ \| | | || || | | | | |
| |_) | |_| | . \_____| _ <| |___| __/_____| |_) | |_| || || |___| |_| |
|____/|____/|_|\_\ |_| \_\_____|_| |____/ \___/|___|_____|____/
Cross-compile and verify reproducible builds for bdk-rust library.
* To use with : BDK-Flutter, LWK-Dart, BOLTZ-dart
* Targeting: Linux, Android, iOS, MaoOS
USAGE
$ bdk-rep-build [COMMAND]
$ bdk-rep-build help [COMMAND]
COMMANDS
help show help
verify verify build against release
build build artifacts for a target
"
echo "$help"
}
call() {
func=$1
if type "$func" 1>/dev/null 2>&1; then
# if it's bdk_rep_build COMMAND help, then call help for that command
case $3 in
-h|--help|help)
call "bdkrepbuild__help_$2"
exit 0
;;
esac
shift # remove func from args
"$func" "$@" # invoke our named function w/ all remaining arguments
else
# if it's bdk_rep_build -h COMMAND, then call help for that command
case $2 in
-h|--help)
call "bdkrepbuild__help_$3"
exit 0
;;
esac
bdkrepbuild__help
exit 1
fi
}
call "bdkrepbuild__$1" "$@"