# Copyright 1999-2025 Gentoo Authors # Distributed under the terms of the GNU General Public License v2 EAPI=8 inherit xdg cmake optfeature flag-o-matic inherit patches # ^ TODO: drop before moving to gentoo repo, and port to manual selection inherit git-r3 # ^ TODO: conditional (only for 9999)? maybe port to tarballs before moving to gentoo repo. EGIT_REPO_URI="https://github.com/telegramdesktop/tdesktop.git" EGIT_SUBMODULES=( '*' -Telegram/ThirdParty/{xxHash,Catch,lz4,libdbusmenu-qt,fcitx{5,}-qt{,5},hime,hunspell,nimf,qt5ct,range-v3,jemalloc,wayland-protocols,plasma-wayland-protocols,xdg-desktop-portal,GSL,kimageformats,kcoreaddons} # ???? buildsystem anyway uses system ms-gsl if it is installed, so, no need for bundled, imho ???? -Telegram/ThirdParty/libtgvoip # ???? devs said it is not used anymore (but I found that it's submodule is still in the repo) ) DESCRIPTION="Official desktop client for Telegram" HOMEPAGE="https://desktop.telegram.org" LICENSE="GPL-3-with-openssl-exception" SLOT="0" if [[ "${PV}" = 9999* ]]; then EGIT_BRANCH="dev" else # TODO: tarballs EGIT_COMMIT="v${PV}" fi # ???? kludge for eix [[ "${PV}" = 9999* ]] || KEYWORDS="~amd64 ~arm ~arm64 ~loong ~ppc64 ~riscv ~x86" # ???? kludge for eix IUSE="custom-api-id +dbus debug enchant +fonts +hunspell +jemalloc lto pipewire pulseaudio +screencast test +wayland +webkit +X" # +system-gsl REQUIRED_USE=" ^^ ( enchant hunspell ) " MYPATCHES=( "allow-disable-stories" "hide-banned" "hide-sponsored-messages" "wide-baloons" "chat-ids" "increase-limits" "ignore-restrictions" ) USE_EXPAND_VALUES_TDESKTOP_PATCHES="${MYPATCHES[@]}" for p in ${MYPATCHES[@]}; do IUSE="${IUSE} tdesktop_patches_${p}" done COMMON_DEPEND=" !net-im/telegram-desktop-bin app-arch/lz4:= >=dev-cpp/abseil-cpp-20240116.2:= dev-cpp/ada dev-libs/boost:= >=dev-libs/glib-2.77:2 >=dev-libs/gobject-introspection-1.77 dev-libs/libdispatch dev-libs/libfmt:= dev-libs/openssl:= >=dev-libs/protobuf-27.2 dev-libs/xxhash >=dev-qt/qtbase-6.5:6=[dbus?,gui,network,opengl,wayland?,widgets,X?] >=dev-qt/qtimageformats-6.5:6= >=dev-qt/qtsvg-6.5:6= enchant? ( app-text/enchant:= ) !fonts? ( media-fonts/open-sans ) hunspell? ( >=app-text/hunspell-1.7:= ) jemalloc? ( dev-libs/jemalloc:=[-lazy-lock] ) kde-frameworks/kcoreaddons:6= kde-frameworks/kimageformats:6=[avif,heif,jpegxl] media-libs/fontconfig:= media-libs/libjpeg-turbo:= media-libs/openal:=[pipewire=] media-libs/opus:= media-libs/rnnoise:= >=media-libs/tg_owt-0_pre20250501:=[pipewire(+)=,screencast=,X=] media-video/ffmpeg:=[opus,vpx] sys-apps/xdg-desktop-portal:= sys-libs/zlib:=[minizip] virtual/opengl pulseaudio? ( !pipewire? ( media-sound/pulseaudio-daemon ) ) pipewire? ( media-video/pipewire[sound-server(+)] !media-sound/pulseaudio-daemon ) wayland? ( >=dev-qt/qtwayland-6.5:6=[compositor,qml] kde-plasma/kwayland:= dev-libs/wayland-protocols:= dev-libs/plasma-wayland-protocols:= ) webkit? ( wayland? ( >=dev-qt/qtdeclarative-6.5:6 >=dev-qt/qtwayland-6.5:6[compositor] ) ) X? ( x11-libs/libxcb:= x11-libs/xcb-util-keysyms ) " # dev-libs/libsigc++:2 # >=dev-cpp/glibmm-2.77:2.68 RDEPEND=" ${COMMON_DEPEND} webkit? ( || ( net-libs/webkit-gtk:4.1 net-libs/webkit-gtk:6 ) ) " DEPEND=" ${COMMON_DEPEND} >=dev-cpp/cppgir-2.0_p20240315 dev-cpp/range-v3 net-libs/tdlib:=[e2e-private-stuff] " # ????tdlib builds static libs, and so tdesktop links statically, so, no need to be in RDEPEND # # system-expected? ( dev-cpp/expected-lite ) # system-gsl? ( >=dev-cpp/ms-gsl-4.1 ) # ???? currently it's buildsystem anyway uses system one if it is anyhow installed BDEPEND=" amd64? ( dev-lang/yasm ) >=dev-build/cmake-3.16 >=dev-cpp/cppgir-2.0_p20240315 >=dev-cpp/ms-gsl-4.1 dev-util/gdbus-codegen virtual/pkgconfig wayland? ( dev-util/wayland-scanner ) " # dev-cpp/cld3:= # dev-libs/qr-code-generator:= RESTRICT="!test? ( test )" pkg_pretend() { for p in ${MYPATCHES[@]}; do if use "tdesktop_patches_${p}"; then tdesktop_patches_warn=1 fi done if [[ -n "${tdesktop_patches_warn}" ]]; then ewarn "!!!!!!!!!!!!!!!!!!!!!!!!!" ewarn "!!!!!!!! WARNING !!!!!!!" ewarn "!!!!!!!!!!!!!!!!!!!!!!!!!" ewarn "You have enabled some custom patches!" ewarn "Some of them can violate TOS of Telegram and can (but non necessary will) lead to ban of your account on TG main network." ewarn "Please, be careful." einfo "Also, note that none of that patches have any chance to be ported to ${PN} ebuild in Gentoo repo" fi if use custom-api-id; then if [[ -n "${TELEGRAM_CUSTOM_API_ID}" ]] && [[ -n "${TELEGRAM_CUSTOM_API_HASH}" ]]; then einfo "" einfo "${P} was built with your custom ApiId and ApiHash" einfo "" else eerror "" eerror "It seems you did not set one or both of TELEGRAM_CUSTOM_API_ID and TELEGRAM_CUSTOM_API_HASH variables," eerror "which are required for custom-api-id USE-flag." eerror "You can set them either in:" eerror "- /etc/portage/make.conf (globally, so all applications you'll build will see that ID and HASH" eerror "- /etc/portage/env/${CATEGORY}/${PN} (privately for this package builds)" eerror "" die "You should correctly set both TELEGRAM_CUSTOM_API_ID and TELEGRAM_CUSTOM_API_HASH variables" fi fi # if use system-rlottie; then # eerror "" # eerror "Currently, ${PN} is totally incompatible with Samsung's rlottie, and uses custom bundled fork." # eerror "Build will definitelly fail. You've been warned!" # eerror "Even if you have custom patches to make it build, there is another issue:" # ewarn "" # ewarn "Unfortunately, ${PN} uses custom modifications over rlottie" # ewarn "(which aren't accepted by upstream, since they made it another way)." # ewarn "This leads to following facts:" # ewarn " - Colors replacement maps are not working when you link against system rlottie package." # ewarn " That means, for example, that 'giant animated emojis' will ignore skin-tone colors" # ewarn " and will always be yellow" # ewarn " Ref: https://github.com/Samsung/rlottie/pull/252" # ewarn " - Crashes on some stickerpacks" # ewarn " Probably related to: https://github.com/Samsung/rlottie/pull/262" # ewarn "" # fi if has ccache ${FEATURES}; then ewarn "ccache does not work with ${PN} out of the box" ewarn "due to usage of precompiled headers" ewarn "check bug https://bugs.gentoo.org/715114 for more info" ewarn fi } src_unpack() { # use system-gsl && EGIT_SUBMODULES+=(-Telegram/ThirdParty/GSL) # # XXX: maybe de-unbundle those? Anyway, they're header-only libraries... # # Moreover, upstream recommends to use bundled versions to avoid artefacts ???? # use system-expected && EGIT_SUBMODULES+=(-Telegram/ThirdParty/expected) ( use arm && ! use arm64 ) || EGIT_SUBMODULES+=(-Telegram/ThirdParty/dispatch) # use system-rlottie && EGIT_SUBMODULES+=(-Telegram/{lib_rlottie,ThirdParty/rlottie}) # ^ Ref: https://bugs.gentoo.org/752417 git-r3_src_unpack } src_prepare() { # use system-rlottie || ( # # Ref: https://bugs.gentoo.org/752417 # sed -i \ # -e 's/DESKTOP_APP_USE_PACKAGED/0/' \ # cmake/external/rlottie/CMakeLists.txt || die # ) # # Bundle kde-frameworks/kimageformats for qt6, since it's impossible to # # build in gentoo right now. # if use qt6-imageformats; then # sed -e 's/DESKTOP_APP_USE_PACKAGED_LAZY/TRUE/' -i \ # cmake/external/kimageformats/CMakeLists.txt || die # printf "%s\n" \ # 'Q_IMPORT_PLUGIN(QAVIFPlugin)' \ # 'Q_IMPORT_PLUGIN(HEIFPlugin)' \ # 'Q_IMPORT_PLUGIN(QJpegXLPlugin)' \ # >> cmake/external/qt/qt_static_plugins/qt_static_plugins.cpp || die # fi # Happily fail if libraries aren't found... find -type f \( -name 'CMakeLists.txt' -o -name '*.cmake' \) \ \! -path './Telegram/lib_webview/CMakeLists.txt' \ \! -path "./cmake/external/expected/CMakeLists.txt" \ \! -path './cmake/external/kcoreaddons/CMakeLists.txt' \ \! -path './cmake/external/lz4/CMakeLists.txt' \ \! -path './cmake/external/opus/CMakeLists.txt' \ \! -path './cmake/external/xxhash/CMakeLists.txt' \ \! -path './cmake/external/qt/package.cmake' \ \! -path './Telegram/lib_webview/CMakeLists.txt' \ -print0 | xargs -0 sed -i \ -e '/pkg_check_modules(/s/[^ ]*)/REQUIRED &/' \ -e '/find_package(/s/)/ REQUIRED)/' || die # \! -path './cmake/external/kimageformats/CMakeLists.txt' \ # Make sure to check the excluded files for new # CMAKE_DISABLE_FIND_PACKAGE entries. # Control QtDBus dependency from here, to avoid messing with QtGui. if ! use dbus; then sed -e '/find_package(Qt[^ ]* OPTIONAL_COMPONENTS/s/DBus *//' \ -i cmake/external/qt/package.cmake || die fi # HACK: tmp (nothing is more persistent than temporary, hehe) sed -r \ -e '1i#include ' \ -i "${S}/Telegram/SourceFiles/payments/smartglocal/smartglocal_card.h" \ "${S}/Telegram/SourceFiles/payments/smartglocal/smartglocal_error.h" || die # Use system xdg-portal things sed -r \ -e '/generate_dbus\([^ ]*\ org.freedesktop.portal/{s@\$\{third_party_loc\}/xdg-desktop-portal/data@/usr/share/dbus-1/interfaces@}' \ -i "${S}/Telegram/lib_base/CMakeLists.txt" "${S}/Telegram/CMakeLists.txt" || die # Control automagic dep only needed when USE="webkit wayland" if ! use webkit || ! use wayland; then sed -e 's/QT_CONFIG(wayland_compositor_quick)/0/' \ -i Telegram/lib_webview/webview/platform/linux/webview_linux_compositor.h || die fi patches_src_prepare # cmake_src_prepare # ^ to be used when will be ported to gentoo repo } src_configure() { append-flags '-fpch-preprocess' # ccache compatibility. # ^ see https://bugs.gentoo.org/715114 # Having user paths sneak into the build environment through the # XDG_DATA_DIRS variable causes all sorts of weirdness with cppgir: # - bug 909038: can't read from flatpak directories (fixed upstream) # - bug 920819: system-wide directories ignored when variable is set export XDG_DATA_DIRS="${EPREFIX}/usr/share" # Evil flag (bug #919201) filter-flags -fno-delete-null-pointer-checks # The ABI of media-libs/tg_owt breaks if the -DNDEBUG flag doesn't keep # the same state across both projects. # See https://bugs.gentoo.org/866055 filter-flags '-DDEBUG' # produces bugs in bundled forks of 3party code append-cppflags '-DNDEBUG' # Telegram sets that in code use lto && ( append-flags '-flto' append-ldflags '-flto' ) local mycxxflags=( ${CXXFLAGS} -Wno-error=deprecated-declarations -Wno-deprecated-declarations -Wno-switch -DLIBDIR="$(get_libdir)" -DTDESKTOP_DISABLE_AUTOUPDATE # XXX: temp (I hope) kludge (until abseil-cpp-2025+ will be in tree) -I/usr/include/tg_owt/third_party/abseil-cpp ) local no_webkit_wayland=$(use webkit && use wayland && echo no || echo yes) local use_webkit_wayland=$(use webkit || use wayland && echo yes || echo no) local mycmakeargs=( -DQT_VERSION_MAJOR=6 # Override new cmake.eclass defaults (https://bugs.gentoo.org/921939) # Upstream never tests this any other way -DCMAKE_DISABLE_PRECOMPILE_HEADERS=OFF # Control automagic dependencies on certain packages ## Header-only lib, some git version. -DCMAKE_DISABLE_FIND_PACKAGE_tl-expected=ON # Control automagic dependencies on certain packages ## These libraries are only used in lib_webview, for wayland ## See Telegram/lib_webview/webview/platform/linux/webview_linux_compositor.h -DCMAKE_DISABLE_FIND_PACKAGE_Qt6Quick=${no_webkit_wayland} -DCMAKE_DISABLE_FIND_PACKAGE_Qt6QuickWidgets=${no_webkit_wayland} -DCMAKE_DISABLE_FIND_PACKAGE_Qt6WaylandCompositor=${no_webkit_wayland} -DCMAKE_DISABLE_FIND_PACKAGE_Qt6WaylandClient=$(usex !wayland) # Make sure dependencies that aren't patched to be REQUIRED in # src_prepare, are found. This was suggested to me by the telegram # devs, in lieu of having explicit flags in the build system. -DCMAKE_REQUIRE_FIND_PACKAGE_Qt6DBus=$(usex dbus) -DCMAKE_REQUIRE_FIND_PACKAGE_Qt6Quick=${use_webkit_wayland} -DCMAKE_REQUIRE_FIND_PACKAGE_Qt6QuickWidgets=${use_webkit_wayland} -DCMAKE_REQUIRE_FIND_PACKAGE_Qt6WaylandCompositor=${use_webkit_wayland} # -DCMAKE_DISABLE_FIND_PACKAGE_KF6CoreAddons=ON -DCMAKE_CXX_FLAGS:="${mycxxflags[*]}" # Upstream does not need crash reports from custom builds anyway -DDESKTOP_APP_DISABLE_CRASH_REPORTS=ON -DDESKTOP_APP_USE_ENCHANT=$(usex enchant) # enables enchant and disables hunspell # Unbundling: -DDESKTOP_APP_USE_PACKAGED=ON # Main -DDESKTOP_APP_DISABLE_X11_INTEGRATION=$(usex !X) # -DDESKTOP_APP_DISABLE_WAYLAND_INTEGRATION="$(usex !wayland)" -DDESKTOP_APP_DISABLE_JEMALLOC=$(usex !jemalloc) $(usex lto "-DCMAKE_INTERPROCEDURAL_OPTIMIZATION=ON" '') -DTDESKTOP_API_TEST=$(usex test) ## Use system fonts instead of bundled ones -DDESKTOP_APP_USE_PACKAGED_FONTS=$(usex !fonts) # Snapcraft (snap, flatpack, whatever) API keys: # As of my discussion with John Preston, he specifically asked TG servers owners to never ban snap's keys: # TODO: (!!!!!!!) Ask Gentoo Council (or whatever) to get "official" Gentoo keys. -DTDESKTOP_API_ID=$(usex custom-api-id "${TELEGRAM_CUSTOM_API_ID}" "611335") -DTDESKTOP_API_HASH=$(usex custom-api-id "${TELEGRAM_CUSTOM_API_HASH}" "d524b414d21f4d37f08684c1df41ac9c") -DDESKTOP_APP_DISABLE_QT_PLUGINS=ON # -DDESKTOP_APP_LOTTIE_USE_CACHE=NO # # in case of caching bugs. Maybe also useful with system-rlottie[cache]. TODO: test that idea. ) cmake_src_configure } src_compile() { # There's a bug where sometimes, it will rebuild/relink during src_install # Make sure that happens here, instead. cmake_build cmake_build } pkg_preinst() { xdg_pkg_preinst } pkg_postinst() { xdg_pkg_postinst if ! use X && ! use screencast; then ewarn "both the 'X' and 'screencast' USE flags are disabled, screen sharing won't work!" ewarn fi if ! use jemalloc && use elibc_glibc; then # https://github.com/telegramdesktop/tdesktop/issues/16084 # https://github.com/desktop-app/cmake_helpers/pull/91#issuecomment-881788003 ewarn "Disabling USE=jemalloc on glibc systems may cause very high RAM usage!" ewarn "Do NOT report issues about RAM usage without enabling this flag first." ewarn fi optfeature_header optfeature "AVIF, HEIF and JpegXL image support" kde-frameworks/kimageformats[avif,heif,jpegxl] } pkg_postrm() { xdg_pkg_postrm }