How to build Telegram Desktop for Mac OS from source code
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:
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:
- 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:
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
.
Now you are ready to clone repositories from GitHub using SSH
.
Process of Building Telegram Desktop
- Run
git clone [email protected]:telegramdesktop/tdesktop tdesktop
Note that we removed --recursive
from the official guide and changed HTTP cloning to SSH.
- Open the
.gitmodules
file and replace all occurrences ofhttps://github.com/
with[email protected]:
.
-
Run
git submodule init && git submodule sync && git submodule update --depth 1
-
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).
-
Run
./tdesktop/Telegram/build/prepare/mac.sh
-
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
-
Open the
tdesktop/out/Telegram.xcodeproj
file in Xcode. -
Select the
Telegram
scheme, then click on "Edit scheme" and change the build configuration to "Release".
-
Select Product > Build For > Running
-
Move
tdesktop/out/Release/Telegram.dmg
to~/Applications
That's it!