规则
- cc_binary
- cc_import
- cc_library
- cc_proto_library
- cc_shared_library
- fdo_prefetch_hints
- fdo_profile
- memprof_profile
- propeller_optimize
- cc_test
- cc_toolchain
- cc_toolchain_suite
cc_binary
查看规则来源cc_binary(name, deps, srcs, data, additional_linker_inputs, args, compatible_with, copts, defines, deprecation, distribs, env, exec_compatible_with, exec_properties, features, includes, licenses, link_extra_lib, linkopts, linkshared, linkstatic, local_defines, malloc, nocopts, output_licenses, restricted_to, stamp, tags, target_compatible_with, testonly, toolchains, visibility, win_def_file)
隐式输出目标
name.stripped
(仅在明确请求时构建):二进制文件的剥离版本。对二进制文件运行strip -g
以移除调试符号。可以使用--stripopt=-foo
在命令行中提供其他剥离选项。此输出仅在明确请求的情况下构建。name.dwp
(仅在明确请求时构建):如果启用了 Fission:一个调试信息包文件,适用于调试远程部署的二进制文件。否则:一个空文件。
参数
属性 | |
---|---|
name |
名称(必需) 此目标的唯一名称。 |
deps
|
标签列表;默认值为 这些目标可以是 |
srcs
|
标签列表;默认值为 系统会编译所有
所有 如果规则的名称位于
允许的
...以及生成这些文件的任何规则。 根据 gcc 惯例,不同的扩展名表示不同的编程语言。 |
additional_linker_inputs
|
标签列表;默认值为 例如,您可以在此处提供已编译的 Windows .res 文件,以将其嵌入到二进制目标中。 |
copts
|
字符串列表;默认值为
在编译二进制目标之前,此属性中的每个字符串都会按给定顺序添加到
如果软件包声明 feature
|
defines
|
字符串列表;默认值为 -D 前缀,并会添加到此目标的编译命令行以及依赖于它的每条规则中。请务必小心,因为这可能会造成深远的影响。如果有疑问,请改为向 local_defines 添加定义值。
|
includes
|
字符串列表;默认值为
需遵循替换 "Make variable" 的规定。
每个字符串都带有 头文件必须添加到 srcs 或 hdrs,否则当编译采用沙盒机制(默认设置)时,从属规则将无法使用这些头文件。 |
link_extra_lib
|
标签;默认值为
默认情况下,C++ 二进制文件链接到 |
linkopts
|
字符串列表;默认值为 LINKOPTS 中。
此列表假定列表中每个不以 |
linkshared
|
布尔值;不可配置;默认值为 linkshared=True 。默认情况下,此选项处于关闭状态。
如果存在此标志,则表示使用
如果您同时指定 |
linkstatic
|
布尔值;默认值为 cc_binary 和 cc_test :在静态模式下关联二进制文件。对于 cc_library.linkstatic :请参阅下文。
默认情况下,此选项会为
如果启用,并且这是二进制文件或测试文件,则此选项会告知构建工具尽可能链接 关联可执行文件其实有三种不同的方法:
如果用于
如果为 |
local_defines
|
字符串列表;默认值为 -D 作为前缀,并添加到此目标的编译命令行中,但不会添加到其依赖项中。
|
malloc
|
标签;默认值为
默认情况下,C++ 二进制文件链接到 |
nocopts
|
字符串;默认值为 COPTS 中移除与此正则表达式匹配的任何现有 COPTS (包括规则的 copts 属性中明确指定的值)。您应该很少需要此属性。
|
stamp
|
整数;默认值为
除非其依赖项发生变化,否则带时间戳的二进制文件不会被重新构建。 |
win_def_file
|
标签;默认值为 仅当 Windows 是目标平台时,才应使用此属性。 它可用于在关联共享库期间 导出符号。 |
cc_import
查看规则来源cc_import(name, deps, data, hdrs, alwayslink, compatible_with, deprecation, distribs, features, interface_library, licenses, restricted_to, shared_library, static_library, system_provided, tags, target_compatible_with, testonly, visibility)
cc_import
规则允许用户导入预编译的 C/C++ 库。
以下是典型的用例:
1. 关联静态库
cc_import( name = "mylib", hdrs = ["mylib.h"], static_library = "libmylib.a", # If alwayslink is turned on, # libmylib.a will be forcely linked into any binary that depends on it. # alwayslink = 1, )2. 关联共享库 (Unix)
cc_import( name = "mylib", hdrs = ["mylib.h"], shared_library = "libmylib.so", )3. 将共享库与接口库相关联 (Windows)
cc_import( name = "mylib", hdrs = ["mylib.h"], # mylib.lib is an import library for mylib.dll which will be passed to linker interface_library = "mylib.lib", # mylib.dll will be available for runtime shared_library = "mylib.dll", )4. 使用
system_provided=True
关联共享库 (Windows)
cc_import( name = "mylib", hdrs = ["mylib.h"], # mylib.lib is an import library for mylib.dll which will be passed to linker interface_library = "mylib.lib", # mylib.dll is provided by system environment, for example it can be found in PATH. # This indicates that Bazel is not responsible for making mylib.dll available. system_provided = 1, )5. 链接到静态库或共享库
在 Unix 上:
cc_import( name = "mylib", hdrs = ["mylib.h"], static_library = "libmylib.a", shared_library = "libmylib.so", ) # first will link to libmylib.a cc_binary( name = "first", srcs = ["first.cc"], deps = [":mylib"], linkstatic = 1, # default value ) # second will link to libmylib.so cc_binary( name = "second", srcs = ["second.cc"], deps = [":mylib"], linkstatic = 0, )在 Windows 上:
cc_import( name = "mylib", hdrs = ["mylib.h"], static_library = "libmylib.lib", # A normal static library interface_library = "mylib.lib", # An import library for mylib.dll shared_library = "mylib.dll", ) # first will link to libmylib.lib cc_binary( name = "first", srcs = ["first.cc"], deps = [":mylib"], linkstatic = 1, # default value ) # second will link to mylib.dll through mylib.lib cc_binary( name = "second", srcs = ["second.cc"], deps = [":mylib"], linkstatic = 0, )
cc_import
支持 include 属性。例如:
cc_import( name = "curl_lib", hdrs = glob(["vendor/curl/include/curl/*.h"]), includes = [ "vendor/curl/include" ], shared_library = "vendor/curl/lib/.libs/libcurl.dylib", )
参数
属性 | |
---|---|
name |
名称(必需) 此目标的唯一名称。 |
deps
|
标签列表;默认值为 deps 的一般注释。
|
hdrs
|
标签列表;默认值为 |
alwayslink
|
布尔值;默认值为 如果由于已知问题而导致始终链接无法用于 Windows 上的 VS 2017,请将 VS 2017 升级到最新版本。 |
interface_library
|
标签;默认值为 允许的文件类型: |
shared_library
|
标签;默认值为 允许的文件类型: |
static_library
|
标签;默认值为 允许的文件类型: |
system_provided
|
布尔值;默认值为 interface_library ,shared_library 应为空。
|
cc_library
查看规则来源cc_library(name, deps, srcs, data, hdrs, additional_compiler_inputs, additional_linker_inputs, alwayslink, compatible_with, copts, defines, deprecation, distribs, exec_compatible_with, exec_properties, features, implementation_deps, include_prefix, includes, licenses, linkopts, linkstamp, linkstatic, local_defines, nocopts, restricted_to, strip_include_prefix, tags, target_compatible_with, testonly, textual_hdrs, toolchains, visibility, win_def_file)
标头包含性检查
build 中使用的所有头文件必须在 cc_*
规则的 hdrs
或 srcs
中声明。系统会强制执行此要求。
对于 cc_library
规则,hdrs
中的头文件包含库的公共接口,可以直接从库本身的 hdrs
和 srcs
中的文件以及 cc_*
规则的 hdrs
和 srcs
的 srcs
中的文件(在 deps
中列出库)直接包含头文件。
srcs
中的头文件只能直接从库本身的 hdrs
和 srcs
内的文件中添加。在决定是将标头放入 hdrs
还是 srcs
时,您应该询问您是否希望此库的使用方能够直接包含该标头。这与编程语言中 public
到 private
可见性的决定大致相同。
cc_binary
和 cc_test
规则没有导出的接口,因此它们也不具有 hdrs
属性。所有属于二进制文件或直接测试的头文件都应在 srcs
中列出。
为了说明这些规则,请看以下示例。
cc_binary( name = "foo", srcs = [ "foo.cc", "foo.h", ], deps = [":bar"], ) cc_library( name = "bar", srcs = [ "bar.cc", "bar-impl.h", ], hdrs = ["bar.h"], deps = [":baz"], ) cc_library( name = "baz", srcs = [ "baz.cc", "baz-impl.h", ], hdrs = ["baz.h"], )
下表列出了此示例中允许的直接包含项。例如,foo.cc
可以直接包含 foo.h
和 bar.h
,但不能包含 baz.h
。
包括文件 | 允许的包含项 |
---|---|
foo.h | bar.h |
foo.cc | foo.h bar.h |
bar.h | bar-impl.h,baz.h |
bar-impl.h | bar.h baz.h |
bar.cc | bar.h bar-impl.h baz.h |
baz.h | baz-impl.h |
baz-impl.h | baz.h |
baz.cc | baz.h baz-impl.h |
包含项检查规则仅适用于直接包含项。在上面的示例中,foo.cc
可以包含 bar.h
,其中可能包括 baz.h
,而后者又可以包含 baz-impl.h
。从技术上讲,编译 .cc
文件时,可能会传递性 deps
闭包内任何 cc_library
内的 hdrs
或 srcs
内包含的任何头文件。在这种情况下,编译器在编译 foo.cc
时可以读取 baz.h
和 baz-impl.h
,但 foo.cc
不得包含 #include "baz.h"
。若要允许该行为,必须将 baz
添加到 foo
的 deps
中。
Bazel 依赖于工具链支持来强制执行包含检查规则。layering_check
功能必须受到工具链支持,并且必须明确请求,例如通过 --features=layering_check
命令行标志或 package
函数的 features
参数进行请求。在 Unix 和 macOS 上,Bazel 提供的工具链仅支持通过 clang 使用此功能。
参数
属性 | |
---|---|
name |
名称(必需) 此目标的唯一名称。 |
deps
|
标签列表;默认值为 这些目标可以是 |
srcs
|
标签列表;默认值为 系统会编译所有
所有 如果规则的名称位于
允许的
...以及生成这些文件的任何规则。 根据 gcc 惯例,不同的扩展名表示不同的编程语言。 |
hdrs
|
标签列表;默认值为 此位置是声明用于描述库接口的头文件的位置。这些标头将可供此规则或依赖规则中的来源包含。
不应纳入此库的客户端的标头应改为列在 |
additional_compiler_inputs
|
标签列表;默认值为 |
additional_linker_inputs
|
标签列表;默认值为 例如,您可以在此处提供已编译的 Windows .res 文件,以将其嵌入到二进制目标中。 |
alwayslink
|
布尔值;默认值为 srcs 中列出的文件的所有对象文件中,即使其中某些文件不包含二进制文件引用的符号也是如此。如果您的代码没有被二进制文件中的代码明确调用(例如,您的代码注册以接收某项服务提供的某种回调),那么这种做法非常有用。
如果由于已知问题而导致始终链接无法用于 Windows 上的 VS 2017,请将 VS 2017 升级到最新版本。 |
copts
|
字符串列表;默认值为
在编译二进制目标之前,此属性中的每个字符串都会按给定顺序添加到
如果软件包声明 feature
|
defines
|
字符串列表;默认值为 -D 前缀,并会添加到此目标的编译命令行以及依赖于它的每条规则中。请务必小心,因为这可能会造成深远的影响。如果有疑问,请改为向 local_defines 添加定义值。
|
implementation_deps
|
标签列表;默认值为 deps 不同,这些库(及其所有传递依赖项)的头文件和 include 路径仅用于此库的编译,而不用于依赖于此库的库。使用 implementation_deps 指定的库仍会在依赖于此库的二进制文件目标中链接。
目前,此用法仅限于 cc_libraries,并通过 |
include_prefix
|
字符串;默认值为 设置后,此规则的 在添加此前缀之前,系统会先移除 |
includes
|
字符串列表;默认值为
需遵循替换 "Make variable" 的规定。
每个字符串都带有 头文件必须添加到 srcs 或 hdrs,否则当编译采用沙盒机制(默认设置)时,从属规则将无法使用这些头文件。 |
linkopts
|
字符串列表;默认值为 LINKOPTS 中。
此列表假定列表中每个不以 |
linkstamp
|
标签;默认值为 base 软件包中才需要此选项。
|
linkstatic
|
布尔值;默认值为 cc_binary 和 cc_test :在静态模式下关联二进制文件。对于 cc_library.linkstatic :请参阅下文。
默认情况下,此选项会为
如果启用,并且这是二进制文件或测试文件,则此选项会告知构建工具尽可能链接 关联可执行文件其实有三种不同的方法:
如果用于
如果为 |
local_defines
|
字符串列表;默认值为 -D 作为前缀,并添加到此目标的编译命令行中,但不会添加到其依赖项中。
|
nocopts
|
字符串;默认值为 COPTS 中移除与此正则表达式匹配的任何现有 COPTS (包括规则的 copts 属性中明确指定的值)。您应该很少需要此属性。
|
strip_include_prefix
|
字符串;默认值为 设置后,此规则的 如果是相对路径,则会被当作软件包相对路径。如果它是绝对路径,则会被理解为代码库相对路径。
|
textual_hdrs
|
标签列表;默认值为 这是用于声明无法自行编译的头文件的位置;也就是说,它们始终需要由其他源文件以文本形式包含才能构建有效代码。 |
win_def_file
|
标签;默认值为 仅当 Windows 是目标平台时,才应使用此属性。 它可用于在关联共享库期间 导出符号。 |
cc_proto_library
查看规则来源cc_proto_library(name, deps, data, compatible_with, deprecation, distribs, exec_compatible_with, exec_properties, features, licenses, restricted_to, tags, target_compatible_with, testonly, visibility)
cc_proto_library
从 .proto
文件生成 C++ 代码。
deps
必须指向 proto_library
规则。
例如:
cc_library( name = "lib", deps = [":foo_cc_proto"], ) cc_proto_library( name = "foo_cc_proto", deps = [":foo_proto"], ) proto_library( name = "foo_proto", )
参数
属性 | |
---|---|
name |
名称(必需) 此目标的唯一名称。 |
deps
|
标签列表;默认值为 proto_library 规则列表。
|
cc_shared_library
查看规则来源cc_shared_library(name, deps, additional_linker_inputs, dynamic_deps, exports_filter, shared_lib_name, tags, user_link_flags, win_def_file)
它会生成一个共享库。
示例
cc_shared_library( name = "foo_shared", deps = [ ":foo", ], dynamic_deps = [ ":bar_shared", ], additional_linker_inputs = [ ":foo.lds", ], user_link_flags = [ "-Wl,--version-script=$(location :foo.lds)", ], ) cc_library( name = "foo", srcs = ["foo.cc"], hdrs = ["foo.h"], deps = [ ":bar", ":baz", ], ) cc_shared_library( name = "bar_shared", shared_lib_name = "bar.so", deps = [":bar"], ) cc_library( name = "bar", srcs = ["bar.cc"], hdrs = ["bar.h"], ) cc_library( name = "baz", srcs = ["baz.cc"], hdrs = ["baz.h"], )
在该示例中,foo_shared
静态链接 foo
和 baz
,后者是传递依赖项。它不关联 bar
,因为它已由 dynamic_dep
bar_shared
动态提供。
foo_shared
使用链接器脚本 *.lds 文件来控制应导出哪些符号。cc_shared_library
规则逻辑不控制要导出哪些符号,它仅使用假定要导出的内容,以便在分析阶段出现错误,前提是两个共享库导出相同的目标。
cc_shared_library
的每个直接依赖项都假定为导出。因此,Bazel 在分析期间假定 foo_shared
正在导出 foo
。baz
不假定由 foo_shared
导出。与 exports_filter
匹配的每个目标也都假定被导出。
示例中的每个 cc_library
最多只能出现在一个 cc_shared_library
中。如果我们还想将 baz
也关联到 bar_shared
,则需要将 tags = ["LINKABLE_MORE_THAN_ONCE"]
添加到 baz
。
由于 shared_lib_name
属性,由 bar_shared
生成的文件的名称将为 bar.so
,而不是其在 Linux 上默认使用的名称 libbar.so
。
错误
Two shared libraries in dependencies export the same symbols.
每当您使用两个导出相同目标的不同 cc_shared_library
依赖项创建目标时,就会发生这种情况。如需解决此问题,您需要停止在某个 cc_shared_library
依赖项中导出库。
Two shared libraries in dependencies link the same library statically
每当您使用两个不同的 cc_shared_library
依赖项(以静态方式链接同一目标)创建新的 cc_shared_library
时,就会发生这种情况。类似于导出错误。
解决此问题的一种方法是停止将库关联到其中一个 cc_shared_library
依赖项。同时,仍然关联它的库需要导出库,以便未关联库的库可以保持符号的可见性。另一种方法是提取用于导出目标的第三个库。第三种方法是使用 LINKABLE_MORE_THAN_ONCE
标记导致问题的 cc_library
,但这种修复应该很少见,您应该绝对确保 cc_library
确实可以安全地链接多次。
'//foo:foo' is already linked statically in '//bar:bar' but not exported`
这意味着,deps
的传递闭包中的库无需通过某个 cc_shared_library
依赖项即可访问,但已链接到 dynamic_deps
中的其他 cc_shared_library
,并且不会导出。
解决方案是从 cc_shared_library
依赖项中导出该依赖项,或者提取用于导出该依赖项的第三个 cc_shared_library
。
Do not place libraries which only contain a precompiled dynamic library in deps.
如果您有预编译的动态库,则无需执行此操作,也无法以静态方式链接到您当前正在创建的当前 cc_shared_library
目标。因此,它不属于 cc_shared_library
的 deps
。如果此预编译动态库是某个 cc_libraries
的依赖项,则 cc_library
需要直接依赖于它。
Trying to export a library already exported by a different shared library
如果您要在当前规则中声明要导出一个已由某个动态依赖项导出的目标,则会看到此错误。
如需解决此问题,请从 deps
中移除目标,并且仅在动态依赖项中依赖它,或者确保 exports_filter
不会捕获此目标。
参数
属性 | |
---|---|
name |
名称(必需) 此目标的唯一名称。 |
deps
|
标签列表;默认值为
这些直接依赖项的任何传递库依赖项都将链接到此共享库,前提是它们尚未被
在分析期间,规则实现会将
每当同一库以静态方式链接到多个 |
additional_linker_inputs
|
标签列表;默认值为 user_link_flags 属性执行此操作。
|
dynamic_deps
|
标签列表;默认值为 cc_shared_library 依赖项。
|
exports_filter
|
字符串列表;默认值为
任何目标
请注意,此属性实际上并不会向这些目标添加依赖边缘,依赖边缘应由 允许使用以下语法:
|
shared_lib_name
|
字符串;默认值为 |
user_link_flags
|
字符串列表;默认值为 cc_shared_library( name = "foo_shared", additional_linker_inputs = select({ "//src/conditions:linux": [ ":foo.lds", ":additional_script.txt", ], "//conditions:default": []}), user_link_flags = select({ "//src/conditions:linux": [ "-Wl,-rpath,kittens", "-Wl,--version-script=$(location :foo.lds)", "-Wl,--script=$(location :additional_script.txt)", ], "//conditions:default": []}), ... ) |
win_def_file
|
标签;默认值为 仅当 Windows 是目标平台时,才应使用此属性。 它可用于在关联共享库期间 导出符号。 |
fdo_prefetch_hints
查看规则来源fdo_prefetch_hints(name, compatible_with, deprecation, distribs, features, licenses, profile, restricted_to, tags, target_compatible_with, testonly, visibility)
表示工作区中或指定绝对路径中的 FDO 预提取提示配置文件。 示例:
fdo_prefetch_hints( name = "hints", profile = "//path/to/hints:profile.afdo", ) fdo_profile( name = "hints_abs", absolute_path_profile = "/absolute/path/profile.afdo", )
参数
属性 | |
---|---|
name |
名称(必需) 此目标的唯一名称。 |
profile
|
标签;默认值为 |
fdo_profile
查看规则来源fdo_profile(name, absolute_path_profile, compatible_with, deprecation, distribs, features, licenses, profile, proto_profile, restricted_to, tags, target_compatible_with, testonly, visibility)
表示工作区或指定绝对路径中的 FDO 配置文件。 示例:
fdo_profile( name = "fdo", profile = "//path/to/fdo:profile.zip", ) fdo_profile( name = "fdo_abs", absolute_path_profile = "/absolute/path/profile.zip", )
参数
属性 | |
---|---|
name |
名称(必需) 此目标的唯一名称。 |
absolute_path_profile
|
字符串;默认值为 |
profile
|
标签;默认值为 |
proto_profile
|
标签;默认值为 |
memprof_profile
查看规则来源memprof_profile(name, absolute_path_profile, compatible_with, deprecation, distribs, features, licenses, profile, restricted_to, tags, target_compatible_with, testonly, visibility)
表示工作区或指定绝对路径中的 MEMPROF 配置文件。 示例:
memprof_profile( name = "memprof", profile = "//path/to/memprof:profile.afdo", ) memprof_profile( name = "memprof_abs", absolute_path_profile = "/absolute/path/profile.afdo", )
参数
属性 | |
---|---|
name |
名称(必需) 此目标的唯一名称。 |
absolute_path_profile
|
字符串;默认值为 |
profile
|
标签;默认值为 |
propeller_optimize
查看规则来源propeller_optimize(name, compatible_with, deprecation, distribs, features, ld_profile, licenses, restricted_to, tags, target_compatible_with, testonly, visibility)
表示工作区中的 Propeller 优化配置文件。 例如:
propeller_optimize( name = "layout", cc_profile = "//path:cc_profile.txt", ld_profile = "//path:ld_profile.txt" ) propeller_optimize( name = "layout_absolute", absolute_cc_profile = "/absolute/cc_profile.txt", absolute_ld_profile = "/absolute/ld_profile.txt" )
参数
属性 | |
---|---|
name |
名称(必需) 此目标的唯一名称。 |
ld_profile
|
标签;默认值为 |
cc_test
查看规则来源cc_test(name, deps, srcs, data, additional_linker_inputs, args, compatible_with, copts, defines, deprecation, distribs, env, env_inherit, exec_compatible_with, exec_properties, features, flaky, includes, licenses, link_extra_lib, linkopts, linkstatic, local, local_defines, malloc, nocopts, restricted_to, shard_count, size, stamp, tags, target_compatible_with, testonly, timeout, toolchains, visibility, win_def_file)
参数
属性 | |
---|---|
name |
名称(必需) 此目标的唯一名称。 |
deps
|
标签列表;默认值为 这些目标可以是 |
srcs
|
标签列表;默认值为 系统会编译所有
所有 如果规则的名称位于
允许的
...以及生成这些文件的任何规则。 根据 gcc 惯例,不同的扩展名表示不同的编程语言。 |
additional_linker_inputs
|
标签列表;默认值为 例如,您可以在此处提供已编译的 Windows .res 文件,以将其嵌入到二进制目标中。 |
copts
|
字符串列表;默认值为
在编译二进制目标之前,此属性中的每个字符串都会按给定顺序添加到
如果软件包声明 feature
|
defines
|
字符串列表;默认值为 -D 前缀,并会添加到此目标的编译命令行以及依赖于它的每条规则中。请务必小心,因为这可能会造成深远的影响。如果有疑问,请改为向 local_defines 添加定义值。
|
includes
|
字符串列表;默认值为
需遵循替换 "Make variable" 的规定。
每个字符串都带有 头文件必须添加到 srcs 或 hdrs,否则当编译采用沙盒机制(默认设置)时,从属规则将无法使用这些头文件。 |
link_extra_lib
|
标签;默认值为
默认情况下,C++ 二进制文件链接到 |
linkopts
|
字符串列表;默认值为 LINKOPTS 中。
此列表假定列表中每个不以 |
linkstatic
|
布尔值;默认值为 cc_binary 和 cc_test :在静态模式下关联二进制文件。对于 cc_library.linkstatic :请参阅下文。
默认情况下,此选项会为
如果启用,并且这是二进制文件或测试文件,则此选项会告知构建工具尽可能链接 关联可执行文件其实有三种不同的方法:
如果用于
如果为 |
local_defines
|
字符串列表;默认值为 -D 作为前缀,并添加到此目标的编译命令行中,但不会添加到其依赖项中。
|
malloc
|
标签;默认值为
默认情况下,C++ 二进制文件链接到 |
nocopts
|
字符串;默认值为 COPTS 中移除与此正则表达式匹配的任何现有 COPTS (包括规则的 copts 属性中明确指定的值)。您应该很少需要此属性。
|
stamp
|
整数;默认值为
除非其依赖项发生变化,否则带时间戳的二进制文件不会被重新构建。 |
win_def_file
|
标签;默认值为 仅当 Windows 是目标平台时,才应使用此属性。 它可用于在关联共享库期间 导出符号。 |
cc_toolchain
查看规则来源cc_toolchain(name, all_files, ar_files, as_files, compatible_with, compiler_files, compiler_files_without_includes, coverage_files, deprecation, distribs, dwp_files, dynamic_runtime_lib, exec_transition_for_inputs, features, libc_top, licenses, linker_files, module_map, objcopy_files, restricted_to, static_runtime_lib, strip_files, supports_header_parsing, supports_param_files, tags, target_compatible_with, testonly, toolchain_config, toolchain_identifier, visibility)
表示 C++ 工具链。
该规则负责:
-
收集运行 C++ 操作所需的所有工件。这通过
all_files
、compiler_files
、linker_files
等属性或以_files
结尾的其他属性完成。这些是最常见的文件组,用于传播所有必需的文件。 -
为 C++ 操作生成正确的命令行。这可通过
CcToolchainConfigInfo
提供程序完成(详情如下)。
使用 toolchain_config
属性配置 C++ 工具链。
另请参阅此
页面
,查看详细的 C++ 工具链配置和工具链选择文档。
使用 tags = ["manual"]
可防止在调用 bazel build //...
时不必要地构建和配置工具链
参数
属性 | |
---|---|
name |
名称(必需) 此目标的唯一名称。 |
all_files
|
标签(必需) 所有 cc_toolchain 工件的集合。这些工件将作为输入添加到所有与 rules_cc 相关的操作(使用下面属性中的更精确工件集的操作除外)。Bazel 假定all_files 是所有其他提供工件的属性的超集(例如,linktamp 编译需要编译和链接文件,因此需要 all_files )。
这是 |
ar_files
|
标签;默认值为 归档操作所需的所有 cc_toolchain 工件的集合。 |
as_files
|
标签;默认值为 组装操作所需的所有 cc_toolchain 工件的集合。 |
compiler_files
|
标签(必需) 编译操作所需的所有 cc_toolchain 工件的集合。 |
compiler_files_without_includes
|
标签;默认值为 |
coverage_files
|
标签;默认值为 |
dwp_files
|
标签(必需) dwp 操作所需的所有 cc_toolchain 工件的集合。 |
dynamic_runtime_lib
|
标签;默认值为 当“static_link_cpp_runtimes”功能处于启用状态,并且我们正在动态关联依赖项时,将使用此属性。 |
exec_transition_for_inputs
|
布尔值;默认值为 |
libc_top
|
标签;默认值为 |
linker_files
|
标签(必需) 关联操作所需的所有 cc_toolchain 工件的集合。 |
module_map
|
标签;默认值为 |
objcopy_files
|
标签(必需) objcopy 操作所需的所有 cc_toolchain 工件的集合。 |
static_runtime_lib
|
标签;默认值为 当“static_link_cpp_runtimes”功能处于启用状态,并且我们以静态方式关联依赖项时,将使用此属性。 |
strip_files
|
标签(必需) 剥离操作所需的所有 cc_toolchain 工件的集合。 |
supports_header_parsing
|
布尔值;默认值为 |
supports_param_files
|
布尔值;默认值为 |
toolchain_config
|
标签(必需) 提供cc_toolchain_config_info 的规则的标签。
|
toolchain_identifier
|
字符串;不可配置;默认值为
在问题 #5380 得到解决之前,建议使用将 |
cc_toolchain_suite
查看规则来源cc_toolchain_suite(name, compatible_with, deprecation, distribs, features, licenses, restricted_to, tags, target_compatible_with, testonly, toolchains, visibility)
表示 C++ 工具链的集合。
该规则负责:
- 收集所有相关的 C++ 工具链。
-
根据传递给 Bazel 的
--cpu
和--compiler
选项选择一个工具链。
另请参阅此 页面 ,查看详细的 C++ 工具链配置和工具链选择文档。
参数
属性 | |
---|---|
name |
名称(必需) 此目标的唯一名称。 |
toolchains
|
将字符串映射到标签的字典;不可配置;必需 从“<cpu>”或“<cpu>|<compiler>”字符串到cc_toolchain 标签的映射。当仅将 --cpu 传递给 Bazel 时,将使用“<cpu>”;当 --cpu 和 --compiler 都传递给 Bazel 时,将使用“<cpu>|<compiler>”。示例:
cc_toolchain_suite( name = "toolchain", toolchains = { "piii|gcc": ":my_cc_toolchain_for_piii_using_gcc", "piii": ":my_cc_toolchain_for_piii_using_default_compiler", }, ) |