Skip to content

Commit

Permalink
Merge pull request LedgerHQ#35 from KhalilBellakrid/develop
Browse files Browse the repository at this point in the history
Fixes and preparing mobile integration
  • Loading branch information
KhalilBellakrid authored Oct 26, 2018
2 parents 8e6ae01 + 3fc6577 commit 28e3294
Show file tree
Hide file tree
Showing 41 changed files with 641 additions and 136 deletions.
92 changes: 91 additions & 1 deletion .circleci/build_lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

BUILD_CONFIG="Debug"
cmake_params="" # All params passed to cmake to generate build files
export ARCH=$2

###
# Commands of the script. Put them in command line parameters to trigger
Expand All @@ -20,6 +21,55 @@ function command_Release {
add_to_cmake_params -DBUILD_TESTS=OFF
}

function command_Debug {
BUILD_CONFIG="Debug"
add_to_cmake_params -DBUILD_TESTS=ON
}

function command_ios {
export POLLY_IOS_BUNDLE_IDENTIFIER='com.ledger.core'
#Needed for nocodesign toolchains
export XCODE_XCCONFIG_FILE=$POLLY_ROOT/scripts/NoCodeSign.xcconfig
echo "command_ios with architecture : $ARCH"
if [ "$ARCH" == "armv7" ]; then
export TOOLCHAIN_NAME='ios-nocodesign-11-2-dep-9-3-armv7'
export OSX_SYSROOT=iphoneos
elif [ "$ARCH" == "arm64" ]; then
export TOOLCHAIN_NAME='ios-nocodesign-11-2-dep-9-3-arm64'
export OSX_SYSROOT=iphoneos
else
export TOOLCHAIN_NAME='ios-nocodesign-11-2-dep-9-3'
export OSX_SYSROOT=iphonesimulator
export ARCH=x86_64
#Copy iphone.cmake which is not forcing CMAKE_OSX_SYSROOT to iphoneos in cache
cp `pwd`/../lib-ledger-core/tools/build_ios/iphone.cmake `pwd`/../lib-ledger-core/toolchains/polly/os/
fi

cp `pwd`/../lib-ledger-core/tools/build_ios/framework.plist.in `pwd`
cp `pwd`/../lib-ledger-core/tools/build_ios/install_name.sh `pwd`


BUILD_CONFIG="Release"
add_to_cmake_params -G "Xcode" -DCMAKE_BUILD_TYPE:STRING=Release -DBUILD_TESTS=OFF -DCMAKE_OSX_ARCHITECTURES:STRING=${ARCH} -DCMAKE_MACOSX_BUNDLE:BOOL=ON -DCMAKE_OSX_SYSROOT:STRING=${OSX_SYSROOT} -DCMAKE_TOOLCHAIN_FILE=${POLLY_ROOT}/${TOOLCHAIN_NAME}.cmake
}

function command_android {
echo "Set Android NDK variable"
export ANDROID_NDK_r16b=/home/circleci/android-ndk-r16b
export JAVA_HOME="$(/usr/libexec/java_home -v 1.8)" || export JAVA_HOME="/usr/lib/jvm/java-11-openjdk-amd64/"
#Needed for nocodesign toolchains
echo "command_android with architecture : $ARCH"
if [ "$ARCH" == "armeabi-v7a" ]; then
export TOOLCHAIN_NAME='android-ndk-r16b-api-21-armeabi-v7a-clang-libcxx14'
elif [ "$ARCH" == "arm64-v8a" ]; then
export TOOLCHAIN_NAME='android-ndk-r16b-api-24-arm64-v8a-clang-libcxx14'
else
export TOOLCHAIN_NAME='android-ndk-r16b-api-16-x86-clang-libcxx14'
fi
BUILD_CONFIG="Release"
add_to_cmake_params -DCMAKE_BUILD_TYPE:STRING=Release -DBUILD_TESTS=OFF -DTARGET_JNI=ON -DCMAKE_TOOLCHAIN_FILE=${POLLY_ROOT}/${TOOLCHAIN_NAME}.cmake
}

###
# Utilities functions
###
Expand All @@ -32,14 +82,30 @@ function add_to_cmake_params {
}

function execute_commands {
if [ "$1" == "ios" -o "$1" == "android" ]; then
command_$1
else
local cmd
for cmd;do
echo $cmd
command_$cmd
done
fi

}

export JAVA_HOME="/usr/lib/jvm/java-8-openjdk"
export POLLY_ROOT=`pwd`/toolchains/polly
###
# Clean
###
if [ "$1" == "ios" -o "$1" == "android" ]; then
echo "=====>Cleaning to prepare clean build"
echo "=====>Cleaning secp256k1"
rm -rf core/lib/secp256k1/include core/lib/secp256k1/src core/lib/secp256k1/tmp core/lib/secp256k1/lib || echo "Failed to clean secp256k1"
echo "=====>Remove build directory"
rm -rf ../lib-ledger-core-build
fi

