2021-09-06 13:12:11 +02:00
# Universal XCFramework build example
2018-02-14 11:19:12 +01:00
2018-02-14 22:41:26 +01:00
Below are instructions for building TDLib for iOS, watchOS, tvOS, and also macOS.
2018-02-14 11:29:54 +01:00
2021-09-06 12:58:13 +02:00
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 ).
2018-02-14 11:29:54 +01:00
2018-02-14 22:41:26 +01:00
For example of usage take a look at our [Swift example ](https://github.com/tdlib/td/tree/master/example/swift ).
2018-02-14 11:19:12 +01:00
2018-02-14 22:41:26 +01:00
To compile `TDLib` you will need to:
2018-10-29 23:26:22 +01:00
* 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 ):
2018-02-14 11:19:12 +01:00
```
2018-10-29 23:26:22 +01:00
brew install gperf cmake coreutils
2018-02-14 22:41:26 +01:00
```
2021-07-15 23:53:22 +02:00
* If you don't want to build `TDLib` for macOS first, you **must** pregenerate required source code files using `CMake` prepare_cross_compiling target:
2018-02-14 22:41:26 +01:00
```
cd < path to TDLib sources >
mkdir native-build
cd native-build
cmake ..
cmake --build . --target prepare_cross_compiling
```
2021-09-06 13:12:11 +02:00
* Build OpenSSL for iOS, watchOS, tvOS, and macOS:
2018-02-14 22:41:26 +01:00
```
cd < path to TDLib sources > /example/ios
2018-02-14 11:19:12 +01:00
./build-openssl.sh
```
2021-09-06 12:58:13 +02:00
Here we use scripts from [Python Apple support ](https://github.com/beeware/Python-Apple-support ), but any other OpenSSL build should work too.
2021-09-03 08:25:14 +02:00
[Python Apple support ](https://github.com/beeware/Python-Apple-support ) has known problems with spaces in the path to the current directory, so
2021-09-06 12:58:13 +02:00
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.
2021-09-06 13:12:11 +02:00
* Build TDLib for iOS, watchOS, tvOS, and macOS:
2018-02-14 11:19:12 +01:00
```
2018-02-14 22:41:26 +01:00
cd < path to TDLib sources > /example/ios
2018-02-14 11:19:12 +01:00
./build.sh
```
2021-09-06 12:58:13 +02:00
This may take a while, because TDLib will be built about 16 times.
2021-09-06 13:12:11 +02:00
Resulting XCFramework will work on any architecture and even on a simulator (x64, Apple silicon).
2018-02-14 22:41:26 +01:00
We use [CMake/iOS.cmake ](https://github.com/tdlib/td/blob/master/CMake/iOS.cmake ) toolchain, other toolchains may work too.
2018-02-14 11:19:12 +01:00
2021-09-06 12:58:13 +02:00
Built libraries and XCFramework will be stored in `tdjson` directory.
2018-03-02 01:34:02 +01:00
Documentation for all available classes and methods can be found at https://core.telegram.org/tdlib/docs.
2021-09-06 12:58:13 +02:00
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.