Build wallet with Android NDK

This commit is contained in:
MoroccanMalinois 2017-01-05 01:11:05 +00:00
parent dd580d7bc7
commit 80abc3bc4a
10 changed files with 103 additions and 8 deletions

View file

@ -375,6 +375,13 @@ else()
set(STATIC_ASSERT_FLAG "-Dstatic_assert=_Static_assert") set(STATIC_ASSERT_FLAG "-Dstatic_assert=_Static_assert")
endif() endif()
try_compile(STATIC_ASSERT_CPP_RES "${CMAKE_CURRENT_BINARY_DIR}/static-assert" "${CMAKE_CURRENT_SOURCE_DIR}/cmake/test-static-assert.cpp" COMPILE_DEFINITIONS "-std=c++11")
if(STATIC_ASSERT_CPP_RES)
set(STATIC_ASSERT_CPP_FLAG "")
else()
set(STATIC_ASSERT_CPP_FLAG "-Dstatic_assert=_Static_assert")
endif()
option(COVERAGE "Enable profiling for test coverage report" 0) option(COVERAGE "Enable profiling for test coverage report" 0)
if(COVERAGE) if(COVERAGE)
@ -410,7 +417,7 @@ else()
endif() endif()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11 -D_GNU_SOURCE ${MINGW_FLAG} ${STATIC_ASSERT_FLAG} ${WARNINGS} ${C_WARNINGS} ${ARCH_FLAG} ${COVERAGE_FLAGS} ${PIC_FLAG}") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11 -D_GNU_SOURCE ${MINGW_FLAG} ${STATIC_ASSERT_FLAG} ${WARNINGS} ${C_WARNINGS} ${ARCH_FLAG} ${COVERAGE_FLAGS} ${PIC_FLAG}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -D_GNU_SOURCE ${MINGW_FLAG} ${STATIC_ASSERT_FLAG} ${WARNINGS} ${CXX_WARNINGS} ${ARCH_FLAG} ${COVERAGE_FLAGS} ${PIC_FLAG}") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -D_GNU_SOURCE ${MINGW_FLAG} ${STATIC_ASSERT_CPP_FLAG} ${WARNINGS} ${CXX_WARNINGS} ${ARCH_FLAG} ${COVERAGE_FLAGS} ${PIC_FLAG}")
# With GCC 6.1.1 the compiled binary malfunctions due to aliasing. Until that # With GCC 6.1.1 the compiled binary malfunctions due to aliasing. Until that
# is fixed in the code (Issue #847), force compiler to be conservative. # is fixed in the code (Issue #847), force compiler to be conservative.
@ -494,6 +501,13 @@ else()
endif(ARM) endif(ARM)
if(ANDROID AND NOT BUILD_GUI_DEPS STREQUAL "ON")
#From Android 5: "only position independent executables (PIE) are supported"
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIE")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIE")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_CXX_FLAGS} -fPIE -pie")
endif()
if(APPLE) if(APPLE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DGTEST_HAS_TR1_TUPLE=0") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DGTEST_HAS_TR1_TUPLE=0")
endif() endif()
@ -580,7 +594,7 @@ endif()
include_directories(SYSTEM ${Boost_INCLUDE_DIRS}) include_directories(SYSTEM ${Boost_INCLUDE_DIRS})
if(MINGW) if(MINGW)
set(EXTRA_LIBRARIES mswsock;ws2_32;iphlpapi) set(EXTRA_LIBRARIES mswsock;ws2_32;iphlpapi)
elseif(APPLE OR FREEBSD OR OPENBSD) elseif(APPLE OR FREEBSD OR OPENBSD OR ANDROID)
set(EXTRA_LIBRARIES "") set(EXTRA_LIBRARIES "")
elseif(DRAGONFLY) elseif(DRAGONFLY)
find_library(COMPAT compat) find_library(COMPAT compat)

View file