echo "=====>Create build directory"
cd .. && (mkdir lib-ledger-core-build || echo "lib-ledger-core-build directory already exists") && cd lib-ledger-core-build
Expand All @@ -66,4 +132,28 @@ fi
echo $cmake_params
cmake $cmake_params ../lib-ledger-core
echo "======> Build for $unamestr in $BUILD_CONFIG mode"
make -j4
if [ "$1" == "ios" ]; then
echo " >>> Starting iOS build for architecture ${ARCH} with toolchain ${TOOLCHAIN_NAME} for ${OSX_SYSROOT}"
xcodebuild -project ledger-core.xcodeproj -configuration Release -jobs 4
else
make -j4
fi

if [ "$1" == "ios" ]; then
if [ "$ARCH" == "armv7" -o "$ARCH" == "arm64" ]; then
PATH_TO_LIB=core/src/Release-iphoneos
else
PATH_TO_LIB=core/src/Release-iphonesimulator
#Remove signature
rm -rf $PATH_TO_LIB/ledger-core.framework/_CodeSignature
codesign --remove-signature $PATH_TO_LIB/ledger-core.framework/ledger-core
fi

#echo "======> Set rpath"
#install_name_tool -id "@rpath/libledger-core.dylib" $PATH_TO_LIB/libledger-core.dylib
#install_name_tool -add_rpath "@executable_path/Frameworks" $PATH_TO_LIB/libledger-core.dylib

echo "======> Store artifacts to build fat framework"
mkdir -p /Users/distiller/ios/$ARCH && cp -r $PATH_TO_LIB/ledger-core.framework /Users/distiller/ios/$ARCH
fi

61 changes: 59 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,40 @@ jobs:
command: |
. .circleci/build_lib.sh target_jni Release
- deploy:
requires:
- hold
name: Deploy_jni
command: |
. .circleci/deploy.sh target_jni
- run:
name: Setup NDK
command: |
apt-get install -y zip unzip
wget --quiet https://dl.google.com/android/repository/android-ndk-r16b-linux-x86_64.zip
unzip -q android-ndk-r16b-linux-x86_64.zip -d /home/circleci
ls -la /home/circleci/android-ndk-r16b
- run:
name: Build_Library_android
command: |
. .circleci/build_lib.sh android
- deploy:
name: Deploy_android
command: |
. .circleci/deploy.sh android
- run:
name: Build_Library_android_armeabi-v7a
command: |
. .circleci/build_lib.sh android armeabi-v7a
- deploy:
name: Deploy_android_armeabi-v7a
command: |
. .circleci/deploy.sh android armeabi-v7a
- run:
name: Build_Library_android_arm64-v8a
command: |
. .circleci/build_lib.sh android arm64-v8a
- deploy:
name: Deploy_android_arm64-v8a
command: |
. .circleci/deploy.sh android arm64-v8a
build_linux_debug:
docker:
- image: debian:stretch
Expand Down Expand Up @@ -119,6 +148,34 @@ jobs:
name: Deploy_jni
command: |
. .circleci/deploy.sh target_jni
- run:
name: Build_Library_ios_x86
command: |
. .circleci/build_lib.sh ios
- deploy:
name: Deploy_ios_x86
command: |
. .circleci/deploy.sh ios
- run:
name: Build_Library_ios_armv7
command: |
. .circleci/build_lib.sh ios armv7
- deploy:
name: Deploy_ios_armv7
command: |
. .circleci/deploy.sh ios armv7
- run:
name: Build_Library_ios_arm64
command: |
. .circleci/build_lib.sh ios arm64
- deploy:
name: Deploy_ios_arm64
command: |
. .circleci/deploy.sh ios arm64
- run:
name: Build_Fat_Library_ios
command: |
. .circleci/deploy_fat_lib.sh
build_macos_debug:
macos:
xcode: "9.2.0"
Expand Down
24 changes: 21 additions & 3 deletions .circleci/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@

unamestr=$(uname)
TARGET=$1
#branchstr=`git rev-parse --abbrev-ref HEAD`
ARCH=$2
branchstr=$(git branch | grep '*' | sed 's/^..//')

echo "======> Deploy from $branchstr branch, version : $LIB_VERSION"

if [ "$branchstr" == "develop" -o "$branchstr" == "jni-ci" ]; then
if [ "$branchstr" == "develop" ]; then
echo "======> Start deploy for $unamestr"
if [ "$unamestr" == "Linux" ]; then
if [ "$TARGET" == "target_jni" ]; then
mv ../lib-ledger-core-build/core/src/libledger-core.so ../lib-ledger-core-build/core/src/libledger-core_jni.so
export BUILD_TYPE=linux/jni
elif [ "$TARGET" == "android" ]; then
export BUILD_TYPE=android/${ARCH}
else
export BUILD_TYPE=linux
fi
Expand All @@ -25,8 +27,24 @@ if [ "$branchstr" == "develop" -o "$branchstr" == "jni-ci" ]; then
fi
fi

