brpc icon indicating copy to clipboard operation
brpc copied to clipboard

bazel deal with attribute const

Open fausturs opened this issue 1 year ago • 2 comments

注意到,目前使用的BUILD.bazel文件中有这样一条宏定义 https://github.com/apache/brpc/blob/master/BUILD.bazel#L25

-D__const__=__unused__

相关背景可以在issue:https://github.com/apache/brpc/issues/1693 与文档:https://github.com/apache/brpc/blob/master/docs/cn/thread_local.md#gcc4%E4%B8%8B%E7%9A%84errno%E9%97%AE%E9%A2%98 中找到介绍。

总结来说就是

务必在直接或间接使用bthread的项目的gcc编译选项中添加-D__const__=unused,即把__const__定义为一个无副作用的属性,避免gcc4做相关优化。

对于cmake来说,这个可能不好由brpc仓库进行实现。但对bazel来说,我们有办法由brpc仓库进行这个操作。

具体来说,bazel的cc_library提供一个参数defines, 用于给依赖(或者间接依赖)该目标的目标,添加宏定义。具体的,官方文档为: https://bazel.build/reference/be/c-cpp#cc_library

image

因此,brpc这边是否考虑,给bthread这个cc_library,直接添加这个宏定义呢

fausturs avatar Dec 16 '24 03:12 fausturs

@fausturs 可以添加这个宏定义。

chenBright avatar Feb 28 '25 06:02 chenBright