@ -70,6 +70,10 @@ release-static-armv7:
mkdir -p build/release mkdir -p build/release
cd build/release && cmake -D BUILD_TESTS=OFF -D ARCH="armv7-a" -D STATIC=ON -D BUILD_64=OFF -D CMAKE_BUILD_TYPE=release ../.. && $(MAKE) cd build/release && cmake -D BUILD_TESTS=OFF -D ARCH="armv7-a" -D STATIC=ON -D BUILD_64=OFF -D CMAKE_BUILD_TYPE=release ../.. && $(MAKE)
release-static-android:
mkdir -p build/release
cd build/release && cmake -D BUILD_TESTS=OFF -D ARCH="armv7-a" -D STATIC=ON -D BUILD_64=OFF -D CMAKE_BUILD_TYPE=release -D ANDROID=true -D INSTALL_VENDORED_LIBUNBOUND=ON ../.. && $(MAKE)
release-static-armv8: release-static-armv8:
mkdir -p build/release mkdir -p build/release
cd build/release && cmake -D BUILD_TESTS=OFF -D ARCH="armv8-a" -D STATIC=ON -D BUILD_64=ON -D CMAKE_BUILD_TYPE=release ../.. && $(MAKE) cd build/release && cmake -D BUILD_TESTS=OFF -D ARCH="armv8-a" -D STATIC=ON -D BUILD_64=ON -D CMAKE_BUILD_TYPE=release ../.. && $(MAKE)

View file

@ -0,0 +1,34 @@
// Copyright (c) 2014-2016, The Monero Project
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification, are
// permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other
// materials provided with the distribution.
//
// 3. Neither the name of the copyright holder nor the names of its contributors may be
// used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <assert.h>
static_assert(1, "FAIL");
int main(int argc, char *argv[]) {
return 0;
}

View file

@ -133,7 +133,7 @@ namespace epee
bool wait_stdin_data() bool wait_stdin_data()
{ {
#if !defined(WIN32) #if !defined(WIN32)
#ifdef __OpenBSD__ #if defined(__OpenBSD__) || defined(__ANDROID__)
int stdin_fileno = fileno(stdin); int stdin_fileno = fileno(stdin);
#else #else
int stdin_fileno = ::fileno(stdin); int stdin_fileno = ::fileno(stdin);

View file

@ -30,6 +30,11 @@ if(FREEBSD)
add_definitions(-DMDB_DSYNC=O_SYNC) add_definitions(-DMDB_DSYNC=O_SYNC)
endif() endif()
if(ANDROID)
add_definitions("-DANDROID=1")
endif()
set (lmdb_sources set (lmdb_sources
mdb.c mdb.c
midl.c) midl.c)

View file

@ -30,7 +30,13 @@
#ifdef HAVE_SYS_SYSCTL_H #ifdef HAVE_SYS_SYSCTL_H
#include <sys/sysctl.h> #include <sys/sysctl.h>
#endif #endif
#ifdef __ANDROID__
#include <sys/vfs.h>
#define statvfs statfs
#define fstatvfs fstatfs
#else
#include <sys/statvfs.h> #include <sys/statvfs.h>
#endif
#include <sys/socket.h> #include <sys/socket.h>
#include <sys/mount.h> #include <sys/mount.h>
#include <sys/mman.h> #include <sys/mman.h>

View file

@ -36,6 +36,10 @@
#include <string.h> #include <string.h>
#include <sys/param.h> #include <sys/param.h>
#if defined(__ANDROID__)
#include <byteswap.h>
#endif
#if defined(_MSC_VER) #if defined(_MSC_VER)
#include <stdlib.h> #include <stdlib.h>
@ -138,16 +142,24 @@ static inline uint32_t ident32(uint32_t x) { return x; }
static inline uint64_t ident64(uint64_t x) { return x; } static inline uint64_t ident64(uint64_t x) { return x; }
#ifndef __OpenBSD__ #ifndef __OpenBSD__
# if defined(__ANDROID__) && defined(__swap32) && !defined(swap32)
# define swap32 __swap32
# elif !defined(swap32)
static inline uint32_t swap32(uint32_t x) { static inline uint32_t swap32(uint32_t x) {
x = ((x & 0x00ff00ff) << 8) | ((x & 0xff00ff00) >> 8); x = ((x & 0x00ff00ff) << 8) | ((x & 0xff00ff00) >> 8);
return (x << 16) | (x >> 16); return (x << 16) | (x >> 16);
} }
# endif
# if defined(__ANDROID__) && defined(__swap64) && !defined(swap64)
# define swap64 __swap64
# elif !defined(swap64)
static inline uint64_t swap64(uint64_t x) { static inline uint64_t swap64(uint64_t x) {
x = ((x & 0x00ff00ff00ff00ff) << 8) | ((x & 0xff00ff00ff00ff00) >> 8); x = ((x & 0x00ff00ff00ff00ff) << 8) | ((x & 0xff00ff00ff00ff00) >> 8);
x = ((x & 0x0000ffff0000ffff) << 16) | ((x & 0xffff0000ffff0000) >> 16); x = ((x & 0x0000ffff0000ffff) << 16) | ((x & 0xffff0000ffff0000) >> 16);
return (x << 32) | (x >> 32); return (x << 32) | (x >> 32);
} }
#endif # endif
#endif /* __OpenBSD__ */
#if defined(__GNUC__) #if defined(__GNUC__)
#define UNUSED __attribute__((unused)) #define UNUSED __attribute__((unused))

View file

@ -89,3 +89,14 @@ if (ARM)
PROPERTY COMPILE_DEFINITIONS "NO_OPTIMIZED_MULTIPLY_ON_ARM") PROPERTY COMPILE_DEFINITIONS "NO_OPTIMIZED_MULTIPLY_ON_ARM")
endif() endif()
endif() endif()
# Because of the way Qt works on android with JNI, the code does not live in the main android thread
# So this code runs with a 1 MB default stack size.
# This will force the use of the heap for the allocation of the scratchpad
if (ANDROID)
if( BUILD_GUI_DEPS )
add_definitions(-DFORCE_USE_HEAP=1)
endif()
endif()

