From 7aede75e437503a1f8544051add9636d4da5973f Mon Sep 17 00:00:00 2001
From: 23rd <23rd@vivaldi.net>
Date: Fri, 18 Nov 2022 01:32:18 +0300
Subject: [PATCH] Added external cld3 library.

---
 .gitmodules                                 |  3 ++
 Telegram/ThirdParty/cld3                    |  1 +
 Telegram/build/docker/centos_env/Dockerfile | 23 +++++++++++++
 Telegram/build/prepare/prepare.py           | 37 +++++++++++++++++++++
 Telegram/lib_spellcheck                     |  2 +-
 cmake                                       |  2 +-
 6 files changed, 66 insertions(+), 2 deletions(-)
 create mode 160000 Telegram/ThirdParty/cld3

diff --git a/.gitmodules b/.gitmodules
index 36964946d..052fbbe91 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -97,3 +97,6 @@
 [submodule "Telegram/ThirdParty/kcoreaddons"]
 	path = Telegram/ThirdParty/kcoreaddons
 	url = https://github.com/KDE/kcoreaddons.git
+[submodule "Telegram/ThirdParty/cld3"]
+	path = Telegram/ThirdParty/cld3
+	url = https://github.com/google/cld3.git
diff --git a/Telegram/ThirdParty/cld3 b/Telegram/ThirdParty/cld3
new file mode 160000
index 000000000..b48dc4651
--- /dev/null
+++ b/Telegram/ThirdParty/cld3
@@ -0,0 +1 @@
+Subproject commit b48dc46512566f5a2d41118c8c1116c4f96dc661
diff --git a/Telegram/build/docker/centos_env/Dockerfile b/Telegram/build/docker/centos_env/Dockerfile
index 32eedeaa7..670cf911a 100644
--- a/Telegram/build/docker/centos_env/Dockerfile
+++ b/Telegram/build/docker/centos_env/Dockerfile
@@ -98,6 +98,28 @@ RUN git clone -b v5.2.5 https://git.tukaani.org/xz.git \
 	&& cd .. \
 	&& rm -rf xz
 
+FROM builder AS protobuf
+RUN git clone --recursive -b v21.9 https://github.com/protocolbuffers/protobuf \
+    && cd protobuf \
+    && git clone https://github.com/abseil/abseil-cpp third_party/abseil-cpp \
+    && cd third_party/abseil-cpp \
+    && git checkout 273292d1cf \
+    && cd ../.. \
+    && mkdir build \
+    && cd build \
+    && cmake -GNinja .. \
+    	-DCMAKE_BUILD_TYPE=None \
+		-DCMAKE_C_FLAGS="$CFLAGS" \
+		-DCMAKE_CXX_FLAGS="$CXXFLAGS" \
+        -Dprotobuf_BUILD_TESTS=OFF \
+        -Dprotobuf_BUILD_PROTOBUF_BINARIES=ON \
+        -Dprotobuf_BUILD_LIBPROTOC=ON \
+        -Dprotobuf_WITH_ZLIB_DEFAULT=OFF \
+        -Dprotobuf_DEBUG_POSTFIX="" \
+    && cmake --build . --parallel \
+    && cd .. \
+    && rm -rf .git
+
 FROM patches AS libproxy
 RUN git clone -b 0.4.17 --depth=1 {{ GIT }}/libproxy/libproxy.git \
 	&& cd libproxy \
@@ -759,6 +781,7 @@ FROM builder-base
 COPY --link --from=libffi {{ LibrariesPath }}/libffi-cache /
 COPY --link --from=zlib {{ LibrariesPath }}/zlib-cache /
 COPY --link --from=xz {{ LibrariesPath }}/xz-cache /
+COPY --link --from=protobuf {{ LibrariesPath }}/protobuf protobuf
 COPY --link --from=libproxy {{ LibrariesPath }}/libproxy-cache /
 COPY --link --from=lcms2 {{ LibrariesPath }}/lcms2-cache /
 COPY --link --from=brotli {{ LibrariesPath }}/brotli-cache /
diff --git a/Telegram/build/prepare/prepare.py b/Telegram/build/prepare/prepare.py
index 4a0845381..0f45a420d 100644
--- a/Telegram/build/prepare/prepare.py
+++ b/Telegram/build/prepare/prepare.py
@@ -1390,4 +1390,41 @@ release:
     lipo -create Release.arm64/libtg_owt.a Release.x86_64/libtg_owt.a -output Release/libtg_owt.a
 """)
 
+stage('protobuf', """
+win:
+    git clone --recursive -b v21.9 https://github.com/protocolbuffers/protobuf
+    cd protobuf
+    git clone https://github.com/abseil/abseil-cpp third_party/abseil-cpp
+    cd third_party/abseil-cpp
+    git checkout 273292d1cf
+    cd ../..
+    mkdir build
+    cd build
+    cmake .. ^
+        -A %WIN32X64% ^
+        -Dprotobuf_BUILD_TESTS=OFF ^
+        -Dprotobuf_BUILD_PROTOBUF_BINARIES=ON ^
+        -Dprotobuf_BUILD_LIBPROTOC=ON ^
+        -Dprotobuf_WITH_ZLIB_DEFAULT=OFF ^
+        -Dprotobuf_DEBUG_POSTFIX=""
+    cmake --build . --config Release --parallel
+    cmake --build . --config Debug --parallel
+""")
+# mac:
+#     git clone --recursive -b v21.9 https://github.com/protocolbuffers/protobuf
+#     cd protobuf
+#     git clone https://github.com/abseil/abseil-cpp third_party/abseil-cpp
+#     cd third_party/abseil-cpp
+#     git checkout 273292d1cf
+#     cd ../..
+#     mkdir build
+#     cd build
+#     CFLAGS="$UNGUARDED" CPPFLAGS="$UNGUARDED" cmake .. \
+#         -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=$MACOSX_DEPLOYMENT_TARGET \
+#         -Dprotobuf_BUILD_TESTS=OFF \
+#         -Dprotobuf_BUILD_PROTOBUF_BINARIES=ON \
+#         -Dprotobuf_BUILD_LIBPROTOC=ON \
+#         -Dprotobuf_WITH_ZLIB_DEFAULT=OFF
+#     cmake --build . $MAKE_THREADS_CNT
+
 runStages()
diff --git a/Telegram/lib_spellcheck b/Telegram/lib_spellcheck
index 0e386e22c..4fc3b43c0 160000
--- a/Telegram/lib_spellcheck
+++ b/Telegram/lib_spellcheck
@@ -1 +1 @@
-Subproject commit 0e386e22cb6ba8a114b569840a635e096dcb645e
+Subproject commit 4fc3b43c0608b0b5c807f34f37a60a8078e19c47
diff --git a/cmake b/cmake
index d41ce7f55..5727743f9 160000
--- a/cmake
+++ b/cmake
@@ -1 +1 @@
-Subproject commit d41ce7f553f034f54d0e87643ddfee6d585b6b63
+Subproject commit 5727743f9a3d3f01b275eb77f39e7a24b9671c4d