XueSongTap commented on issue #2904:
URL: https://github.com/apache/brpc/issues/2904#issuecomment-2933479696

   
   Hi, @chenBright 我在编译 `//test:brpc_http_rpc_protocol_unittest` 这个 UT 时,发现现在 
`MODULE.bazel` 里默认用的 protobuf 版本是比较新的 27.3,应该是为了兼容 Bazel module 的用法:
   
   
[https://github.com/apache/brpc/blob/c24e641009fa0305f0efebce694d0dad886c85ca/MODULE.bazel#L11](https://github.com/apache/brpc/blob/c24e641009fa0305f0efebce694d0dad886c85ca/MODULE.bazel#L11)
   
   ```bazel
   bazel_dep(name = 'protobuf', version = '27.3', repo_name = 
'com_google_protobuf')
   ```
   
   而 CMake 目前的版本约束是:
   
   
[https://github.com/apache/brpc/blob/c24e641009fa0305f0efebce694d0dad886c85ca/CMakeLists.txt#L178](https://github.com/apache/brpc/blob/c24e641009fa0305f0efebce694d0dad886c85ca/CMakeLists.txt#L178)
   
   ```cmake
   if(Protobuf_VERSION GREATER 4.21)
   ```
   
   也就是说,CMake 构建目前用 Protobuf ≥ 4.21(对应 protobuf release v21.3 及以上)是没问题的。
   
   ---
   
   但是我在用 Bazel + protobuf 27.3 版本编译 UT 时遇到了如下链接错误:
   
   ```text
   undefined symbol: google::protobuf::internal::LogMessage::LogMessage(...)
   referenced by brpc_http_rpc_protocol_unittest.cpp
   (...) google::protobuf::internal::CheckNotNull(...)
   ```
   
   完整 log 略,核心是:
   
   ```text
   google::protobuf::internal::LogMessage
   google::protobuf::internal::CheckNotNull
   ```
   
   ---
   
   从源码看,问题出在这里:
   
   
[https://github.com/apache/brpc/blob/c24e641009fa0305f0efebce694d0dad886c85ca/test/brpc\_http\_rpc\_protocol\_unittest.cpp#L1131](https://github.com/apache/brpc/blob/c24e641009fa0305f0efebce694d0dad886c85ca/test/brpc_http_rpc_protocol_unittest.cpp#L1131)
   
   代码里使用了:
   
   ```cpp
   GOOGLE_CHECK_NOTNULL(test_header);
   ```
   
   而 `GOOGLE_CHECK_NOTNULL` 宏定义在:
   
   ```cpp
   #include <google/protobuf/stubs/logging.h>
   ```
   
   ```cpp
   #define GOOGLE_CHECK_NOTNULL(A)               \
     ::google::protobuf::internal::CheckNotNull( \
         __FILE__, __LINE__, "'" #A "' must not be nullptr", (A))
   ```
   
   ---
   
   但是在 protobuf module ≥ v27.x 里,`protobuf/stubs/logging.h` 以及 
`google::protobuf::internal::LogMessage` 相关实现已经被移除或重构了,导致链接失败。
   
   ---
   
   所以这里有一个问题想确认一下:
   
   * 这种情况,是否应该 **修改 brpc 源码,清理老的 protobuf internal API 依赖,适配最新 protobuf**?
   * 还是考虑在 Bazel 里保持和 CMake 一致,**暂时固定降级到 protobuf 3.21.x**,保持当前兼容性?
   
   ---
   
   目前看 brpc 官方 CI 还是用 protobuf 3.21.12,所以这种 UT 在 CI 里是能正常编过的,只有用 Bazel module + 
protobuf 27.x 才会暴露出这个问题。
   
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to