View file

@ -39,8 +39,8 @@
#include <malloc.h> #include <malloc.h>
#endif #endif
// FreeBSD, and OpenBSD also don't need timeb.h // ANDROID, FreeBSD, and OpenBSD also don't need timeb.h
#if !defined(__FreeBSD__) && !defined(__OpenBSD__) #if !defined(__FreeBSD__) && !defined(__OpenBSD__) && !defined(__ANDROID__)
#include <sys/timeb.h> #include <sys/timeb.h>
#else #else
#include <sys/time.h> #include <sys/time.h>
@ -499,7 +499,7 @@ static void oaes_get_seed( char buf[RANDSIZ + 1] )
#else #else
static uint32_t oaes_get_seed(void) static uint32_t oaes_get_seed(void)
{ {
#if !defined(__FreeBSD__) && !defined(__OpenBSD__) #if !defined(__FreeBSD__) && !defined(__OpenBSD__) && !defined(__ANDROID__)
struct timeb timer; struct timeb timer;
struct tm *gmTimer; struct tm *gmTimer;
char * _test = NULL; char * _test = NULL;

View file

@ -1052,7 +1052,6 @@ STATIC INLINE void xor_blocks(uint8_t* a, const uint8_t* b)
void cn_slow_hash(const void *data, size_t length, char *hash) void cn_slow_hash(const void *data, size_t length, char *hash)
{ {
uint8_t long_state[MEMORY];
uint8_t text[INIT_SIZE_BYTE]; uint8_t text[INIT_SIZE_BYTE];
uint8_t a[AES_BLOCK_SIZE]; uint8_t a[AES_BLOCK_SIZE];
uint8_t b[AES_BLOCK_SIZE]; uint8_t b[AES_BLOCK_SIZE];
@ -1070,6 +1069,13 @@ void cn_slow_hash(const void *data, size_t length, char *hash)
hash_extra_blake, hash_extra_groestl, hash_extra_jh, hash_extra_skein hash_extra_blake, hash_extra_groestl, hash_extra_jh, hash_extra_skein
}; };
#ifndef FORCE_USE_HEAP
uint8_t long_state[MEMORY];
#else
uint8_t *long_state = NULL;
long_state = (uint8_t *)malloc(MEMORY);
#endif
hash_process(&state.hs, data, length); hash_process(&state.hs, data, length);
memcpy(text, state.init, INIT_SIZE_BYTE); memcpy(text, state.init, INIT_SIZE_BYTE);
@ -1129,6 +1135,9 @@ void cn_slow_hash(const void *data, size_t length, char *hash)
memcpy(state.init, text, INIT_SIZE_BYTE); memcpy(state.init, text, INIT_SIZE_BYTE);
hash_permutation(&state.hs); hash_permutation(&state.hs);
extra_hashes[state.hs.b[0] & 3](&state, 200, hash); extra_hashes[state.hs.b[0] & 3](&state, 200, hash);
#ifdef FORCE_USE_HEAP
free(long_state);
#endif
} }
#endif /* !aarch64 || !crypto */ #endif /* !aarch64 || !crypto */