1{
2 fetchFromGitHub,
3 gperf,
4 openssl,
5 readline,
6 zlib,
7 cmake,
8 lib,
9 stdenv,
10 writeShellApplication,
11 common-updater-scripts,
12 jq,
13 buildPackages,
14
15 tde2eOnly ? false,
16}:
17
18let
19 updateScript = writeShellApplication {
20 name = "update-tdlib";
21
22 runtimeInputs = [
23 jq
24 common-updater-scripts
25 ];
26
27 text = ''
28 commit_msg="^Update version to (?<v>\\\\d+.\\\\d+.\\\\d+)\\\\.$"
29 commit=$(curl -s "https://api.github.com/repos/tdlib/td/commits?path=CMakeLists.txt" | jq -c "map(select(.commit.message | test(\"''${commit_msg}\"))) | first")
30
31 rev=$(echo "$commit" | jq -r ".sha")
32 version=$(echo "$commit" | jq -r ".commit.message | capture(\"''${commit_msg}\") | .v")
33
34 update-source-version tdlib "$version" --rev="$rev"
35 '';
36 };
37in
38
39stdenv.mkDerivation {
40 pname = if tde2eOnly then "tde2e" else "tdlib";
41 version = "1.8.51";
42
43 src = fetchFromGitHub {
44 owner = "tdlib";
45 repo = "td";
46
47 # The tdlib authors do not set tags for minor versions, but
48 # external programs depending on tdlib constrain the minor
49 # version, hence we set a specific commit with a known version.
50 rev = "bb474a201baa798784d696d2d9d762a9d2807f96";
51 hash = "sha256-Jd2ojDDwO/7W54QjnKLlc1ecqTfJEFPRtT50rNlukKA=";
52 };
53
54 buildInputs = [
55 openssl
56 readline
57 zlib
58 ];
59
60 nativeBuildInputs = [
61 cmake
62 gperf
63 ];
64
65 depsBuildBuild = [ buildPackages.stdenv.cc ];
66
67 preConfigure = lib.optionalString (stdenv.buildPlatform != stdenv.hostPlatform) ''
68 cmake -B native-build \
69 -DCMAKE_C_COMPILER=$CC_FOR_BUILD \
70 -DCMAKE_CXX_COMPILER=$CXX_FOR_BUILD \
71 -DCMAKE_AR=$(command -v $AR_FOR_BUILD) \
72 -DCMAKE_RANLIB=$(command -v $RANLIB_FOR_BUILD) \
73 -DCMAKE_STRIP=$(command -v $STRIP_FOR_BUILD) \
74 -DTD_GENERATE_SOURCE_FILES=ON .
75 cmake --build native-build -j $NIX_BUILD_CORES
76 '';
77
78 cmakeFlags = [
79 (lib.cmakeBool "TD_E2E_ONLY" tde2eOnly)
80 ];
81
82 # https://github.com/tdlib/td/issues/1974
83 postPatch = ''
84 substituteInPlace CMake/GeneratePkgConfig.cmake \
85 --replace 'function(generate_pkgconfig' \
86 'include(GNUInstallDirs)
87 function(generate_pkgconfig' \
88 --replace '\$'{prefix}/'$'{CMAKE_INSTALL_LIBDIR} '$'{CMAKE_INSTALL_FULL_LIBDIR} \
89 --replace '\$'{prefix}/'$'{CMAKE_INSTALL_INCLUDEDIR} '$'{CMAKE_INSTALL_FULL_INCLUDEDIR}
90 ''
91 + lib.optionalString (stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isAarch64) ''
92 sed -i "/vptr/d" test/CMakeLists.txt
93 '';
94
95 passthru.updateScript = lib.getExe updateScript;
96
97 meta = with lib; {
98 description = "Cross-platform library for building Telegram clients";
99 homepage = "https://core.telegram.org/tdlib/";
100 license = [ licenses.boost ];
101 platforms = platforms.unix;
102 maintainers = [
103 maintainers.vyorkin
104 maintainers.vonfry
105 ];
106 };
107}