Skip to content

Commit

Permalink
feat: iOS builds
Browse files Browse the repository at this point in the history
  • Loading branch information
MrCyjaneK committed Apr 2, 2024
1 parent e4cde6d commit e2ad141
Show file tree
Hide file tree
Showing 15 changed files with 379 additions and 23 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@
[submodule "external/polyseed"]
path = external/polyseed
url = https://github.com/tevador/polyseed
[submodule "external/ios-cmake"]
path = external/ios-cmake
url = https://github.com/leetal/ios-cmake
89 changes: 72 additions & 17 deletions build_single.sh
Original file line number Diff line number Diff line change
Expand Up @@ -103,19 +103,15 @@ case "$HOST_ABI" in
export CC="clang"
export CXX="clang++"
;;
"host-apple-ios")
export CC="clang -arch arm64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk"
export CXX="clang++ -arch arm64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk"
;;
*)
echo "Unsupported target."
exit 1
;;
esac

if [[ "x$CC" == "x" ]];
then
echo "No C compiler found for abi: '$HOST_ABI'. Adjust the switch case in $0"
exit 1
fi

if [[ "x$CXX" == "x" ]];
then
echo "No C++ compiler found for abi: '$HOST_ABI'. Adjust the switch case in $0"
exit 1
fi
pushd $repo/contrib/depends
case "$HOST_ABI" in
"x86_64-linux-gnu" | "i686-linux-gnu" | "aarch64-linux-gnu" | "x86_64-linux-android" | "i686-linux-android" | "aarch64-linux-android" | "arm-linux-androideabi" | "i686-w64-mingw32" | "x86_64-w64-mingw32" | "x86_64-apple-darwin11" | "aarch64-apple-darwin11")
Expand Down Expand Up @@ -156,6 +152,43 @@ pushd $repo/contrib/depends
verbose_copy "${HOMEBREW_PREFIX}/lib/libsodium.a" ${MACOS_LIBS_DIR}/lib/libsodium.a
verbose_copy "${HOMEBREW_PREFIX}/lib/libevent.a" ${MACOS_LIBS_DIR}/lib/libevent.a
;;
"host-apple-ios")
echo "===================================="
echo "= ="
echo "= CHECK README.md IF BUILD FAILS ="
echo "= ="
echo "===================================="
# pushd external/ios
# ./build_all.sh
# popd
POLYSEED_DIR=../../../external/polyseed/build/${HOST_ABI}
rm -rf ${POLYSEED_DIR}
mkdir -p ${POLYSEED_DIR}
pushd ${POLYSEED_DIR}
CC="${CC}" CXX="${CXX}" cmake -DCMAKE_TOOLCHAIN_FILE=../../../ios-cmake/ios.toolchain.cmake -DPLATFORM=OS64 ../..
make $NPROC
popd
IOS_LIBS_DIR="${PWD}/host-apple-ios"
rm -rf ${IOS_LIBS_DIR}
mkdir -p ${IOS_LIBS_DIR}/lib
export IOS_PREFIX="$(realpath "${PWD}/../../../external/ios/build/ios")"
verbose_copy "${IOS_PREFIX}/lib/libunbound.a" ${IOS_LIBS_DIR}/lib/libunbound.a
verbose_copy "${IOS_PREFIX}/lib/libboost_chrono.a" ${IOS_LIBS_DIR}/lib/libboost_chrono.a
verbose_copy "${IOS_PREFIX}/lib/libboost_locale.a" ${IOS_LIBS_DIR}/lib/libboost_locale.a
verbose_copy "${IOS_PREFIX}/lib/libboost_date_time.a" ${IOS_LIBS_DIR}/lib/libboost_date_time.a
verbose_copy "${IOS_PREFIX}/lib/libboost_filesystem.a" ${IOS_LIBS_DIR}/lib/libboost_filesystem.a
verbose_copy "${IOS_PREFIX}/lib/libboost_program_options.a" ${IOS_LIBS_DIR}/lib/libboost_program_options.a
verbose_copy "${IOS_PREFIX}/lib/libboost_regex.a" ${IOS_LIBS_DIR}/lib/libboost_regex.a
verbose_copy "${IOS_PREFIX}/lib/libboost_serialization.a" ${IOS_LIBS_DIR}/lib/libboost_serialization.a
verbose_copy "${IOS_PREFIX}/lib/libboost_system.a" ${IOS_LIBS_DIR}/lib/libboost_system.a
verbose_copy "${IOS_PREFIX}/lib/libboost_thread.a" ${IOS_LIBS_DIR}/lib/libboost_thread.a
verbose_copy "${IOS_PREFIX}/lib/libboost_wserialization.a" ${IOS_LIBS_DIR}/lib/libboost_wserialization.a
verbose_copy "${POLYSEED_DIR}/libpolyseed.a" ${IOS_LIBS_DIR}/lib/libpolyseed.a
verbose_copy "${IOS_PREFIX}/lib/libssl.a" ${IOS_LIBS_DIR}/lib/libssl.a
verbose_copy "${IOS_PREFIX}/lib/libcrypto.a" ${IOS_LIBS_DIR}/lib/libcrypto.a
verbose_copy "${IOS_PREFIX}/lib/libsodium.a" ${IOS_LIBS_DIR}/lib/libsodium.a
# verbose_copy "${IOS_PREFIX}/lib/libevent.a" ${IOS_LIBS_DIR}/lib/libevent.a
;;
*)
echo "Unable to build dependencies for '$HOST_ABI'."
exit 1
Expand Down Expand Up @@ -205,6 +238,15 @@ pushd $repo/build/${HOST_ABI}
"host-apple-darwin")
env CC="${CC}" CXX="${CXX}" cmake -D USE_DEVICE_TREZOR=OFF -D BUILD_GUI_DEPS=1 -D BUILD_TESTS=OFF -D STATIC=ON -D BUILD_64=ON -D CMAKE_BUILD_TYPE=$buildType ../..
;;
"host-apple-ios")
PREFIX="$(realpath "${PWD}/../../../external/ios/build/ios")"
# echo $PREFIX
# exit 1
env \
CMAKE_INCLUDE_PATH="${PREFIX}/include" \
CMAKE_LIBRARY_PATH="${PREFIX}/lib" \
CC="${CC}" CXX="${CXX}" cmake -D IOS=ON -D ARCH=arm64 -D CMAKE_BUILD_DYPE=$buildType -D STATIC=ON -D BUILD_GUI_DEPS=1 -D UNBOUND_INCLUDE_DIR="${PREFIX}/lib" ../..
;;
*)
echo "we don't know how to compile monero for '$HOST_ABI'"
exit 1
Expand All @@ -222,10 +264,23 @@ fi
pushd ${repo}_libwallet2_api_c
rm -rf build/${HOST_ABI} || true
mkdir -p build/${HOST_ABI} -p
cd build/${HOST_ABI}

