如何从 bazel 中的 cc_library 指定输出工件?
How to specify output artifact from a cc_library in bazel?
我想将 "foo.c" 构建为一个库,然后在生成的 .so 而不是“.a”上执行 "readelf",我如何在 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) > $@",
)
错误是"missing input file '//:libfoo.so'"。
将 genrule 的 srcs 属性更改为“:foo”会将“.a”和“.so”文件都传递给 readelf,这不是我需要的。
有什么方法可以指定“:foo”的哪个输出传递给 genrule 吗?
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) > $@",
)
我想将 "foo.c" 构建为一个库,然后在生成的 .so 而不是“.a”上执行 "readelf",我如何在 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) > $@",
)
错误是"missing input file '//:libfoo.so'"。
将 genrule 的 srcs 属性更改为“:foo”会将“.a”和“.so”文件都传递给 readelf,这不是我需要的。
有什么方法可以指定“:foo”的哪个输出传递给 genrule 吗?
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) > $@",
)