PATH_TO_LIB=../lib-ledger-core-build/core/src/
if [ "$TARGET" == "ios" ]; then
if [ "$ARCH" == "armv7" -o "$ARCH" == "arm64" ]; then
export BUILD_TYPE=ios/${ARCH}
PATH_TO_LIB=../lib-ledger-core-build/core/src/Release-iphoneos
else
export BUILD_TYPE=ios/x86_64
PATH_TO_LIB=../lib-ledger-core-build/core/src/Release-iphonesimulator
fi
elif [ "$TARGET" == "android" ]; then
if [ "$ARCH" == "armeabi-v7a" -o "$ARCH" == "arm64-v8a" ]; then
export BUILD_TYPE=android/${ARCH}
else
export BUILD_TYPE=android/x86
fi
fi
echo "======> Deploy for $unamestr"
aws s3 sync ../lib-ledger-core-build/core/src/ s3://ledger-lib-ledger-core/$LIB_VERSION/$BUILD_TYPE --acl public-read --exclude "CMakeFiles/*" --exclude "Makefile" --exclude "cmake_install.cmake" && \
aws s3 sync $PATH_TO_LIB s3://ledger-lib-ledger-core/$LIB_VERSION/$BUILD_TYPE --acl public-read --exclude "CMakeFiles/*" --exclude "Makefile" --exclude "cmake_install.cmake" && \
aws s3 ls s3://ledger-lib-ledger-core/$LIB_VERSION/$BUILD_TYPE;

else
Expand Down
28 changes: 28 additions & 0 deletions .circleci/deploy_fat_lib.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env bash

unamestr=$(uname)
branchstr=$(git branch | grep '*' | sed 's/^..//')

cd /Users/distiller/ios

echo "======> Build Fat Library"
pwd

#We don't put x86_64/ledger-core.framework/ledger-core otherwise we have a problem when pushing to AppStore
lipo -create armv7/ledger-core.framework/ledger-core arm64/ledger-core.framework/ledger-core -o ledger-core
mkdir ledger-core.framework
mv ledger-core ledger-core.framework/
cp arm64/ledger-core.framework/Info.plist ledger-core.framework/
install_name_tool -add_rpath "@executable_path/Frameworks/universal" ledger-core.framework/ledger-core
lipo -info ledger-core.framework/ledger-core

echo "======> Deploy from $branchstr branch, version : $LIB_VERSION"

if [ "$branchstr" == "develop" ]; then
echo "======> Start deploy fat library for $unamestr"
aws s3 sync ./ s3://ledger-lib-ledger-core/$LIB_VERSION/ios/universal --acl public-read --exclude "x86_64/*" --exclude "armv7/*" --exclude "arm64/*" && \
aws s3 ls s3://ledger-lib-ledger-core/$LIB_VERSION/ios/universal;

