diff --git a/bootstrap.sh b/bootstrap.sh index cdb20a25993..520bedf90dd 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -5,9 +5,43 @@ # Fail if any commands fails set -e -echo "#### Initializing workspace with dependencies ... ####" +source tools/parse_args "$@" + +if isHelp; then + echo "usage: bootstrap.sh [-h | --help] [all | wasm | android | ios]" + echo "" + echo "Installs dependencies and prepares WalletCore for building" + exit 0 +fi + +echo "#### Installing system dependencies ... ####" +if [[ $(uname) == "Darwin" ]]; then + tools/install-sys-dependencies-macos +else + tools/install-sys-dependencies-linux +fi + +echo "#### Installing C++ libraries ... ####" tools/install-dependencies -tools/install-rust-dependencies -echo "#### Building and running tests ... ####" -tools/build-and-test +echo "#### Installing Rust toolchain and tools ... ####" +tools/install-rust-dependencies dev + +# WASM +if isTargetSpecified "wasm"; then + echo "#### Installing WASM environment ... ####" + tools/install-wasm-dependencies +fi + +# Android +if isTargetSpecified "android"; then + echo "#### Installing Android dependencies ... ####" + tools/install-android-dependencies +fi + +echo "#### Generating files... ####" +tools/generate-files "$@" + +echo "" +echo "WalletCore is ready for development!" +echo "Consider running native C++ tests via './tools/build-and-test'" diff --git a/tools/generate-files b/tools/generate-files index bd0fb1638c0..de3abc7f906 100755 --- a/tools/generate-files +++ b/tools/generate-files @@ -10,6 +10,16 @@ set -e +source tools/parse_args "$@" + +if isHelp; then + echo "usage: generate-files [-h | --help] [all | native | wasm | android | ios]" + echo "" + echo "Generate files and bindings for target platforms specified in arguments" + echo "You can specify multiple targets at once" + exit 0 +fi + # This script works in both Docker and normal build environments. # Protobuf and co. tools are taken from: $PREFIX if provided, or from $PWD/build/local if exists, or from /usr/bin if [ -z $PREFIX ] @@ -53,15 +63,11 @@ codegen/bin/codegen tools/doxygen_convert_comments # Generate rust bindgen -tools/rust-bindgen $1 +tools/rust-bindgen "$@" # Generate Java, C++ and Swift Protobuf files -IOS="false" -if [[ "$1" == "ios" ]] || [[ "$1" == "" ]]; then - IOS="true" -fi -if [ -x "$(command -v protoc-gen-swift)" ] && [[ "$IOS" == "true" ]]; then +if [ -x "$(command -v protoc-gen-swift)" ] && isTargetSpecified "ios"; then "$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 else "$PROTOC" -I=$PREFIX/include -I=src/proto --cpp_out=src/proto --java_out=lite:jni/proto src/proto/*.proto @@ -78,14 +84,13 @@ fi "$PROTOC" -I=$PREFIX/include -I=src/proto --plugin=$PREFIX/bin/protoc-gen-swift-typealias --swift-typealias_out swift/Sources/Generated/Protobuf src/proto/*.proto # Generate Xcode project -if [ -x "$(command -v xcodegen)" ] && [[ "$IOS" == "true" ]]; then +if [ -x "$(command -v xcodegen)" ] && isTargetSpecified "ios"; then pushd swift xcodegen pod install popd -elif [ "$1" == "android" ]; then - echo -e "\nWARNING: Android detected, skipping xcodegen generation" -else +elif isTargetSpecified "ios"; then echo -e "\nWARNING: Skipped generating Xcode project because the xcodegen tool is not installed." +else + echo -e "\nWARNING: skipping xcodegen generation" fi - diff --git a/tools/install-sys-dependencies-mac b/tools/install-sys-dependencies-mac index c01bd2cde28..28dc34cb356 100755 --- a/tools/install-sys-dependencies-mac +++ b/tools/install-sys-dependencies-mac @@ -2,9 +2,11 @@ set -e -# A workaround for "The `brew link` step did not complete successfully" error. -brew install python@3 || brew link --overwrite python@3 -brew install boost ninja xcodegen xcbeautify +brew install cmake boost ninja xcodegen xcbeautify + +if [[ "$BOOST_ROOT" == "" ]]; then + echo "export BOOST_ROOT=$(brew --prefix boost)" >> ~/.zprofile +fi if command -v rustup &> /dev/null then diff --git a/tools/parse_args b/tools/parse_args new file mode 100755 index 00000000000..3868fe56077 --- /dev/null +++ b/tools/parse_args @@ -0,0 +1,36 @@ +#!/bin/bash + +# Save the arguments on the first `source ./tools/parse_args "$@"` call. +ARGS=("$@") + +function containsArg() { + for arg in "${ARGS[@]}"; do + if [[ "$arg" == "$1" ]]; then + return 0 + fi + done + return 1 +} + +function isHelp() { + if containsArg "--help" || containsArg "-h"; then + return 0 + fi + return 1 +} + +function noArgs() { + if [[ "${#ARGS}" -eq 0 ]]; then + return 0 + fi + return 1 +} + +# Whether the command line arguments contain a target. +# Returns `true` if either no arguments are specified, or `all`, or the exact target specified. +function isTargetSpecified() { + if noArgs || containsArg "all" || containsArg "$1"; then + return 0 + fi + return 1 +} diff --git a/tools/rust-bindgen b/tools/rust-bindgen index 0ca640b7766..0edaf9c23a5 100755 --- a/tools/rust-bindgen +++ b/tools/rust-bindgen @@ -2,8 +2,17 @@ set -e +source "$(dirname $0)/parse_args" "$@" source "$(dirname $0)/android-sdk" +if isHelp; then + echo "usage: rust-bindgen [-h | --help] [all | native | wasm | android | ios]" + echo "" + echo "Generate Rust bindings for target platforms specified in arguments" + echo "You can specify multiple targets at once" + exit 0 +fi + TARGET_NAME="libwallet_core_rs.a" TARGET_XCFRAMEWORK_NAME=../swift/WalletCoreRs.xcframework BUILD_FOLDER=../rust/target @@ -19,47 +28,21 @@ create_xc_framework() { cd rust -NATIVE="false" -ANDROID="false" -IOS="false" -WASM="false" - -# Whether to generate bindings for native platform. -if [[ "$1" == "native" ]] || [[ "$1" == "" ]]; then - NATIVE="true" -fi - -# Whether to generate bindings for Android. - if [[ "$1" == "android" ]] || [[ "$1" == "" ]]; then - ANDROID="true" - fi - -# Generate bindings for ios platforms on MacOS only. -if [[ `uname` == "Darwin" ]]; then -# Whether to generate bindings for iOS. - if [[ "$1" == "ios" ]] || [[ "$1" == "" ]]; then - IOS="true" - fi -fi - -# Whether to generate bindings for WASM. -if [[ "$1" == "wasm" ]] || [[ "$1" == "" ]]; then - WASM="true" -fi - -if [[ "$NATIVE" == "true" ]]; then +if isTargetSpecified "native"; then echo "Generating Native target" cargo build --release --lib fi export RUSTFLAGS="-Zlocation-detail=none" -if [[ "$WASM" == "true" ]]; then +if isTargetSpecified "wasm"; then echo "Generating WASM target" + + source ../emsdk/emsdk_env.sh cargo build -Z build-std=std,panic_abort --target wasm32-unknown-emscripten --release --lib fi -if [[ "$ANDROID" == "true" ]]; then +if isTargetSpecified "android"; then NDK_BIN_PATH=$(find_android_ndk) export AR="$NDK_BIN_PATH/llvm-ar" @@ -72,7 +55,7 @@ if [[ "$ANDROID" == "true" ]]; then 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 fi -if [[ "$IOS" == "true" ]]; then +if isTargetSpecified "ios" && [[ $(uname) == "Darwin" ]]; then echo "Generating iOS targets" 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 & wait @@ -89,7 +72,7 @@ cbindgen --crate $CRATE --output ../src/rust/bindgen/$HEADER_NAME cd - [[ -e rust/target/release/${TARGET_NAME} ]] && cp rust/target/release/${TARGET_NAME} build/local/lib/ -if [[ "$IOS" == "true" ]]; then +if isTargetSpecified "ios" && [[ $(uname) == "Darwin" ]]; then cd rust cat > $TARGET_XCFRAMEWORK_NAME/Info.plist << EOF