如何从bazel中的cc_library指定输出伪像? [英] How to specify output artifact from a cc_library in bazel?

查看:247
本文介绍了如何从bazel中的cc_library指定输出伪像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将"foo.c"构建为一个库,然后在生成的.so而不是".a"上执行"readelf",如何在bazel中编写它?

I want to build "foo.c" as a library and then execute "readelf" on the generated .so but not the ".a", how can I write it in bazel?

以下BUILD.bazel文件不起作用:

The following BUILD.bazel file doesn't work:

cc_library(
    name = "foo",
    srcs = ["foo.c"],
)

genrule(
    name = "readelf_foo",
    srcs = ["libfoo.so"],
    outs = ["readelf_foo.txt"],
    cmd = "readelf -a $(SRCS) > $@",
)

错误是缺少输入文件'//:libfoo.so'".

The error is "missing input file '//:libfoo.so'".

将genrule的srcs属性更改为:foo"会将".a"和".so"文件都传递给readelf,这不是我所需要的.

Changing the genrule's srcs attribute to ":foo" passes both the ".a" and ".so" file to readelf, which is not what I need.

是否可以指定要传递给genrule的:foo"输出?

Is there any way to specify which output of ":foo" to pass to the genrule?

推荐答案

cc_library产生多个输出,这些输出由输出组分隔.如果只想获取.so输出,则可以将filegroupdynamic_library输出组一起使用.

cc_library produces several outputs, which are separated by output groups. If you want to get only .so outputs, you can use filegroup with dynamic_library output group.

因此,这应该可行:

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) > $@",
)

这篇关于如何从bazel中的cc_library指定输出伪像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