else
echo "======> Deployment only on Develop (temporary) branch"
fi
2 changes: 1 addition & 1 deletion .circleci/init_submodules.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ git submodule sync
echo "========> Update all submodules "
#No need for those
#git submodule update -- djinni || echo "===========Djinni submodule already updated"
#git submodule update -- toolchains/polly || echo "===========Polly submodule already updated"
git submodule update -- toolchains/polly || echo "===========Polly submodule already updated"
#git submodule update -- tools/gyp || echo "===========gyp submodule already updated"
git submodule update -- core/lib/spdlog || echo "===========spdlog submodule already updated"
git submodule update -- core/lib/leveldb || echo "===========leveldb submodule already updated"
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ include(UseBackportedModules)
# The project version number.
set(VERSION_MAJOR 1 CACHE STRING "Project major version number.")
set(VERSION_MINOR 1 CACHE STRING "Project minor version number.")
set(VERSION_PATCH 0 CACHE STRING "Project patch version number.")
set(VERSION_PATCH 3 CACHE STRING "Project patch version number.")
mark_as_advanced(VERSION_MAJOR VERSION_MINOR VERSION_PATCH)

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY build)
Expand Down
6 changes: 5 additions & 1 deletion api/core/java/BitcoinLikeTransactionBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,11 @@ public abstract class BitcoinLikeTransactionBuilder {
/** Reset the current instance to its initial state */
public abstract void reset();

public static native BitcoinLikeTransaction parseRawUnsignedTransaction(Currency currency, byte[] rawTransaction);
/**
* Parsing unsigned transaction
* parsing a tx might change depending on block height we are on (if an update is effective starting from a given hight)
*/
public static native BitcoinLikeTransaction parseRawUnsignedTransaction(Currency currency, byte[] rawTransaction, Integer currentBlockHeight);

private static final class CppProxy extends BitcoinLikeTransactionBuilder
{
Expand Down
19 changes: 13 additions & 6 deletions api/core/nodejs/NJSBitcoinLikeTransactionBuilderCpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -455,9 +455,9 @@ NAN_METHOD(NJSBitcoinLikeTransactionBuilder::reset) {
NAN_METHOD(NJSBitcoinLikeTransactionBuilder::parseRawUnsignedTransaction) {

//Check if method called with right number of arguments
if(info.Length() != 2)
if(info.Length() != 3)
{
return Nan::ThrowError("NJSBitcoinLikeTransactionBuilder::parseRawUnsignedTransaction needs 2 arguments");
return Nan::ThrowError("NJSBitcoinLikeTransactionBuilder::parseRawUnsignedTransaction needs 3 arguments");
}

//Check if parameters have correct types
Expand Down Expand Up @@ -613,16 +613,23 @@ NAN_METHOD(NJSBitcoinLikeTransactionBuilder::parseRawUnsignedTransaction) {
}
}

auto arg_2 = std::experimental::optional<int32_t>();
if(!info[2]->IsNull())
{
auto opt_arg_2 = Nan::To<int32_t>(info[2]).FromJust();
arg_2.emplace(opt_arg_2);
}

auto result = BitcoinLikeTransactionBuilder::parseRawUnsignedTransaction(arg_0,arg_1);

auto result = BitcoinLikeTransactionBuilder::parseRawUnsignedTransaction(arg_0,arg_1,arg_2);

//Wrap result in node object
auto arg_2_wrap = NJSBitcoinLikeTransaction::wrap(result);
auto arg_2 = Nan::ObjectWrap::Unwrap<NJSBitcoinLikeTransaction>(arg_2_wrap)->handle();
auto arg_3_wrap = NJSBitcoinLikeTransaction::wrap(result);
auto arg_3 = Nan::ObjectWrap::Unwrap<NJSBitcoinLikeTransaction>(arg_3_wrap)->handle();


//Return result
info.GetReturnValue().Set(arg_2);
info.GetReturnValue().Set(arg_3);
}

NAN_METHOD(NJSBitcoinLikeTransactionBuilder::New) {
Expand Down
5 changes: 5 additions & 0 deletions api/core/nodejs/NJSBitcoinLikeTransactionBuilderCpp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#define DJINNI_GENERATED_NJSBITCOINLIKETRANSACTIONBUILDER_HPP


#include "../../../core/src/api/../utils/optional.hpp"
#include "../../../core/src/api/BitcoinLikeNetworkParameters.hpp"
#include "../../../core/src/api/BitcoinLikePickingStrategy.hpp"
#include "../../../core/src/api/Currency.hpp"
Expand Down Expand Up @@ -126,6 +127,10 @@ class NJSBitcoinLikeTransactionBuilder: public Nan::ObjectWrap {
/** Reset the current instance to its initial state */
static NAN_METHOD(reset);

/**
* Parsing unsigned transaction
* parsing a tx might change depending on block height we are on (if an update is effective starting from a given hight)
*/
static NAN_METHOD(parseRawUnsignedTransaction);

static NAN_METHOD(New);
Expand Down
6 changes: 5 additions & 1 deletion api/core/nodejs/ledgerapp_nodejs_doc.js
Original file line number Diff line number Diff line change
Expand Up @@ -1707,7 +1707,11 @@ declare class NJSBitcoinLikeTransactionBuilder
declare function clone(): NJSBitcoinLikeTransactionBuilder;
/** Reset the current instance to its initial state */
declare function reset();
static declare function parseRawUnsignedTransaction(currency: Currency, rawTransaction: Object): NJSBitcoinLikeTransaction;
/**
* Parsing unsigned transaction
* parsing a tx might change depending on block height we are on (if an update is effective starting from a given hight)
*/
static declare function parseRawUnsignedTransaction(currency: Currency, rawTransaction: Object, currentBlockHeight: ?number): NJSBitcoinLikeTransaction;
}
/**
*Callback triggered by main completed task,
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ branches:
image:
- Visual Studio 2015
environment:
LIB_VERSION: 1.1.0 #Hardcode the LIB_VERSION : should be retrieved by building libcore node module and run tests/lib_version.js
LIB_VERSION: 1.1.3 #Hardcode the LIB_VERSION : should be retrieved by building libcore node module and run tests/lib_version.js
nodejs_version: "9"
appveyor_rdp_password:
secure: jb1LsDmcxCww7tA38S3xSw==
Expand Down
Loading

0 comments on commit 28e3294

Please sign in to comment.