Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bazel deal with attribute const #2850

Open
fausturs opened this issue Dec 16, 2024 · 0 comments
Open

bazel deal with attribute const #2850

fausturs opened this issue Dec 16, 2024 · 0 comments

Comments

@fausturs
Copy link

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

-D__const__=__unused__

相关背景可以在issue:#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,直接添加这个宏定义呢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant