Перейти к основному содержимому

How to build Telegram Desktop for Mac OS from source code

· 5 мин. чтения

This is a short guide on how to avoid Git errors when cloning large repositories and build Telegram Desktop for Mac OS faster than in the official guide.

Why not just follow the official guide?

Well, you can precisely follow it — here is the link — but you will encounter these two problems:

  1. git will crash when cloning one of the submodules or third-party libraries required for Telegram Desktop because of an issue with HTTP cloning of large repositories. You might see an error message like this:

Git issue on MacOS

Git crashes when cloning a large repository via HTTP

  1. The preparation script is veeeeery slow.

Here's how to avoid these issues.

Fix cloning large repositories crash

On StackOverflow, you can find some solutions, such as forcing Git to use HTTP/1.1 instead of HTTP/2 and increasing the postBuffer size, but these do not work. The only working solution is to switch from HTTP to SSH cloning.

First, we should check if we already have a pair of SSH keys or need to create a new one.

ls -al ~/.ssh

If the folder is empty, you must create a new SSH key:

ssh-keygen -t ed25519 -C "[email protected]"

Now we should add some SSH configuration for github.com. Open the file in your favorite editor, for example:

nano ~/.ssh/config

And put the following content into the file:

~/.ssh/config
Host github.com
AddKeysToAgent yes
UseKeychain yes
IdentityFile ~/.ssh/id_ed25519

After that, the client configuration is complete, and we should add the SSH public key to GitHub.

Go to https://github.com/settings/keys, click on "New SSH key," and paste the content of ~/.ssh/id_ed25519.pub.

SSH Keys on GitHub

SSH Keys on GitHub

Now you are ready to clone repositories from GitHub using SSH.

Process of Building Telegram Desktop

  1. Run git clone [email protected]:telegramdesktop/tdesktop tdesktop
warning

Note that we removed --recursive from the official guide and changed HTTP cloning to SSH.

  1. Open the .gitmodules file and replace all occurrences of https://github.com/ with [email protected]:.
1/2 Find all occurrences
1/2 Find all occurrences
  1. Run git submodule init && git submodule sync && git submodule update --depth 1

  2. After all submodules are cloned, you need to run the preparation script (tdesktop/Telegram/build/prepare/prepare.py). But before that, you might want to patch it to ensure fast and problem-free third-party library compilation.

    • First, you need to apply this patch to significantly speed up the library cloning process. This allows us to clone only one commit, not the entire library Git index.
    • Second, you need to replace all occurrences of https://github.com/ with [email protected]: (to fix the Git issue we discussed above).
  3. Run ./tdesktop/Telegram/build/prepare/mac.sh

  4. Switch to the tdesktop/Telegram folder and run ./configure.sh -D TDESKTOP_API_ID=some_id -D TDESKTOP_API_HASH=some_hash. API credentials can be retrieved here.

Осторожно

Or you can use the official ones at your own risk (it's against the ToS): ./configure.sh -D TDESKTOP_API_ID=2040 -D TDESKTOP_API_HASH=b18441a1ff607e10a989891a5462e627

  1. Open the tdesktop/out/Telegram.xcodeproj file in Xcode.

  2. Select the Telegram scheme, then click on "Edit scheme" and change the build configuration to "Release".

1/3 Select "Telegram" build scheme
1/3 Select "Telegram" build scheme
  1. Select Product > Build For > Running

  2. Move tdesktop/out/Release/Telegram.dmg to ~/Applications

That's it!

final.png