TDLib

TDLib builds for iOS and Apple platforms

Build OpenSSL, TDLib and an XCFramework for iOS, macOS, watchOS, tvOS and visionOS.

GetTGAPI editorial teamUpdated
TDLib documentationReviewed

Source revision a94b83d67ab4 · TDLib contributors · BSL-1.0

Based on official sources and independently maintained by GetTGAPI. Documentation and glossary →

On this page
  1. Before you start
  2. Universal XCFramework build example

Before you start

Match Xcode, SDKs, architectures and target platforms. xcode-select --install primarily installs command-line tools; an iOS build still needs full Xcode. Check your actual development environment before using the source commands.

Universal XCFramework build example

Below are instructions for building TDLib for iOS, watchOS, tvOS, visionOS, and also macOS.

If you need only a macOS build for the current architecture, take a look at TDLib build instructions generator.

For example of usage take a look at our Swift example.

To compile TDLib you will need to:

  • Install the latest Xcode via xcode-select --install or downloading it from Xcode website. It is not enough to install only command line developer tools to build TDLib for iOS. Xcode >= 14.0 is required to build TDLib for watchOS.
  • Install other build dependencies using Homebrew:
brew install gperf cmake coreutils
  • If you don't want to build TDLib for macOS first, you must pregenerate required source code files in the following way:
cd <path to TDLib sources>
mkdir native-build
cd native-build
cmake -DTD_GENERATE_SOURCE_FILES=ON ..
cmake --build .
  • Build OpenSSL for iOS, watchOS, tvOS, visionOS, and macOS:
cd <path to TDLib sources>/example/ios
./build-openssl.sh

Here we use scripts from Python Apple support, but any other OpenSSL build should work too. 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, visionOS, and macOS:
cd <path to TDLib sources>/example/ios
./build.sh

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 toolchain, other toolchains may work too.

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.

Continue with the TDLib overview. For credentials, follow the API ID and Hash application process. For portal ERROR assistance, contact GetTGAPI support.

Source license and attribution · BSL-1.0

TDLib contributors · Full license file

Boost Software License - Version 1.0 - August 17th, 2003

Permission is hereby granted, free of charge, to any person or organization
obtaining a copy of the software and accompanying documentation covered by
this license (the "Software") to use, reproduce, display, distribute,
execute, and transmit the Software, and to prepare derivative works of the
Software, and to permit third-parties to whom the Software is furnished to
do so, all subject to the following:

The copyright notices in the Software and this entire statement, including
the above license grant, this restriction and the following disclaimer,
must be included in all copies of the Software, in whole or in part, and
all derivative works of the Software, unless such copies or derivative
works are solely in the form of machine-executable object code generated by
a source language processor.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.