brpc icon indicating copy to clipboard operation
brpc copied to clipboard

基于Bazel编译的UT不完善

Open ZhengweiZhu opened this issue 9 months ago • 4 comments

Is your feature request related to a problem? (你需要的功能是否与某个问题有关?) bRPC已支持现代化的bazel编译框架,但对UT的编译不够完善,缺少维护,这对于使用bazel的开发者不友好。 如test目录下BUILD.bazel涵盖的UT用例不全,只编译了bvar, bthread, butil等模块,且这些模块中一些UT源文件还被excluded了,至于brpc开头的ut源文件都没有编译。

我尝试了编译完整的UT,确实存在很多编译报错(如echo.pb.h找不到),但通过努力发现大多数问题都能修改解决。 I will try to fix this.

Describe the solution you'd like (描述你期望的解决方法)

Describe alternatives you've considered (描述你想到的折衷方案)

Additional context/screenshots (更多上下文/截图)

ZhengweiZhu avatar Mar 03 '25 11:03 ZhengweiZhu

examples也不全,可以考虑补全一下。

chenBright avatar Mar 03 '25 11:03 chenBright

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

bazel_dep(name = 'protobuf', version = '27.3', repo_name = 'com_google_protobuf')

而 CMake 目前的版本约束是:

https://github.com/apache/brpc/blob/c24e641009fa0305f0efebce694d0dad886c85ca/CMakeLists.txt#L178

if(Protobuf_VERSION GREATER 4.21)

也就是说,CMake 构建目前用 Protobuf ≥ 4.21(对应 protobuf release v21.3 及以上)是没问题的。


但是我在用 Bazel + protobuf 27.3 版本编译 UT 时遇到了如下链接错误:

undefined symbol: google::protobuf::internal::LogMessage::LogMessage(...)
referenced by brpc_http_rpc_protocol_unittest.cpp
(...) google::protobuf::internal::CheckNotNull(...)

完整 log 略,核心是:

google::protobuf::internal::LogMessage
google::protobuf::internal::CheckNotNull

从源码看,问题出在这里:

https://github.com/apache/brpc/blob/c24e641009fa0305f0efebce694d0dad886c85ca/test/brpc_http_rpc_protocol_unittest.cpp#L1131

代码里使用了:

GOOGLE_CHECK_NOTNULL(test_header);

GOOGLE_CHECK_NOTNULL 宏定义在:

#include <google/protobuf/stubs/logging.h>
#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 才会暴露出这个问题。

XueSongTap avatar Jun 03 '25 05:06 XueSongTap

https://github.com/apache/brpc/blob/c24e641009fa0305f0efebce694d0dad886c85ca/test/brpc_http_rpc_protocol_unittest.cpp#L1131

是不是改成CHECK(test_header != NULL)就可以兼容新旧版本了?

chenBright avatar Jun 03 '25 12:06 chenBright

我理解是需要类似这样的改动

XueSongTap avatar Jun 03 '25 13:06 XueSongTap