env CC="${CC}" CXX="${CXX}" cmake -DMONERO_FLAVOR=$repo -DCMAKE_BUILD_TYPE=Debug -DHOST_ABI=${HOST_ABI} ../..
CC="${CC}" CXX="${CXX}" make $NPROC
pushd build/${HOST_ABI}
case $HOST_ABI in
"x86_64-linux-gnu" | "i686-linux-gnu" | "aarch64-linux-gnu" | "x86_64-linux-android" | "i686-linux-android" | "aarch64-linux-android" | "arm-linux-androideabi" | "i686-w64-mingw32" | "x86_64-w64-mingw32" | "x86_64-apple-darwin11" | "aarch64-apple-darwin11")
env CC="${CC}" CXX="${CXX}" cmake -DMONERO_FLAVOR=$repo -DCMAKE_BUILD_TYPE=Debug -DHOST_ABI=${HOST_ABI} ../..
CC="${CC}" CXX="${CXX}" make $NPROC
;;
"host-apple-ios")
export -n CC CXX
cmake -DCMAKE_TOOLCHAIN_FILE=../../../external/ios-cmake/ios.toolchain.cmake -DPLATFORM=OS64 -DMONERO_FLAVOR=$repo -DCMAKE_BUILD_TYPE=Debug -DHOST_ABI=${HOST_ABI} ../..
make $NPROC
;;
*)
echo "Unable to build ${repo}_libwallet2_api_c for ${HOST_ABI}"
exit 1
;;
esac
popd
popd

mkdir -p release/$repo 2>/dev/null || true
Expand All @@ -237,7 +292,7 @@ pushd release/$repo
cp ../../$repo/build/${HOST_ABI}/external/polyseed/libpolyseed.${APPENDIX} ${HOST_ABI}_libpolyseed.${APPENDIX}
rm ${HOST_ABI}_libpolyseed.${APPENDIX}.xz || true
xz -e ${HOST_ABI}_libpolyseed.${APPENDIX}
elif [[ "${HOST_ABI}" == "x86_64-apple-darwin11" || "${HOST_ABI}" == "aarch64-apple-darwin11" || "${HOST_ABI}" == "host-apple-darwin" ]];
elif [[ "${HOST_ABI}" == "x86_64-apple-darwin11" || "${HOST_ABI}" == "aarch64-apple-darwin11" || "${HOST_ABI}" == "host-apple-darwin" || "${HOST_ABI}" == "host-apple-ios" ]];
then
APPENDIX="${APPENDIX}dylib"
else
Expand Down
1 change: 1 addition & 0 deletions external/ios-cmake
Submodule ios-cmake added at 06465b
25 changes: 25 additions & 0 deletions external/ios/build_boost.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

