trpc-group / trpc-cpp

A pluggable, high-performance RPC framework written in cpp
Other
286 stars 81 forks source link

Fails to compile on Arch with gcc-14.2 #166

Closed zhangyi1357 closed 4 days ago

zhangyi1357 commented 3 months ago

What version of tRPC-Cpp are you using?

v1.2.0

What operating system and compiler are you using?

OS: Arch Linux on Windows 10 x86_64 Kernel: 5.15.133.1-microsoft-standard-WSL2 Compiler: g++ (GCC) 14.2.1 20240802

What did you do?

After cloning the project just run the following command under project root directory.

mkdir -p build && cd build && cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS=ON .. && make -j8 && cd -
mkdir -p examples/helloworld/build && cd examples/helloworld/build &&cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS=ON .. && make -j8 && cd -

What did you expect to see?

No compilation errors.

What did you see instead?

Just show the core errors:

  1. Non-compiling assignment operator related issue: https://github.com/Tencent/rapidjson/issues/718. it was fixed 8 years ago, but not a new release has been published and trpc-cpp uses 8 years old rapidjson@v1.1.0 (the newest release, lmao) without the fixed.
/home/zy/learning/trpc-cpp/cmake_third_party/rapidjson/include/rapidjson/document.h: In member function ‘rapidjson::GenericStringRef<CharType>& rapidjson::GenericStringRef<CharType>::operator=(const rapidjson::GenericStringRef<CharType>&)’:
/home/zy/learning/trpc-cpp/cmake_third_party/rapidjson/include/rapidjson/document.h:319:82: error: assignment of read-only member ‘rapidjson::GenericStringRef<CharType>::length’
  319 |     GenericStringRef& operator=(const GenericStringRef& rhs) { s = rhs.s; length = rhs.length; }
      |                                                                           ~~~~~~~^~~~~~~~~~~~
  1. Wrong use of std::negation_v
/home/zy/learning/trpc-cpp/trpc/config/trpc_conf_compatible.h:44:47: error: wrong number of template arguments (2, should be 1)
   44 |   if constexpr (std::negation_v<T, Json::Value> && std::negation_v<T, YAML::Node> &&
      |                                               ^
In file included from /usr/lib/gcc/x86_64-pc-linux-gnu/14.2.1/../../../../include/c++/14.2.1/bits/stl_pair.h:60,
                 from /usr/lib/gcc/x86_64-pc-linux-gnu/14.2.1/../../../../include/c++/14.2.1/bits/stl_algobase.h:64:
/usr/lib/gcc/x86_64-pc-linux-gnu/14.2.1/../../../../include/c++/14.2.1/type_traits:271:27: note: provided for ‘template<class _Pp> constexpr const bool std::negation_v<_Pp>’
  271 |     inline constexpr bool negation_v = negation<_Pp>::value;
      |                           ^~~~~~~~~~
/home/zy/learning/trpc-cpp/trpc/config/trpc_conf_compatible.h:44:81: error: wrong number of template arguments (2, should be 1)
   44 |   if constexpr (std::negation_v<T, Json::Value> && std::negation_v<T, YAML::Node> &&
      |                                                                                 ^
/usr/lib/gcc/x86_64-pc-linux-gnu/14.2.1/../../../../include/c++/14.2.1/type_traits:271:27: note: provided for ‘template<class _Pp> constexpr const bool std::negation_v<_Pp>’
  271 |     inline constexpr bool negation_v = negation<_Pp>::value;

Full build log: build.log

How to fix

I'd like to fix above compilation problems.

For error 1, just do a patch on rapidjson like what has been done for spdlog.

For error 2, just do the following change:

diff --git a/trpc/config/trpc_conf_compatible.h b/trpc/config/trpc_conf_compatible.h
index e1eb5b2..e9125c1 100644
--- a/trpc/config/trpc_conf_compatible.h
+++ b/trpc/config/trpc_conf_compatible.h
@@ -41,8 +41,8 @@ std::optional<T> LoadConfig(const std::string& plugin_name, const std::string& c
                             const std::any& params = nullptr) {
   std::optional<T> ret;
   // Determine the type of support
-  if constexpr (std::negation_v<T, Json::Value> && std::negation_v<T, YAML::Node> &&
-                std::negation_v<T, std::map<std::string, std::string> >) {
+  if constexpr (std::negation_v<std::is_same<T, Json::Value>> && std::negation_v<std::is_same<T, YAML::Node>> &&
+                std::negation_v<std::is_same<T, std::map<std::string, std::string>>>) {
     TRPC_LOG_ERROR("Unknown type!");
     return ret;
   }
zhangyi1357 commented 3 months ago

When I tried to fix the issue, another problem with GoogleTest comes up.

In file included from /home/zy/learning/my-trpc-cpp/cmake_third_party/gtest/googletest/src/gtest-all.cc:42:
/home/zy/learning/my-trpc-cpp/cmake_third_party/gtest/googletest/src/gtest-death-test.cc: In function ‘bool testing::internal::StackGrowsDown()’:
/home/zy/learning/my-trpc-cpp/cmake_third_party/gtest/googletest/src/gtest-death-test.cc:1301:24: error: ‘dummy’ may be used uninitialized [-Werror=maybe-uninitialized]
 1301 |   StackLowerThanAddress(&dummy, &result);
      |   ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~

It has been solved by https://github.com/google/googletest/pull/3024, we only need to update GoogleTest to use version 1.11.0 or newer.

weimch commented 3 months ago

When using cc_proto_library, bazel will use a specific version of protobuf to generate .pb.h/.pb.cc stub code.

Starting from bazel-7, we can't change version of protobuf by simply declare a com_google_protobuf bazel repository (it does work in bazel-1~bazel-6). So the stub code will be genreated using protobuf-3.21.8 and can't compatible with trpc-cpp protobuf-3.15.8 which causes compile error.

To resolve this problem, just downgrade bazel version to bazel-6.

zhangyi1357 commented 3 months ago

@weimch I'm not using Bazel, I'm using CMake.

weimch commented 3 months ago

@weimch I'm not using Bazel, I'm using CMake.

sor, thought you were the guy asking compile error in private.

weimch commented 4 days ago

Already solved by @zhangyi1357 at https://github.com/trpc-group/trpc-cpp/pull/167. Thanks for contribution.