Skip to content

Commit b4221b4

Browse files
chore(build): Improve build scripts, configure bootstrap.sh (#4040)
1 parent 4af0ee3 commit b4221b4

File tree

5 files changed

+111
-51
lines changed

5 files changed

+111
-51
lines changed

bootstrap.sh

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,43 @@
55
# Fail if any commands fails
66
set -e
77

8-
echo "#### Initializing workspace with dependencies ... ####"
8+
source tools/parse_args "$@"
9+
10+
if isHelp; then
11+
echo "usage: bootstrap.sh [-h | --help] [all | wasm | android | ios]"
12+
echo ""
13+
echo "Installs dependencies and prepares WalletCore for building"
14+
exit 0
15+
fi
16+
17+
echo "#### Installing system dependencies ... ####"
18+
if [[ $(uname) == "Darwin" ]]; then
19+
tools/install-sys-dependencies-macos
20+
else
21+
tools/install-sys-dependencies-linux
22+
fi
23+
24+
echo "#### Installing C++ libraries ... ####"
925
tools/install-dependencies
10-
tools/install-rust-dependencies
1126

12-
echo "#### Building and running tests ... ####"
13-
tools/build-and-test
27+
echo "#### Installing Rust toolchain and tools ... ####"
28+
tools/install-rust-dependencies dev
29+
30+
# WASM
31+
if isTargetSpecified "wasm"; then
32+
echo "#### Installing WASM environment ... ####"
33+
tools/install-wasm-dependencies
34+
fi
35+
36+
# Android
37+
if isTargetSpecified "android"; then
38+
echo "#### Installing Android dependencies ... ####"
39+
tools/install-android-dependencies
40+
fi
41+
42+
echo "#### Generating files... ####"
43+
tools/generate-files "$@"
44+
45+
echo ""
46+
echo "WalletCore is ready for development!"
47+
echo "Consider running native C++ tests via './tools/build-and-test'"

tools/generate-files

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@
1010

1111
set -e
1212

13+
source tools/parse_args "$@"
14+
15+
if isHelp; then
16+
echo "usage: generate-files [-h | --help] [all | native | wasm | android | ios]"
17+
echo ""
18+
echo "Generate files and bindings for target platforms specified in arguments"
19+
echo "You can specify multiple targets at once"
20+
exit 0
21+
fi
22+
1323
# This script works in both Docker and normal build environments.
1424
# Protobuf and co. tools are taken from: $PREFIX if provided, or from $PWD/build/local if exists, or from /usr/bin
1525
if [ -z $PREFIX ]
@@ -53,15 +63,11 @@ codegen/bin/codegen
5363
tools/doxygen_convert_comments
5464

5565
# Generate rust bindgen
56-
tools/rust-bindgen $1
66+
tools/rust-bindgen "$@"
5767

5868
# Generate Java, C++ and Swift Protobuf files
59-
IOS="false"
60-
if [[ "$1" == "ios" ]] || [[ "$1" == "" ]]; then
61-
IOS="true"
62-
fi
6369

64-
if [ -x "$(command -v protoc-gen-swift)" ] && [[ "$IOS" == "true" ]]; then
70+
if [ -x "$(command -v protoc-gen-swift)" ] && isTargetSpecified "ios"; then
6571
"$PROTOC" -I=$PREFIX/include -I=src/proto --cpp_out=src/proto --java_out=lite:jni/proto --swift_out=swift/Sources/Generated/Protobuf --swift_opt=Visibility=Public src/proto/*.proto
6672
else
6773
"$PROTOC" -I=$PREFIX/include -I=src/proto --cpp_out=src/proto --java_out=lite:jni/proto src/proto/*.proto
@@ -78,14 +84,13 @@ fi
7884
"$PROTOC" -I=$PREFIX/include -I=src/proto --plugin=$PREFIX/bin/protoc-gen-swift-typealias --swift-typealias_out swift/Sources/Generated/Protobuf src/proto/*.proto
7985

8086
# Generate Xcode project
81-
if [ -x "$(command -v xcodegen)" ] && [[ "$IOS" == "true" ]]; then
87+
if [ -x "$(command -v xcodegen)" ] && isTargetSpecified "ios"; then
8288
pushd swift
8389
xcodegen
8490
pod install
8591
popd
86-
elif [ "$1" == "android" ]; then
87-
echo -e "\nWARNING: Android detected, skipping xcodegen generation"
88-
else
92+
elif isTargetSpecified "ios"; then
8993
echo -e "\nWARNING: Skipped generating Xcode project because the xcodegen tool is not installed."
94+
else
95+
echo -e "\nWARNING: skipping xcodegen generation"
9096
fi
91-

tools/install-sys-dependencies-mac

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
set -e
44

5-
# A workaround for "The `brew link` step did not complete successfully" error.
6-
brew install python@3 || brew link --overwrite python@3
7-
brew install boost ninja xcodegen xcbeautify
5+
brew install cmake boost ninja xcodegen xcbeautify
6+
7+
if [[ "$BOOST_ROOT" == "" ]]; then
8+
echo "export BOOST_ROOT=$(brew --prefix boost)" >> ~/.zprofile
9+
fi
810

911
if command -v rustup &> /dev/null
1012
then

tools/parse_args

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/bash
2+
3+
# Save the arguments on the first `source ./tools/parse_args "$@"` call.
4+
ARGS=("$@")
5+
6+
function containsArg() {
7+
for arg in "${ARGS[@]}"; do
8+
if [[ "$arg" == "$1" ]]; then
9+
return 0
10+
fi
11+
done
12+
return 1
13+
}
14+
15+
function isHelp() {
16+
if containsArg "--help" || containsArg "-h"; then
17+
return 0
18+
fi
19+
return 1
20+
}
21+
22+
function noArgs() {
23+
if [[ "${#ARGS}" -eq 0 ]]; then
24+
return 0
25+
fi
26+
return 1
27+
}
28+
29+
# Whether the command line arguments contain a target.
30+
# Returns `true` if either no arguments are specified, or `all`, or the exact target specified.
31+
function isTargetSpecified() {
32+
if noArgs || containsArg "all" || containsArg "$1"; then
33+
return 0
34+
fi
35+
return 1
36+
}

tools/rust-bindgen

Lines changed: 16 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,17 @@
22

33
set -e
44

5+
source "$(dirname $0)/parse_args" "$@"
56
source "$(dirname $0)/android-sdk"
67

8+
if isHelp; then
9+
echo "usage: rust-bindgen [-h | --help] [all | native | wasm | android | ios]"
10+
echo ""
11+
echo "Generate Rust bindings for target platforms specified in arguments"
12+
echo "You can specify multiple targets at once"
13+
exit 0
14+
fi
15+
716
TARGET_NAME="libwallet_core_rs.a"
817
TARGET_XCFRAMEWORK_NAME=../swift/WalletCoreRs.xcframework
918
BUILD_FOLDER=../rust/target
@@ -19,47 +28,21 @@ create_xc_framework() {
1928

2029
cd rust
2130

22-
NATIVE="false"
23-
ANDROID="false"
24-
IOS="false"
25-
WASM="false"
26-
27-
# Whether to generate bindings for native platform.
28-
if [[ "$1" == "native" ]] || [[ "$1" == "" ]]; then
29-
NATIVE="true"
30-
fi
31-
32-
# Whether to generate bindings for Android.
33-
if [[ "$1" == "android" ]] || [[ "$1" == "" ]]; then
34-
ANDROID="true"
35-
fi
36-
37-
# Generate bindings for ios platforms on MacOS only.
38-
if [[ `uname` == "Darwin" ]]; then
39-
# Whether to generate bindings for iOS.
40-
if [[ "$1" == "ios" ]] || [[ "$1" == "" ]]; then
41-
IOS="true"
42-
fi
43-
fi
44-
45-
# Whether to generate bindings for WASM.
46-
if [[ "$1" == "wasm" ]] || [[ "$1" == "" ]]; then
47-
WASM="true"
48-
fi
49-
50-
if [[ "$NATIVE" == "true" ]]; then
31+
if isTargetSpecified "native"; then
5132
echo "Generating Native target"
5233
cargo build --release --lib
5334
fi
5435

5536
export RUSTFLAGS="-Zlocation-detail=none"
5637

57-
if [[ "$WASM" == "true" ]]; then
38+
if isTargetSpecified "wasm"; then
5839
echo "Generating WASM target"
40+
41+
source ../emsdk/emsdk_env.sh
5942
cargo build -Z build-std=std,panic_abort --target wasm32-unknown-emscripten --release --lib
6043
fi
6144

62-
if [[ "$ANDROID" == "true" ]]; then
45+
if isTargetSpecified "android"; then
6346
NDK_BIN_PATH=$(find_android_ndk)
6447

6548
export AR="$NDK_BIN_PATH/llvm-ar"
@@ -72,7 +55,7 @@ if [[ "$ANDROID" == "true" ]]; then
7255
cargo build -Z build-std=std,panic_abort --target aarch64-linux-android --target armv7-linux-androideabi --target x86_64-linux-android --target i686-linux-android --release --lib
7356
fi
7457

75-
if [[ "$IOS" == "true" ]]; then
58+
if isTargetSpecified "ios" && [[ $(uname) == "Darwin" ]]; then
7659
echo "Generating iOS targets"
7760
cargo build -Z build-std=std,panic_abort --target aarch64-apple-ios --target aarch64-apple-ios-sim --target x86_64-apple-ios --target aarch64-apple-darwin --target x86_64-apple-darwin --target aarch64-apple-ios-macabi --target x86_64-apple-ios-macabi --release --lib &
7861
wait
@@ -89,7 +72,7 @@ cbindgen --crate $CRATE --output ../src/rust/bindgen/$HEADER_NAME
8972
cd -
9073
[[ -e rust/target/release/${TARGET_NAME} ]] && cp rust/target/release/${TARGET_NAME} build/local/lib/
9174

92-
if [[ "$IOS" == "true" ]]; then
75+
if isTargetSpecified "ios" && [[ $(uname) == "Darwin" ]]; then
9376
cd rust
9477
cat > $TARGET_XCFRAMEWORK_NAME/Info.plist << EOF
9578
<?xml version="1.0" encoding="UTF-8"?>

0 commit comments

Comments
 (0)