set -e

. ./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.84.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
16 changes: 16 additions & 0 deletions external/ios/build_libiconv.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

set -e

. config.sh

ICONV_DIR_PATH="${EXTERNAL_IOS_SOURCE_DIR}/libiconv"

rm -rf $ICONV_DIR_PATH
mkdir -p $ICONV_DIR_PATH
pushd $ICONV_DIR_PATH
wget https://ftp.gnu.org/gnu/libiconv/libiconv-1.15.tar.gz -O -| tar xzv
pushd libiconv-1.15

popd
popd
14 changes: 14 additions & 0 deletions external/ios/build_monero_all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

set -e

rm -rf build

. ./config.sh
./install_missing_headers.sh
./build_openssl.sh
./build_boost.sh
./build_sodium.sh
./build_zmq.sh
./build_unbound.sh

19 changes: 19 additions & 0 deletions external/ios/build_openssl.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

set -e

. ./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.1q --targets="ios-cross-arm64" --deprecated

mv ${OPEN_SSL_DIR_PATH}/include/* $EXTERNAL_IOS_INCLUDE_DIR
mv ${OPEN_SSL_DIR_PATH}/lib/libcrypto-iOS.a ${EXTERNAL_IOS_LIB_DIR}/libcrypto.a
mv ${OPEN_SSL_DIR_PATH}/lib/libssl-iOS.a ${EXTERNAL_IOS_LIB_DIR}/libssl.a
19 changes: 19 additions & 0 deletions external/ios/build_sodium.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

set -e

. ./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
cd $SODIUM_PATH
git checkout 443617d7507498f7477703f0b51cb596d4539262
./dist-build/apple-xcframework.sh

mv ${SODIUM_PATH}/libsodium-apple/ios/include/* $EXTERNAL_IOS_INCLUDE_DIR
mv ${SODIUM_PATH}/libsodium-apple/ios/lib/* $EXTERNAL_IOS_LIB_DIR
28 changes: 28 additions & 0 deletions external/ios/build_unbound.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash

set -e

. ./config.sh

UNBOUND_VERSION=release-1.16.2
UNBOUND_HASH="cbed768b8ff9bfcf11089a5f1699b7e5707f1ea5"
UNBOUND_URL="https://www.nlnetlabs.nl/downloads/unbound/unbound-${UNBOUND_VERSION}.tar.gz"
UNBOUND_DIR_PATH="${EXTERNAL_IOS_SOURCE_DIR}/unbound-1.16.2"

echo "============================ Unbound ============================"
rm -rf ${UNBOUND_DIR_PATH}
git clone https://github.com/NLnetLabs/unbound.git -b ${UNBOUND_VERSION} ${UNBOUND_DIR_PATH}
cd $UNBOUND_DIR_PATH
test `git rev-parse HEAD` = ${UNBOUND_HASH} || exit 1

export IOS_SDK=iPhone
export IOS_CPU=arm64
export IOS_PREFIX=$EXTERNAL_IOS_DIR
export AUTOTOOLS_HOST=aarch64-apple-ios
export AUTOTOOLS_BUILD="$(./config.guess)"
source ./contrib/ios/setenv_ios.sh
./contrib/ios/install_tools.sh
./contrib/ios/install_expat.sh
./configure --build="$AUTOTOOLS_BUILD" --host="$AUTOTOOLS_HOST" --prefix="$IOS_PREFIX" --with-ssl="$IOS_PREFIX" --with-libexpat="$IOS_PREFIX"
make
make install
22 changes: 22 additions & 0 deletions external/ios/build_zmq.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash

set -e

. ./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
cd $ZMQ_PATH
mkdir cmake-build
cd cmake-build
cmake ..
make


cp ${ZMQ_PATH}/include/* $EXTERNAL_IOS_INCLUDE_DIR
cp ${ZMQ_PATH}/cmake-build/lib/libzmq.a $EXTERNAL_IOS_LIB_DIR
12 changes: 12 additions & 0 deletions external/ios/config.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh

export IOS_SCRIPTS_DIR="$(pwd)"
export CW_ROOT="${IOS_SCRIPTS_DIR}"
export EXTERNAL_DIR="${CW_ROOT}/build"
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"
69 changes: 69 additions & 0 deletions external/ios/install_missing_headers.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/bin/bash

set -e

. ./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/IOMapTypes.h ]; then
cp /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/IOKit.framework/Versions/A/Headers/IOMapTypes.h ${EXTERNAL_IOS_INCLUDE_DIR}/IOKit/IOMapTypes.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
Loading

0 comments on commit e2ad141

Please sign in to comment.