Skip to content
This repository has been archived by the owner on Mar 7, 2023. It is now read-only.

Bundle JNI artifact into Nexus #5

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,24 @@ lib/protobuf
.history/

# Generated files
CMakeFiles
jni/cpp/generated
jni/java/wallet/core/jni
jni/.gradle
jni/*.iml
swift/Sources/Generated
swift/wallet-core/
src/Generated
include/TrustWalletCore/TWHRP.h
include/TrustWalletCore/TW*Proto.h
tests/googletest-build/googlemock/gtest/generated
Makefile
**Makefile
**.cmake
**.a
**.so
tests/tests
trezor-crypto/tests/TrezorCryptoTests

# Code coverage files
coverage.info
Expand All @@ -50,3 +61,6 @@ samples/cpp/Makefile
samples/cpp/*.cmake
# built binary
samples/cpp/sample
compile_commands.json
walletconsole/walletconsole
CMakeCache.txt
24 changes: 9 additions & 15 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,20 @@ include(ExternalProject)
# Dependencies
include(cmake/Protobuf.cmake)

option(CODE_COVERAGE "Enable coverage reporting" OFF)
if(CODE_COVERAGE AND CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -fprofile-arcs -ftest-coverage")
set(CMAKE_EXE_LINKER_FLAGS "-fprofile-arcs -ftest-coverage")
endif()

# Source files
if(${ANDROID})

find_package(Java REQUIRED)
find_package(JNI REQUIRED)
include(UseJava)
include_directories(${PREFIX}/include ${JNI_INCLUDE_DIRS} ${_classDir} ${_stubDir})

message("Configuring for JNI")
file(GLOB_RECURSE sources src/*.c src/*.cc src/*.cpp src/*.h jni/cpp/*.c jni/cpp/*.cpp jni/cpp/*.h jni/cpp/*.c)
add_library(TrustWalletCore SHARED ${sources} ${PROTO_SRCS} ${PROTO_HDRS})
add_library(TrustWalletCore MODULE ${sources} ${PROTO_SRCS} ${PROTO_HDRS})

find_library(log-lib log)
target_link_libraries(TrustWalletCore PRIVATE TrezorCrypto protobuf ${log-lib} Boost::boost)
#find_library(log-lib log)
target_link_libraries(TrustWalletCore TrezorCrypto protobuf ${JNI_INCLUDE_DIRS} Boost::boost)
else()
message("Configuring standalone")
file(GLOB_RECURSE sources src/*.c src/*.cc src/*.cpp src/*.h)
Expand Down Expand Up @@ -92,12 +92,6 @@ target_include_directories(TrustWalletCore
${CMAKE_CURRENT_SOURCE_DIR}/build/local/include
)

if(NOT ANDROID AND NOT IOS_PLATFORM AND NOT WASM)
add_subdirectory(tests)
add_subdirectory(walletconsole/lib)
add_subdirectory(walletconsole)
endif()

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/swift/cpp.xcconfig.in ${CMAKE_CURRENT_SOURCE_DIR}/swift/cpp.xcconfig @ONLY)

install(TARGETS TrustWalletCore
Expand Down
87 changes: 87 additions & 0 deletions docker/wallet-core/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
FROM ubuntu:18.04

ARG CLANG_VERSION=7.0.1
ARG CMAKE_VERSION=3.13.4
ARG PROTOBUF_VERSION=3.9.0

# Install some basics
RUN apt-get update \
&& apt-get install -y \
curl \
git \
nano \
unzip \
xz-utils \
&& apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

# Install required packages for dev
RUN apt-get update \
&& apt-get install -y \
autoconf \
build-essential \
libcurl4-openssl-dev \
libicu-dev \
libreadline-dev \
libssl-dev \
libtool \
ninja-build \
pkg-config \
ruby-full \
&& apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

# Install clang
ENV CLANG_VERSION=$CLANG_VERSION
RUN curl -fSsL http://releases.llvm.org/$CLANG_VERSION/clang+llvm-$CLANG_VERSION-x86_64-linux-gnu-ubuntu-18.04.tar.xz -o clang.tar.xz \
&& tar -xJf clang.tar.xz --directory /usr --strip-components=1 \
&& rm -rf clang.tar.xz

# Install Boost
RUN curl -fSsL https://dl.bintray.com/boostorg/release/1.66.0/source/boost_1_66_0.tar.gz -o boost.tar.gz \
&& tar xzf boost.tar.gz \
&& mv boost_1_66_0/boost /usr/include \
&& rm -rf boost*

# Install CMake, binaries from GitHub
ENV CMAKE_VERSION=$CMAKE_VERSION
RUN cd /usr/local/src \
&& curl -fSsOL https://github.com/Kitware/CMake/releases/download/v$CMAKE_VERSION/cmake-$CMAKE_VERSION-Linux-x86_64.tar.gz \
&& ls -l cmake-$CMAKE_VERSION-Linux-x86_64.tar.gz \
&& tar xf cmake-$CMAKE_VERSION-Linux-x86_64.tar.gz \
&& cd cmake-$CMAKE_VERSION-Linux-x86_64 \
&& cp -r bin /usr/ \
&& cp -r share /usr/ \
&& cp -r doc /usr/share/ \
&& cp -r man /usr/share/ \
&& cd .. \
&& rm -rf cmake*
RUN cmake --version

# Clone repo
ENV CC=/usr/bin/clang
ENV CXX=/usr/bin/clang++
RUN git clone https://github.com/blockchain/wallet-core.git

# Prepare dependencies
RUN cd /wallet-core \
&& export PREFIX=/usr/local \
&& tools/install-dependencies

# Clean Up
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

# Version checks
RUN ruby --version \
&& clang --version \
&& cmake --version \
&& protoc --version

# Build library: generate, cmake, and make
# rbenv trick is needed as Ruby is installed to non-standard location
RUN cd /wallet-core \
&& ./tools/generate-files \
&& cmake -H. -Bbuild -DCMAKE_BUILD_TYPE=Debug \
&& make -Cbuild -j12

RUN apt-get update && apt-get install -y default-jdk

CMD ["/bin/bash"]
81 changes: 81 additions & 0 deletions jni/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* This file was generated by the Gradle 'init' task.
*
* This generated file contains a sample Java Library project to get you started.
* For more details take a look at the Java Libraries chapter in the Gradle
* user guide available at https://docs.gradle.org/4.10.2/userguide/java_library_plugin.html
*/



