bazel:你如何 "request" cc_binary 构建二进制文件的剥离版本?
bazel: How do you "request" that a cc_binary build the stripped version of the binary?
Bazel cc_binary
rule 的文档说:
Implicit output targets
<name>.stripped
(only built if explicitly requested): A stripped version of the binary. strip -g
is run on the binary to remove debug symbols. Additional strip options can be provided on the command line using --stripopt=-foo
. This output is only built if explicitly requested.
我如何“明确请求”构建这个剥离的二进制文件?我需要在 BUILD
文件中的 cc_binary
声明中添加一些内容吗?我无法从文档(或 Bazel 源代码)中弄清楚。
好的,我想我知道怎么做了。
如果我的 BUILD
文件有这个:
cc_binary(
name = "mytool",
srcs = ["mytool.c"]
)
...然后从命令行我可以用这个构建剥离的二进制文件:
bazel build //:mytool.stripped
或者,更常见的情况是,如果我有另一个 BUILD 规则需要剥离的二进制文件作为其输入之一,我可以通过相同的标签 :mytool.stripped
来引用它。这是一个奇怪的人为示例:
genrule(
name = "mygenrule",
outs = ["genrule.out"],
srcs = [":tool1.stripped"],
# run tool1.stripped, sends its output to genrule.out:
cmd = "$(SRCS) > $@"
)
Bazel cc_binary
rule 的文档说:
Implicit output targets
<name>.stripped
(only built if explicitly requested): A stripped version of the binary.strip -g
is run on the binary to remove debug symbols. Additional strip options can be provided on the command line using--stripopt=-foo
. This output is only built if explicitly requested.
我如何“明确请求”构建这个剥离的二进制文件?我需要在 BUILD
文件中的 cc_binary
声明中添加一些内容吗?我无法从文档(或 Bazel 源代码)中弄清楚。
好的,我想我知道怎么做了。
如果我的 BUILD
文件有这个:
cc_binary(
name = "mytool",
srcs = ["mytool.c"]
)
...然后从命令行我可以用这个构建剥离的二进制文件:
bazel build //:mytool.stripped
或者,更常见的情况是,如果我有另一个 BUILD 规则需要剥离的二进制文件作为其输入之一,我可以通过相同的标签 :mytool.stripped
来引用它。这是一个奇怪的人为示例:
genrule(
name = "mygenrule",
outs = ["genrule.out"],
srcs = [":tool1.stripped"],
# run tool1.stripped, sends its output to genrule.out:
cmd = "$(SRCS) > $@"
)