From b81f4679860de7914de046c691bcc208227bbb7a Mon Sep 17 00:00:00 2001 From: M Date: Mon, 13 Sep 2021 19:33:32 +0300 Subject: [PATCH] Added scripts for build iOS monero dependencies --- cw_monero/ios/Classes/monero_api.cpp | 5 +- cw_monero/ios/cw_monero.podspec | 32 ++++++------- ios/Podfile.lock | 2 +- scripts/ios/build_all.sh | 9 ++++ scripts/ios/build_boost.sh | 23 ++++++++++ scripts/ios/build_monero.sh | 61 +++++++++++++++++++++++++ scripts/ios/build_openssl.sh | 16 +++++++ scripts/ios/build_sodium.sh | 16 +++++++ scripts/ios/build_zmq.sh | 13 ++++++ scripts/ios/config.sh | 12 +++++ scripts/ios/install_missing_headers.sh | 63 ++++++++++++++++++++++++++ 11 files changed, 233 insertions(+), 19 deletions(-) create mode 100755 scripts/ios/build_all.sh create mode 100755 scripts/ios/build_boost.sh create mode 100755 scripts/ios/build_monero.sh create mode 100755 scripts/ios/build_openssl.sh create mode 100755 scripts/ios/build_sodium.sh create mode 100755 scripts/ios/build_zmq.sh create mode 100755 scripts/ios/config.sh create mode 100755 scripts/ios/install_missing_headers.sh diff --git a/cw_monero/ios/Classes/monero_api.cpp b/cw_monero/ios/Classes/monero_api.cpp index eefdede60..9d52bdfe2 100644 --- a/cw_monero/ios/Classes/monero_api.cpp +++ b/cw_monero/ios/Classes/monero_api.cpp @@ -8,13 +8,14 @@ #include "thread" #include "CwWalletListener.h" #if __APPLE__ -#include "../External/android/monero/include/wallet2_api.h" +// Fix for randomx on ios +void __clear_cache(void* start, void* end) { } +#include "../External/ios/include/wallet2_api.h" #else #include "../External/android/x86/include/wallet2_api.h" #endif using namespace std::chrono_literals; - #ifdef __cplusplus extern "C" { diff --git a/cw_monero/ios/cw_monero.podspec b/cw_monero/ios/cw_monero.podspec index ad8a94d04..7224073b3 100644 --- a/cw_monero/ios/cw_monero.podspec +++ b/cw_monero/ios/cw_monero.podspec @@ -14,41 +14,41 @@ Pod::Spec.new do |s| s.source_files = 'Classes/**/*' s.public_header_files = 'Classes/**/*.h, Classes/*.h, External/ios/libs/monero/include/src/**/*.h, External/ios/libs/monero/include/contrib/**/*.h, External/ios/libs/monero/include/External/ios/**/*.h' s.dependency 'Flutter' - s.platform = :ios, '9.0' + s.platform = :ios, '10.0' s.swift_version = '4.0' s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES', 'VALID_ARCHS' => 'arm64', 'ENABLE_BITCODE' => 'NO' } s.xcconfig = { 'HEADER_SEARCH_PATHS' => "${PODS_ROOT}/#{s.name}/Classes/*.h" } s.subspec 'OpenSSL' do |openssl| - openssl.preserve_paths = 'External/ios/libs/OpenSSL/include/openssl/*.h', 'External/ios/libs/OpenSSL/include/LICENSE' - openssl.vendored_libraries = 'External/ios/libs/OpenSSL/lib/libcrypto.a', 'External/ios/libs/OpenSSL/lib/libssl.a' + openssl.preserve_paths = 'External/ios/include/*.h' + openssl.vendored_libraries = 'External/ios/lib/libcrypto.a', 'External/ios/lib/libssl.a' openssl.libraries = 'ssl', 'crypto' - openssl.xcconfig = { 'HEADER_SEARCH_PATHS' => "${PODS_ROOT}/#{s.name}/External/ios/libs/OpenSSL/include/**" } + openssl.xcconfig = { 'HEADER_SEARCH_PATHS' => "${PODS_ROOT}/#{s.name}/External/ios/include/**" } end s.subspec 'Monero' do |monero| - monero.preserve_paths = 'External/ios/libs/monero/include/src/**/*.h', 'External/ios/libs/monero/include/External/ios/**/*.h', 'External/ios/libs/monero/include/contrib/**/*.h' - monero.vendored_libraries = 'External/ios/libs/monero/libs/lib-ios/*.a' - monero.libraries = 'easylogging', 'epee', 'unbound', 'wallet_merged', 'lmdb', 'randomx' - monero.xcconfig = { 'HEADER_SEARCH_PATHS' => "${PODS_ROOT}/#{s.name}/External/ios/libs/monero/include/src/**" } + monero.preserve_paths = 'External/ios/include/**/*.h' + monero.vendored_libraries = 'External/ios/lib/libeasylogging.a', 'External/ios/lib/libepee.a', 'External/ios/lib/liblmdb.a', 'External/ios/lib/librandomx.a', 'External/ios/lib/libunbound.a', 'External/ios/lib/libwallet_merged.a', 'libcryptonote_basic.a', 'libcryptonote_format_utils_basic.a' + monero.libraries = 'easylogging', 'epee', 'unbound', 'wallet_merged', 'lmdb', 'randomx', 'cryptonote_basic', 'cryptonote_format_utils_basic' + monero.xcconfig = { 'HEADER_SEARCH_PATHS' => "${PODS_ROOT}/#{s.name}/External/ios/include" } end s.subspec 'Boost' do |boost| - boost.preserve_paths = 'External/ios/libs/boost/include/**/*.h', 'External/ios/libs/boost/include/**/*.h' - boost.vendored_libraries = 'External/ios/libs/boost/build/libs/universal/*.a' - boost.libraries = 'boost', 'boost_wserialization', 'boost_thread', 'boost_system', 'boost_signals', 'boost_serialization', 'boost_regex', 'boost_random', 'boost_program_options', 'boost_locale', 'boost_graph', 'boost_filesystem', 'boost_date_time', 'boost_chrono' - boost.xcconfig = { 'HEADER_SEARCH_PATHS' => "${PODS_ROOT}/#{s.name}/External/ios/libs/boost/include/**" } + boost.preserve_paths = 'External/ios/include/**/*.h', 'External/ios/include/**/*.h' + boost.vendored_libraries = 'External/ios/lib/libboost_chrono.a', 'External/ios/lib/libboost_date_time.a', 'External/ios/lib/libboost_filesystem.a', 'External/ios/lib/libboost_graph.a', 'External/ios/lib/libboost_locale.a', 'External/ios/lib/libboost_program_options.a', 'External/ios/lib/libboost_random.a', 'External/ios/lib/libboost_regex.a', 'External/ios/lib/libboost_serialization.a', 'External/ios/lib/libboost_system.a', 'External/ios/lib/libboost_thread.a', 'External/ios/lib/libboost_wserialization.a' + boost.libraries = 'boost_wserialization', 'boost_thread', 'boost_system', 'boost_serialization', 'boost_regex', 'boost_random', 'boost_program_options', 'boost_locale', 'boost_graph', 'boost_filesystem', 'boost_date_time', 'boost_chrono' + boost.xcconfig = { 'HEADER_SEARCH_PATHS' => "${PODS_ROOT}/#{s.name}/External/ios/include/**" } end s.subspec 'Sodium' do |sodium| - sodium.preserve_paths = 'External/ios/libs/sodium/include/**/*.h' - sodium.vendored_libraries = 'External/ios/libs/sodium/lib/libsodium.a' + sodium.preserve_paths = 'External/ios/include/**/*.h' + sodium.vendored_libraries = 'External/ios/lib/libsodium.a' sodium.libraries = 'sodium' - sodium.xcconfig = { 'HEADER_SEARCH_PATHS' => "${PODS_ROOT}/#{s.name}/External/ios/libs/sodium/include/**" } + sodium.xcconfig = { 'HEADER_SEARCH_PATHS' => "${PODS_ROOT}/#{s.name}/External/ios/include/**" } end s.subspec 'lmdb' do |lmdb| - lmdb.vendored_libraries = 'External/ios/libs/lmdb/liblmdb.a' + lmdb.vendored_libraries = 'External/ios/lib/liblmdb.a' lmdb.libraries = 'lmdb' end end diff --git a/ios/Podfile.lock b/ios/Podfile.lock index 4d3e08838..5d88b8c3b 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -165,7 +165,7 @@ SPEC CHECKSUMS: BigInt: f668a80089607f521586bbe29513d708491ef2f7 connectivity: c4130b2985d4ef6fd26f9702e886bd5260681467 CryptoSwift: 093499be1a94b0cae36e6c26b70870668cb56060 - cw_monero: 78f369253cc913efc23db9cf6be81a11eaf40fe1 + cw_monero: c79d5530b828b8013c1db421f1be8bab687f7b7e devicelocale: b22617f40038496deffba44747101255cee005b0 DKImagePickerController: b5eb7f7a388e4643264105d648d01f727110fc3d DKPhotoGallery: fdfad5125a9fdda9cc57df834d49df790dbb4179 diff --git a/scripts/ios/build_all.sh b/scripts/ios/build_all.sh new file mode 100755 index 000000000..42483323d --- /dev/null +++ b/scripts/ios/build_all.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +. ./config.sh +./install_missing_headers.sh +./build_openssl.sh +./build_boost.sh +./build_sodium.sh +./build_zmq.sh +./build_monero.sh \ No newline at end of file diff --git a/scripts/ios/build_boost.sh b/scripts/ios/build_boost.sh new file mode 100755 index 000000000..e8bdcb0e2 --- /dev/null +++ b/scripts/ios/build_boost.sh @@ -0,0 +1,23 @@ +#!/bin/sh + +. ./config.sh + +MIN_IOS_VERSION=10.0 +BOOST_URL="https://github.com/cake-tech/Apple-Boost-BuildScript.git" +BOOST_DIR_PATH="${EXTERNAL_IOS_SOURCE_DIR}/Apple-Boost-BuildScript" +BOOST_VERSION=1.74.0 +BOOST_LIBS="random regex graph random chrono thread filesystem system date_time locale serialization program_options" + +echo "============================ Boost ============================" + +echo "Cloning Apple-Boost-BuildScript from - $BOOST_URL" +git clone -b build $BOOST_URL $BOOST_DIR_PATH +cd $BOOST_DIR_PATH +./boost.sh -ios \ + --min-ios-version ${MIN_IOS_VERSION} \ + --boost-libs "${BOOST_LIBS}" \ + --boost-version ${BOOST_VERSION} \ + --no-framework + +mv ${BOOST_DIR_PATH}/build/boost/${BOOST_VERSION}/ios/release/prefix/include/* $EXTERNAL_IOS_INCLUDE_DIR +mv ${BOOST_DIR_PATH}/build/boost/${BOOST_VERSION}/ios/release/prefix/lib/* $EXTERNAL_IOS_LIB_DIR \ No newline at end of file diff --git a/scripts/ios/build_monero.sh b/scripts/ios/build_monero.sh new file mode 100755 index 000000000..2984f8ba0 --- /dev/null +++ b/scripts/ios/build_monero.sh @@ -0,0 +1,61 @@ +#!/bin/sh + +. ./config.sh + +MONERO_URL="https://github.com/monero-project/monero.git" +MONERO_DIR_PATH="${EXTERNAL_IOS_SOURCE_DIR}/monero" +MONERO_VERSION=tags/v0.17.2.3 +BUILD_TYPE=release +PREFIX=${EXTERNAL_IOS_DIR} + +echo "Cloning monero from - $MONERO_URL to - $MONERO_DIR_PATH" +git clone $MONERO_URL $MONERO_DIR_PATH +cd $MONERO_DIR_PATH +git checkout $MONERO_VERSION +git submodule update --init --force +mkdir -p build +cd .. + +ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +if [ -z $INSTALL_PREFIX ]; then + INSTALL_PREFIX=${ROOT_DIR}/monero +fi + +for arch in "arm64" #"armv7" "arm64" +do + +echo "Building IOS ${arch}" +export CMAKE_INCLUDE_PATH="${PREFIX}/include" +export CMAKE_LIBRARY_PATH="${PREFIX}/lib" + +case $arch in + "armv7" ) + DEST_LIB=../../lib-armv7;; + "arm64" ) + DEST_LIB=../../lib-armv8-a;; +esac + +rm -r monero/build > /dev/null + +mkdir -p monero/build/${BUILD_TYPE} +pushd monero/build/${BUILD_TYPE} +cmake -D IOS=ON \ + -DARCH=${arch} \ + -DCMAKE_BUILD_TYPE=${BUILD_TYPE} \ + -DSTATIC=ON \ + -DBUILD_GUI_DEPS=ON \ + -DINSTALL_VENDORED_LIBUNBOUND=ON \ + -DCMAKE_INSTALL_PREFIX=${INSTALL_PREFIX} \ + -DUSE_DEVICE_TREZOR=OFF \ + ../.. +make -j4 && make install +cp external/randomx/librandomx.a ${DEST_LIB} +cp src/cryptonote_basic/libcryptonote_basic.a ${DEST_LIB} +cp src/cryptonote_basic/libcryptonote_format_utils_basic.a ${DEST_LIB} +popd + +done + +#only for arm64 +cp ${MONERO_DIR_PATH}/lib-armv8-a/* $EXTERNAL_IOS_LIB_DIR +cp ${MONERO_DIR_PATH}/include/wallet/api/* $EXTERNAL_IOS_INCLUDE_DIR \ No newline at end of file diff --git a/scripts/ios/build_openssl.sh b/scripts/ios/build_openssl.sh new file mode 100755 index 000000000..f6f76c0dd --- /dev/null +++ b/scripts/ios/build_openssl.sh @@ -0,0 +1,16 @@ +#!/bin/sh + +. ./config.sh + +OPEN_SSL_URL="https://github.com/x2on/OpenSSL-for-iPhone.git" +OPEN_SSL_DIR_PATH="${EXTERNAL_IOS_SOURCE_DIR}/OpenSSL" + +echo "============================ OpenSSL ============================" + +echo "Cloning Open SSL from - $OPEN_SSL_URL" +git clone $OPEN_SSL_URL $OPEN_SSL_DIR_PATH +cd $OPEN_SSL_DIR_PATH +./build-libssl.sh --version=1.1.1k --archs="x86_64 arm64 armv7s armv7" --targets="ios64-cross-arm64" --deprecated + +mv ${OPEN_SSL_DIR_PATH}/include/* $EXTERNAL_IOS_INCLUDE_DIR +mv ${OPEN_SSL_DIR_PATH}/lib/* $EXTERNAL_IOS_LIB_DIR \ No newline at end of file diff --git a/scripts/ios/build_sodium.sh b/scripts/ios/build_sodium.sh new file mode 100755 index 000000000..66f383fb4 --- /dev/null +++ b/scripts/ios/build_sodium.sh @@ -0,0 +1,16 @@ +#!/bin/sh + +. ./config.sh + +SODIUM_PATH="${EXTERNAL_IOS_SOURCE_DIR}/libsodium" +SODIUM_URL="https://github.com/jedisct1/libsodium.git" + +echo "============================ SODIUM ============================" + +echo "Cloning SODIUM from - $SODIUM_URL" +git clone $SODIUM_URL $SODIUM_PATH --branch stable +cd $SODIUM_PATH +./dist-build/ios.sh + +mv ${SODIUM_PATH}/libsodium-ios/include/* $EXTERNAL_IOS_INCLUDE_DIR +mv ${SODIUM_PATH}/libsodium-ios/lib/* $EXTERNAL_IOS_LIB_DIR \ No newline at end of file diff --git a/scripts/ios/build_zmq.sh b/scripts/ios/build_zmq.sh new file mode 100755 index 000000000..5b3e7c4a3 --- /dev/null +++ b/scripts/ios/build_zmq.sh @@ -0,0 +1,13 @@ +#!/bin/sh + +. ./config.sh + +ZMQ_PATH="${EXTERNAL_IOS_SOURCE_DIR}/libzmq" +ZMQ_URL="https://github.com/zeromq/libzmq.git" + +echo "============================ ZMQ ============================" + +echo "Cloning ZMQ from - $ZMQ_URL" +git clone $ZMQ_URL $ZMQ_PATH + +cp ${ZMQ_PATH}/include/* $EXTERNAL_IOS_INCLUDE_DIR \ No newline at end of file diff --git a/scripts/ios/config.sh b/scripts/ios/config.sh new file mode 100755 index 000000000..128701469 --- /dev/null +++ b/scripts/ios/config.sh @@ -0,0 +1,12 @@ +#!/bin/sh + +export IOS_SCRIPTS_DIR=`pwd` +export CW_ROOT=${IOS_SCRIPTS_DIR}/../.. +export EXTERNAL_DIR=${CW_ROOT}/cw_monero/ios/External +export EXTERNAL_IOS_DIR=${EXTERNAL_DIR}/ios +export EXTERNAL_IOS_SOURCE_DIR=${EXTERNAL_IOS_DIR}/sources +export EXTERNAL_IOS_LIB_DIR=${EXTERNAL_IOS_DIR}/lib +export EXTERNAL_IOS_INCLUDE_DIR=${EXTERNAL_IOS_DIR}/include + +mkdir -p $EXTERNAL_IOS_LIB_DIR +mkdir -p $EXTERNAL_IOS_INCLUDE_DIR \ No newline at end of file diff --git a/scripts/ios/install_missing_headers.sh b/scripts/ios/install_missing_headers.sh new file mode 100755 index 000000000..26d5bfd9e --- /dev/null +++ b/scripts/ios/install_missing_headers.sh @@ -0,0 +1,63 @@ +#!/bin/bash + +. ./config.sh + +echo "Installing missing headers" + +# vmmeter +mkdir -p ${EXTERNAL_IOS_INCLUDE_DIR}/sys + +if [ ! -f ${EXTERNAL_IOS_INCLUDE_DIR}/sys/vmmeter.h ]; then + cp /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/sys/vmmeter.h ${EXTERNAL_IOS_INCLUDE_DIR}/sys/vmmeter.h +fi + +# netinet +mkdir -p ${EXTERNAL_IOS_INCLUDE_DIR}/netinet +if [ ! -f ${EXTERNAL_IOS_INCLUDE_DIR}/netinet/ip_var.h ]; then + cp /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/netinet/ip_var.h ${EXTERNAL_IOS_INCLUDE_DIR}/netinet/ip_var.h +fi + +if [ ! -f ${EXTERNAL_IOS_INCLUDE_DIR}/netinet/udp_var.h ]; then + cp /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/netinet/udp_var.h ${EXTERNAL_IOS_INCLUDE_DIR}/netinet/udp_var.h +fi + +# IOKit +mkdir -p ${EXTERNAL_IOS_INCLUDE_DIR}/IOKit +if [ ! -f ${EXTERNAL_IOS_INCLUDE_DIR}/IOKit/IOTypes.h ]; then + cp /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/IOKit.framework/Versions/A/Headers/IOTypes.h ${EXTERNAL_IOS_INCLUDE_DIR}/IOKit/IOTypes.h +fi + +if [ ! -f ${EXTERNAL_IOS_INCLUDE_DIR}/IOKit/IOKitLib.h ]; then + cp /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/IOKit.framework/Versions/A/Headers/IOKitLib.h ${EXTERNAL_IOS_INCLUDE_DIR}/IOKit/IOKitLib.h +fi + +if [ ! -f ${EXTERNAL_IOS_INCLUDE_DIR}/IOKit/IOReturn.h ]; then + cp /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/IOKit.framework/Versions/A/Headers/IOReturn.h ${EXTERNAL_IOS_INCLUDE_DIR}/IOKit/IOReturn.h +fi + +if [ ! -f ${EXTERNAL_IOS_INCLUDE_DIR}/IOKit/OSMessageNotification.h ]; then + cp /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/IOKit.framework/Versions/A/Headers/OSMessageNotification.h ${EXTERNAL_IOS_INCLUDE_DIR}/IOKit/OSMessageNotification.h +fi + +# IOKit/ps +mkdir -p ${EXTERNAL_IOS_INCLUDE_DIR}/IOKit/ps + +if [ ! -f ${EXTERNAL_IOS_INCLUDE_DIR}/IOKit/ps/IOPSKeys.h ]; then + cp /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/IOKit.framework/Versions/A/Headers/ps/IOPSKeys.h ${EXTERNAL_IOS_INCLUDE_DIR}/IOKit/ps/IOPSKeys.h +fi + +if [ ! -f ${EXTERNAL_IOS_INCLUDE_DIR}/IOKit/ps/IOPowerSources.h ]; then + cp /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/IOKit.framework/Versions/A/Headers/ps/IOPowerSources.h ${EXTERNAL_IOS_INCLUDE_DIR}/IOKit/ps/IOPowerSources.h +fi + + +# libkern +mkdir -p ${EXTERNAL_IOS_INCLUDE_DIR}/libkern + +if [ ! -f ${EXTERNAL_IOS_INCLUDE_DIR}/libkern/OSTypes.h ]; then + cp /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/libkern/OSTypes.h ${EXTERNAL_IOS_INCLUDE_DIR}/libkern/OSTypes.h +fi + +if [ ! -f ${EXTERNAL_IOS_INCLUDE_DIR}/IOKit/IOKitKeys.h ]; then + cp /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/IOKit.framework/Versions/A/Headers/IOKitKeys.h ${EXTERNAL_IOS_INCLUDE_DIR}/IOKit/IOKitKeys.h +fi