plugins {
// Apply the java-library plugin to add support for Java Library
id 'java'
id 'java-library'
}

group 'com.blockchain'
version '1.0.3'

apply plugin: 'maven-publish'
apply plugin: 'maven'

dependencies {
// This dependency is exported to consumers, that is to say found on their compile classpath.
api 'org.apache.commons:commons-math3:3.6.1'

// This dependency is used internally, and not exposed to consumers on their own compile classpath.
implementation 'com.google.protobuf:protobuf-java:3.8.0'

// Use JUnit test framework
testImplementation 'junit:junit:4.12'
}

// In this section you declare where to find the dependencies of your project
repositories {
// Use jcenter for resolving your dependencies.
// You can declare any Maven/Ivy/file repository here.
jcenter()
}

sourceSets {
main.java.srcDirs = ['java']
main.resources.srcDirs = ['static']
}

task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}

task sourceJar(type: Jar, dependsOn: classes) {
classifier = 'sources'
from sourceSets.main.allSource
}


artifacts {
archives sourceJar
}

publishing {
publications {
mavenJava(MavenPublication) {
from components.java
artifact sourceJar {
classifier "sources"
}
}
}

repositories {
project.ext.set('repo', project.version.endsWith('-SNAPSHOT') ? 'snapshots' : 'releases')
maven {
url "${nexusUrl}/repository/maven-${project.repo}/"
credentials(PasswordCredentials) {
username nexusUsername
password nexusPassword
}
}
}
}
8 changes: 6 additions & 2 deletions jni/cpp/Random.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
// file LICENSE at the root of the source code distribution tree.

#include <jni.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>

static JavaVM* cachedJVM;
Expand All @@ -26,8 +28,10 @@ uint32_t random32() {
}

void random_buffer(uint8_t *buf, size_t len) {
JNIEnv *env;
cachedJVM->AttachCurrentThread(&env, NULL);
void *env_ptr;
cachedJVM->AttachCurrentThread(&env_ptr, NULL);

JNIEnv *env = (JNIEnv *) env_ptr;

// SecureRandom random = new SecureRandom();
jclass secureRandomClass = env->FindClass("java/security/SecureRandom");
Expand Down
Binary file added jni/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
5 changes: 5 additions & 0 deletions jni/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading