Skip to content

Commit

Permalink
Merge branch 'master' into s/bitcoin-cash-v2
Browse files Browse the repository at this point in the history
  • Loading branch information
satoshiotomakan committed Oct 3, 2024
2 parents 44fd42b + b4221b4 commit 0793589
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 51 deletions.
42 changes: 38 additions & 4 deletions bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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'"
27 changes: 16 additions & 11 deletions tools/generate-files
Original file line number Diff line number Diff line change
Expand Up @@ -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 ]
Expand Down Expand Up @@ -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
Expand All @@ -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

8 changes: 5 additions & 3 deletions tools/install-sys-dependencies-mac
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 36 additions & 0 deletions tools/parse_args
Original file line number Diff line number Diff line change
@@ -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
}
49 changes: 16 additions & 33 deletions tools/rust-bindgen
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand All @@ -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
Expand All @@ -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
<?xml version="1.0" encoding="UTF-8"?>
Expand Down

0 comments on commit 0793589

Please sign in to comment.