summaryrefslogtreecommitdiff
path: root/protocols/Telegram/tdlib/td/example/ios
diff options
context:
space:
mode:
authoraunsane <aunsane@gmail.com>2018-04-27 21:33:17 +0300
committeraunsane <aunsane@gmail.com>2018-04-27 21:33:17 +0300
commite1ec72eab6d00b3ba38e5932bc88920f103b6e4a (patch)
tree999de2725a83e30fbbf6576200525d4ef0c5fe38 /protocols/Telegram/tdlib/td/example/ios
parentb9ce1d4d98525490ca1a38e2d9fd4f3369adb3e0 (diff)
Telegram: initial commit
- tdlib moved to telegram dir
Diffstat (limited to 'protocols/Telegram/tdlib/td/example/ios')
-rw-r--r--protocols/Telegram/tdlib/td/example/ios/README.md41
-rw-r--r--protocols/Telegram/tdlib/td/example/ios/build-openssl.sh22
-rw-r--r--protocols/Telegram/tdlib/td/example/ios/build.sh74
3 files changed, 137 insertions, 0 deletions
diff --git a/protocols/Telegram/tdlib/td/example/ios/README.md b/protocols/Telegram/tdlib/td/example/ios/README.md
new file mode 100644
index 0000000000..25a1e68fcc
--- /dev/null
+++ b/protocols/Telegram/tdlib/td/example/ios/README.md
@@ -0,0 +1,41 @@
+# Build for iOS
+
+Below are instructions for building TDLib for iOS, watchOS, tvOS, and also macOS.
+
+If you need only a macOS build, take a look at our build instructions for [macOS](https://github.com/tdlib/td#macos).
+
+For example of usage take a look at our [Swift example](https://github.com/tdlib/td/tree/master/example/swift).
+
+To compile `TDLib` you will need to:
+* Install the latest Xcode command line tools.
+* Install other build dependencies, for example, using [Homebrew](https://brew.sh):
+```
+brew install gperf cmake
+```
+* If you don't want to build `TDLib` for macOS, you can pregenerate required source code files using CMake prepare_cross_compiling target:
+```
+cd <path to TDLib sources>
+mkdir native-build
+cd native-build
+cmake ..
+cmake --build . --target prepare_cross_compiling
+```
+* Build OpenSSL for iOS, watchOS, tvOS and macOS:
+```
+cd <path to TDLib sources>/example/ios
+./build-openssl.sh
+```
+Here we use scripts from [Python Apple support](https://github.com/pybee/Python-Apple-support), but any other OpenSSL builds should work too.
+Built libraries should be stored in `third_party/openssl/<platform>`, because the next script will rely on this location.
+* Build TDLib for iOS, watchOS, tvOS and macOS:
+```
+cd <path to TDLib sources>/example/ios
+./build.sh
+```
+This may take a while, because TDLib will be built about 10 times.
+Resulting library for iOS will work on any architecture (arv7, armv7s, arm64) and even on a simulator.
+We use [CMake/iOS.cmake](https://github.com/tdlib/td/blob/master/CMake/iOS.cmake) toolchain, other toolchains may work too.
+
+Built libraries will be store in `tdjson` directory.
+
+Documentation for all available classes and methods can be found at https://core.telegram.org/tdlib/docs.
diff --git a/protocols/Telegram/tdlib/td/example/ios/build-openssl.sh b/protocols/Telegram/tdlib/td/example/ios/build-openssl.sh
new file mode 100644
index 0000000000..2ad9dbcfee
--- /dev/null
+++ b/protocols/Telegram/tdlib/td/example/ios/build-openssl.sh
@@ -0,0 +1,22 @@
+#!/bin/sh
+
+git clone https://github.com/pybee/Python-Apple-support
+cd Python-Apple-support
+git checkout 2.7
+cd ..
+
+#TODO: change openssl version
+platforms="macOS iOS watchOS tvOS"
+for platform in $platforms;
+do
+ echo $platform
+ cd Python-Apple-support
+ #NB: -j will fail
+ make OpenSSL-$platform
+ cd ..
+ rm -rf third_party/openssl/$platform
+ mkdir -p third_party/openssl/$platform/lib
+ cp ./Python-Apple-support/build/$platform/libcrypto.a third_party/openssl/$platform/lib/
+ cp ./Python-Apple-support/build/$platform/libssl.a third_party/openssl/$platform/lib/
+ cp -r ./Python-Apple-support/build/$platform/Support/OpenSSL/Headers/ third_party/openssl/$platform/include
+done
diff --git a/protocols/Telegram/tdlib/td/example/ios/build.sh b/protocols/Telegram/tdlib/td/example/ios/build.sh
new file mode 100644
index 0000000000..9970008a1c
--- /dev/null
+++ b/protocols/Telegram/tdlib/td/example/ios/build.sh
@@ -0,0 +1,74 @@
+#/bin/sh
+td_path=$(realpath ../..)
+
+rm -rf build
+mkdir -p build
+cd build
+
+platforms="macOS iOS watchOS tvOS"
+for platform in $platforms;
+do
+ echo "Platform = ${platform} Simulator = ${simulator}"
+ openssl_path=$(realpath ../third_party/openssl/${platform})
+ echo "OpenSSL path = ${openssl_path}"
+ openssl_crypto_library="${openssl_path}/lib/libcrypto.a"
+ openssl_ssl_library="${openssl_path}/lib/libssl.a"
+ options="$options -DOPENSSL_FOUND=1"
+ options="$options -DOPENSSL_CRYPTO_LIBRARY=${openssl_crypto_library}"
+ #options="$options -DOPENSSL_SSL_LIBRARY=${openssl_ssl_library}"
+ options="$options -DOPENSSL_INCLUDE_DIR=${openssl_path}/include"
+ options="$options -DOPENSSL_LIBRARIES=${openssl_crypto_library};${openssl_ssl_library}"
+ options="$options -DCMAKE_BUILD_TYPE=Release"
+ if [[ $platform = "macOS" ]]; then
+ build="build-${platform}"
+ install="install-${platform}"
+ rm -rf $build
+ mkdir -p $build
+ mkdir -p $install
+ cd $build
+ cmake $td_path $options -DCMAKE_INSTALL_PREFIX=../${install}
+ make -j3 install || exit
+ cd ..
+ mkdir -p $platform
+ cp $build/libtdjson.dylib $platform/libtdjson.dylib
+ install_name_tool -id @rpath/libtdjson.dylib $platform/libtdjson.dylib
+ else
+ simulators="0 1"
+ for simulator in $simulators;
+ do
+ build="build-${platform}"
+ install="install-${platform}"
+ if [[ $simulator = "1" ]]; then
+ build="${build}-simulator"
+ install="${install}-simulator"
+ ios_platform="SIMULATOR"
+ else
+ ios_platform="OS"
+ fi
+ if [[ $platform = "watchOS" ]]; then
+ ios_platform="WATCH${ios_platform}"
+ fi
+ if [[ $platform = "tvOS" ]]; then
+ ios_platform="TV${ios_platform}"
+ fi
+ echo $ios_platform
+ rm -rf $build
+ mkdir -p $build
+ mkdir -p $install
+ cd $build
+ cmake $td_path $options -DIOS_PLATFORM=${ios_platform} -DCMAKE_TOOLCHAIN_FILE=${td_path}/CMake/iOS.cmake -DCMAKE_INSTALL_PREFIX=../${install}
+ make -j3 install || exit
+ cd ..
+ done
+ lib="install-${platform}/lib/libtdjson.dylib"
+ lib_simulator="install-${platform}-simulator/lib/libtdjson.dylib"
+ mkdir -p $platform
+ lipo -create $lib $lib_simulator -o $platform/libtdjson.dylib
+ install_name_tool -id @rpath/libtdjson.dylib $platform/libtdjson.dylib
+ fi
+
+ mkdir -p ../tdjson/$platform/include
+ rsync --recursive ${install}/include/ ../tdjson/${platform}/include/
+ mkdir -p ../tdjson/$platform/lib
+ cp $platform/libtdjson.dylib ../tdjson/$platform/lib/
+done