diff options
Diffstat (limited to 'protocols/Telegram/tdlib/td/example/ios')
5 files changed, 227 insertions, 75 deletions
diff --git a/protocols/Telegram/tdlib/td/example/ios/Python-Apple-support.patch b/protocols/Telegram/tdlib/td/example/ios/Python-Apple-support.patch new file mode 100644 index 0000000000..cb551bf70a --- /dev/null +++ b/protocols/Telegram/tdlib/td/example/ios/Python-Apple-support.patch @@ -0,0 +1,104 @@ +diff --git a/Makefile b/Makefile +index 695be54..eda7b0d 100644 +--- a/Makefile ++++ b/Makefile +@@ -7,8 +7,11 @@ + # - watchOS - build everything for watchOS + # - OpenSSL-macOS - build OpenSSL for macOS + # - OpenSSL-iOS - build OpenSSL for iOS ++# - OpenSSL-iOS-simulator - build OpenSSL for iOS-simulator + # - OpenSSL-tvOS - build OpenSSL for tvOS ++# - OpenSSL-tvOS-simulator - build OpenSSL for tvOS-simulator + # - OpenSSL-watchOS - build OpenSSL for watchOS ++# - OpenSSL-watchOS-simulator - build OpenSSL for watchOS-simulator + # - BZip2-macOS - build BZip2 for macOS + # - BZip2-iOS - build BZip2 for iOS + # - BZip2-tvOS - build BZip2 for tvOS +@@ -30,37 +33,51 @@ PYTHON_VERSION=2.7.14 + PYTHON_VER=$(basename $(PYTHON_VERSION)) + + OPENSSL_VERSION_NUMBER=1.0.2 +-OPENSSL_REVISION=n ++OPENSSL_REVISION=u + OPENSSL_VERSION=$(OPENSSL_VERSION_NUMBER)$(OPENSSL_REVISION) + + BZIP2_VERSION=1.0.6 + + # Supported OS +-OS=macOS iOS tvOS watchOS ++OS=macOS iOS iOS-simulator tvOS tvOS-simulator watchOS watchOS-simulator + + # macOS targets +-TARGETS-macOS=macosx.x86_64 ++TARGETS-macOS=macosx.arm64 macosx.x86_64 ++PYTHON_TARGETS-macOS=macOS + CFLAGS-macOS=-mmacosx-version-min=$(MACOSX_DEPLOYMENT_TARGET) + + # iOS targets +-TARGETS-iOS=iphonesimulator.x86_64 iphonesimulator.i386 iphoneos.armv7 iphoneos.armv7s iphoneos.arm64 ++TARGETS-iOS=iphoneos.armv7 iphoneos.armv7s iphoneos.arm64 + CFLAGS-iOS=-mios-version-min=7.0 +-CFLAGS-iphoneos.armv7=-fembed-bitcode +-CFLAGS-iphoneos.armv7s=-fembed-bitcode +-CFLAGS-iphoneos.arm64=-fembed-bitcode ++CFLAGS-iphoneos.armv7= ++CFLAGS-iphoneos.armv7s= ++CFLAGS-iphoneos.arm64= ++ ++# iOS-simulator targets ++TARGETS-iOS-simulator=iphonesimulator.x86_64 iphonesimulator.i386 iphonesimulator.arm64 ++CFLAGS-iOS-simulator=-mios-simulator-version-min=7.0 + + # tvOS targets +-TARGETS-tvOS=appletvsimulator.x86_64 appletvos.arm64 ++TARGETS-tvOS=appletvos.arm64 + CFLAGS-tvOS=-mtvos-version-min=9.0 +-CFLAGS-appletvos.arm64=-fembed-bitcode ++CFLAGS-appletvos.arm64= + PYTHON_CONFIGURE-tvOS=ac_cv_func_sigaltstack=no + ++# tvOS-simulator targets ++TARGETS-tvOS-simulator=appletvsimulator.x86_64 appletvsimulator.arm64 ++CFLAGS-tvOS-simulator=-mtvos-simulator-version-min=9.0 ++ + # watchOS targets +-TARGETS-watchOS=watchsimulator.i386 watchos.armv7k ++TARGETS-watchOS=watchos.armv7k watchos.arm64_32 + CFLAGS-watchOS=-mwatchos-version-min=4.0 +-CFLAGS-watchos.armv7k=-fembed-bitcode ++CFLAGS-watchos.armv7k= ++CFLAGS-watchos.arm64_32= + PYTHON_CONFIGURE-watchOS=ac_cv_func_sigaltstack=no + ++# watchOS-simulator targets ++TARGETS-watchOS-simulator=watchsimulator.i386 watchsimulator.x86_64 watchsimulator.arm64 ++CFLAGS-watchOS-simulator=-mwatchos-simulator-version-min=4.0 ++ + # override machine types for arm64 + MACHINE_DETAILED-arm64=aarch64 + MACHINE_SIMPLE-arm64=arm +@@ -194,9 +211,11 @@ endif + + # Configure the build + ifeq ($2,macOS) ++ # Patch openssl-darwin-arm64 ++ cd $$(OPENSSL_DIR-$1) && git apply ../../../../openssl-1.0.2n-darwin-arm64.patch + cd $$(OPENSSL_DIR-$1) && \ + CC="$$(CC-$1)" MACOSX_DEPLOYMENT_TARGET=$$(MACOSX_DEPLOYMENT_TARGET) \ +- ./Configure darwin64-x86_64-cc --openssldir=$(PROJECT_DIR)/build/$2/openssl ++ ./Configure darwin64-$$(ARCH-$1)-cc --openssldir=$(PROJECT_DIR)/build/$2/openssl + else + cd $$(OPENSSL_DIR-$1) && \ + CC="$$(CC-$1)" \ +@@ -216,7 +235,10 @@ $$(OPENSSL_DIR-$1)/libssl.a $$(OPENSSL_DIR-$1)/libcrypto.a: $$(OPENSSL_DIR-$1)/M + CC="$$(CC-$1)" \ + CROSS_TOP="$$(dir $$(SDK_ROOT-$1)).." \ + CROSS_SDK="$$(notdir $$(SDK_ROOT-$1))" \ +- make all && make install ++ make build_libs && \ ++ mkdir -p "$(PROJECT_DIR)/build/$2/openssl/lib" && \ ++ cp libcrypto.a libssl.a "$(PROJECT_DIR)/build/$2/openssl/lib" ++ -cd $$(OPENSSL_DIR-$1) && make install_sw 2> /dev/null + + # Unpack BZip2 + $$(BZIP2_DIR-$1)/Makefile: downloads/bzip2-$(BZIP2_VERSION).tgz diff --git a/protocols/Telegram/tdlib/td/example/ios/README.md b/protocols/Telegram/tdlib/td/example/ios/README.md index 25a1e68fcc..00d4312be4 100644 --- a/protocols/Telegram/tdlib/td/example/ios/README.md +++ b/protocols/Telegram/tdlib/td/example/ios/README.md @@ -1,18 +1,19 @@ -# Build for iOS +# Universal XCFramework build example 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). +If you need only a macOS build for the current architecture, take a look at [TDLib build instructions generator](https://tdlib.github.io/td/build.html). 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): +* Install the latest Xcode via `xcode-select --install` or downloading it from [Xcode website](https://developer.apple.com/xcode/). + It is not enough to install only command line developer tools to build `TDLib` for iOS. +* Install other build dependencies using [Homebrew](https://brew.sh): ``` -brew install gperf cmake +brew install gperf cmake coreutils ``` -* If you don't want to build `TDLib` for macOS, you can pregenerate required source code files using CMake prepare_cross_compiling target: +* If you don't want to build `TDLib` for macOS first, you **must** pregenerate required source code files using `CMake` prepare_cross_compiling target: ``` cd <path to TDLib sources> mkdir native-build @@ -20,22 +21,26 @@ cd native-build cmake .. cmake --build . --target prepare_cross_compiling ``` -* Build OpenSSL for iOS, watchOS, tvOS and macOS: +* 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: +Here we use scripts from [Python Apple support](https://github.com/beeware/Python-Apple-support), but any other OpenSSL build should work too. +[Python Apple support](https://github.com/beeware/Python-Apple-support) has known problems with spaces in the path to the current directory, so +you need to ensure that there are no spaces in the path. +Built OpenSSL libraries should be stored in the directory `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. +This may take a while, because TDLib will be built about 16 times. +Resulting XCFramework will work on any architecture 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. +Built libraries and XCFramework will be stored in `tdjson` directory. Documentation for all available classes and methods can be found at https://core.telegram.org/tdlib/docs. + +If you receive an "error: SDK "appletvsimulator" cannot be located", you need to run the command "sudo xcode-select -s /Applications/Xcode.app/Contents/Developer" before running ./build.sh. diff --git a/protocols/Telegram/tdlib/td/example/ios/build-openssl.sh b/protocols/Telegram/tdlib/td/example/ios/build-openssl.sh index 2ad9dbcfee..eac937caa8 100644 --- a/protocols/Telegram/tdlib/td/example/ios/build-openssl.sh +++ b/protocols/Telegram/tdlib/td/example/ios/build-openssl.sh @@ -1,22 +1,37 @@ #!/bin/sh +cd $(dirname $0) -git clone https://github.com/pybee/Python-Apple-support +git clone https://github.com/beeware/Python-Apple-support cd Python-Apple-support -git checkout 2.7 +git checkout 60b990128d5f1f04c336ff66594574515ab56604 +git apply ../Python-Apple-support.patch 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 + if [[ $platform = "macOS" ]]; then + simulators="0" + else + simulators="0 1" + fi + + for simulator in $simulators; + do + if [[ $simulator = "1" ]]; then + platform="${platform}-simulator" + fi + echo $platform + cd Python-Apple-support + #NB: -j will fail + make OpenSSL-$platform || exit 1 + cd .. + rm -rf third_party/openssl/$platform || exit 1 + mkdir -p third_party/openssl/$platform/lib || exit 1 + cp ./Python-Apple-support/build/$platform/libcrypto.a third_party/openssl/$platform/lib/ || exit 1 + cp ./Python-Apple-support/build/$platform/libssl.a third_party/openssl/$platform/lib/ || exit 1 + cp -r ./Python-Apple-support/build/$platform/openssl/include/ third_party/openssl/$platform/include || exit 1 + done done diff --git a/protocols/Telegram/tdlib/td/example/ios/build.sh b/protocols/Telegram/tdlib/td/example/ios/build.sh index 9970008a1c..cd11907b2d 100644 --- a/protocols/Telegram/tdlib/td/example/ios/build.sh +++ b/protocols/Telegram/tdlib/td/example/ios/build.sh @@ -1,74 +1,90 @@ -#/bin/sh -td_path=$(realpath ../..) +#!/bin/sh +cd $(dirname $0) +td_path=$(grealpath ../..) 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}) +set_cmake_options () { + # Set CMAKE options depending on platform passed $1 + openssl_path=$(grealpath ../third_party/openssl/$1) echo "OpenSSL path = ${openssl_path}" openssl_crypto_library="${openssl_path}/lib/libcrypto.a" openssl_ssl_library="${openssl_path}/lib/libssl.a" + options="" options="$options -DOPENSSL_FOUND=1" options="$options -DOPENSSL_CRYPTO_LIBRARY=${openssl_crypto_library}" - #options="$options -DOPENSSL_SSL_LIBRARY=${openssl_ssl_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" +} + +platforms="macOS iOS watchOS tvOS" +#platforms="watchOS" +for platform in $platforms; +do + echo "Platform = ${platform}" if [[ $platform = "macOS" ]]; then + simulators="0" + else + simulators="0 1" + fi + + for simulator in $simulators; + do + if [[ $platform = "macOS" ]]; then + other_options="-DCMAKE_OSX_ARCHITECTURES='x86_64;arm64'" + else + if [[ $platform = "watchOS" ]]; then + ios_platform="WATCH" + elif [[ $platform = "tvOS" ]]; then + ios_platform="TV" + else + ios_platform="" + fi + + if [[ $simulator = "1" ]]; then + platform="${platform}-simulator" + ios_platform="${ios_platform}SIMULATOR" + else + ios_platform="${ios_platform}OS" + fi + + echo "iOS platform = ${ios_platform}" + other_options="-DIOS_PLATFORM=${ios_platform} -DCMAKE_TOOLCHAIN_FILE=${td_path}/CMake/iOS.cmake" + fi + + set_cmake_options $platform 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} + cmake $td_path $options $other_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 + install_name_tool -id @rpath/libtdjson.dylib ${install}/lib/libtdjson.dylib + mkdir -p ../tdjson/${platform}/include + rsync --recursive ${install}/include/ ../tdjson/${platform}/include/ + mkdir -p ../tdjson/${platform}/lib + cp ${install}/lib/libtdjson.dylib ../tdjson/${platform}/lib/ + done +done - mkdir -p ../tdjson/$platform/include - rsync --recursive ${install}/include/ ../tdjson/${platform}/include/ - mkdir -p ../tdjson/$platform/lib - cp $platform/libtdjson.dylib ../tdjson/$platform/lib/ +produced_dylibs=(install-*/lib/libtdjson.dylib) +xcodebuild_frameworks=() + +for dylib in "${produced_dylibs[@]}"; +do + xcodebuild_frameworks+=(-library $(grealpath "${dylib}")) done + +# Make xcframework +xcodebuild -create-xcframework \ + "${xcodebuild_frameworks[@]}" \ + -output "libtdjson.xcframework" + +rsync --recursive libtdjson.xcframework ../tdjson/ diff --git a/protocols/Telegram/tdlib/td/example/ios/openssl-1.0.2n-darwin-arm64.patch b/protocols/Telegram/tdlib/td/example/ios/openssl-1.0.2n-darwin-arm64.patch new file mode 100644 index 0000000000..5239d94c32 --- /dev/null +++ b/protocols/Telegram/tdlib/td/example/ios/openssl-1.0.2n-darwin-arm64.patch @@ -0,0 +1,12 @@ +--- Configure 2019-12-20 14:02:41.000000000 +0100 ++++ Configure 2020-11-22 16:23:13.000000000 +0100 +@@ -650,7 +650,9 @@ + "darwin-i386-cc","cc:-arch i386 -O3 -fomit-frame-pointer -DL_ENDIAN::-D_REENTRANT:MACOSX:-Wl,-search_paths_first%:BN_LLONG RC4_INT RC4_CHUNK DES_UNROLL BF_PTR:".eval{my $asm=$x86_asm;$asm=~s/cast\-586\.o//;$asm}.":macosx:dlfcn:darwin-shared:-fPIC -fno-common:-arch i386 -dynamiclib:.\$(SHLIB_MAJOR).\$(SHLIB_MINOR).dylib", + "debug-darwin-i386-cc","cc:-arch i386 -g3 -DL_ENDIAN::-D_REENTRANT:MACOSX:-Wl,-search_paths_first%:BN_LLONG RC4_INT RC4_CHUNK DES_UNROLL BF_PTR:${x86_asm}:macosx:dlfcn:darwin-shared:-fPIC -fno-common:-arch i386 -dynamiclib:.\$(SHLIB_MAJOR).\$(SHLIB_MINOR).dylib", + "darwin64-x86_64-cc","cc:-arch x86_64 -O3 -DL_ENDIAN -Wall::-D_REENTRANT:MACOSX:-Wl,-search_paths_first%:SIXTY_FOUR_BIT_LONG RC4_CHUNK DES_INT DES_UNROLL:".eval{my $asm=$x86_64_asm;$asm=~s/rc4\-[^:]+//;$asm}.":macosx:dlfcn:darwin-shared:-fPIC -fno-common:-arch x86_64 -dynamiclib:.\$(SHLIB_MAJOR).\$(SHLIB_MINOR).dylib", ++"darwin64-arm64-cc","cc:-arch arm64 -O3 -DL_ENDIAN -Wall::-D_REENTRANT:MACOSX:-Wl,-search_paths_first%:SIXTY_FOUR_BIT_LONG RC4_CHUNK DES_INT DES_UNROLL:${no_asm}:dlfcn:darwin-shared:-fPIC -fno-common:-arch arm64 -dynamiclib:.\$(SHLIB_MAJOR).\$(SHLIB_MINOR).dylib", + "debug-darwin64-x86_64-cc","cc:-arch x86_64 -ggdb -g2 -O0 -DL_ENDIAN -Wall::-D_REENTRANT:MACOSX:-Wl,-search_paths_first%:SIXTY_FOUR_BIT_LONG RC4_CHUNK DES_INT DES_UNROLL:".eval{my $asm=$x86_64_asm;$asm=~s/rc4\-[^:]+//;$asm}.":macosx:dlfcn:darwin-shared:-fPIC -fno-common:-arch x86_64 -dynamiclib:.\$(SHLIB_MAJOR).\$(SHLIB_MINOR).dylib", ++"debug-darwin64-arm64-cc","cc:-arch arm64 -ggdb -g2 -O0 -DL_ENDIAN -Wall::-D_REENTRANT:MACOSX:-Wl,-search_paths_first%:SIXTY_FOUR_BIT_LONG RC4_CHUNK DES_INT DES_UNROLL:${no_asm}:dlfcn:darwin-shared:-fPIC -fno-common:-arch arm64 -dynamiclib:.\$(SHLIB_MAJOR).\$(SHLIB_MINOR).dylib", + "debug-darwin-ppc-cc","cc:-DBN_DEBUG -DREF_CHECK -DCONF_DEBUG -DCRYPTO_MDEBUG -DB_ENDIAN -g -Wall -O::-D_REENTRANT:MACOSX::BN_LLONG RC4_CHAR RC4_CHUNK DES_UNROLL BF_PTR:${ppc32_asm}:osx32:dlfcn:darwin-shared:-fPIC:-dynamiclib:.\$(SHLIB_MAJOR).\$(SHLIB_MINOR).dylib", + # iPhoneOS/iOS + "iphoneos-cross","llvm-gcc:-O3 -isysroot \$(CROSS_TOP)/SDKs/\$(CROSS_SDK) -fomit-frame-pointer -fno-common::-D_REENTRANT:macOS:-Wl,-search_paths_first%:BN_LLONG RC4_CHAR RC4_CHUNK DES_UNROLL BF_PTR:${no_asm}:dlfcn:darwin-shared:-fPIC -fno-common:-dynamiclib:.\$(SHLIB_MAJOR).\$(SHLIB_MINOR).dylib", |