bazel - 如何从 bazel 中的 cc_library 指定输出工件?
问题描述
我想将“foo.c”构建为一个库,然后在生成的 .so 上执行“readelf”,而不是“.a”,我该如何在 bazel 中编写它?
以下 BUILD.bazel 文件不起作用:
cc_library(
name = "foo",
srcs = ["foo.c"],
)
genrule(
name = "readelf_foo",
srcs = ["libfoo.so"],
outs = ["readelf_foo.txt"],
cmd = "readelf -a $(SRCS) > $@",
)
错误是“缺少输入文件'//:libfoo.so'”。
将 genrule 的 srcs 属性更改为“:foo”会将“.a”和“.so”文件都传递给 readelf,这不是我需要的。
有什么方法可以指定传递给 genrule 的 ":foo" 的哪个输出?
解决方案
cc_library
产生多个输出,这些输出由输出组分隔。如果您只想获得 .so 输出,您可以使用filegroup
输出dynamic_library
组。
所以,这应该工作:
cc_library(
name = "foo",
srcs = ["foo.c"],
)
filegroup(
name='libfoo',
srcs=[':foo'],
output_group = 'dynamic_library'
)
genrule(
name = "readelf_foo",
srcs = [":libfoo"],
outs = ["readelf_foo.txt"],
cmd = "readelf -a $(SRCS) > $@",
)
推荐阅读
- autohotkey - 用于滚动的自动热键脚本
- c - 使用 C 在数据块中查找模式的出现
- android - AuthUI:出现登录错误。com.firebase.ui.auth.FirebaseUiException:代码:12500,消息:12500
- java - Json 属性在 Spring 应用程序的请求正文(Pojo 类)中被截断
- c# - 使用 xUnit 在 Rider 中测试 c#
- python - 如何在辅助线程中运行 aiohttp Web 应用程序
- java - 从服务器解析嵌套的 JSON
- aws-lambda - 未触及的 AWS Lambda/S3 函数突然现在可以正常工作了
- cuda - 将静态声明的 __constant__ 变量作为内核参数(CUDA)传递
- python - systemd 中的 Python 脚本:虚拟环境或真实环境