规则
- cc_binary
- cc_import
- cc_library
- cc_proto_library
- cc_shared_library
- cc_static_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
|
字符串列表;默认值为
需进行“创建变量”替换。
每个字符串都以 标头必须添加到 srcs 或 hdrs 中,否则在沙盒化编译(默认)时,依赖规则将无法使用这些标头。 |
link_extra_lib
|
标签;默认值为
默认情况下,C++ 二进制文件会与 |
linkopts
|
字符串列表;默认值为 LINKOPTS 。
此列表中不以 |
linkshared
|
布尔值;不可配置;默认值为 linkshared=True 。默认情况下,此选项处于关闭状态。
此标志的存在意味着链接时使用
如果您同时指定 |
linkstatic
|
布尔值;默认值为 cc_binary 和 cc_test :以静态模式关联二进制文件。对于 cc_library.linkstatic :请参阅下文。
默认情况下,此选项对
如果已启用且这是二进制文件或测试,此选项会告知 build 工具尽可能链接用户库的 实际上,关联可执行文件有三种不同的方式:
如果
如果值为 |
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, )
cc_import( name = "mylib", hdrs = ["mylib.h"], shared_library = "libmylib.so", )
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", )
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, )
在 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, )
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 的一般注释,请参阅大多数 build 规则定义的典型属性。
|
hdrs
|
标签列表;默认值为 |
alwayslink
|
布尔值;默认值为 如果 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)
标头包含情况检查
构建中使用的所有头文件都必须在 cc_*
规则的 hdrs
或 srcs
中声明。这是强制执行的。
对于 cc_library
规则,hdrs
中的头文件构成库的公共接口,可以直接从库本身的 hdrs
和 srcs
中的文件以及 cc_*
规则(在其 deps
中列出该库)的 hdrs
和 srcs
中的文件进行包含。
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
,而 bar.h
可以包含 baz.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
参数。Bazel 提供的工具链仅支持在 Unix 和 macOS 上使用 clang 实现此功能。
参数
属性 | |
---|---|
name |
名称;必需 相应目标的唯一名称。 |
deps
|
标签列表;默认值为 这些可以是 |
srcs
|
标签列表;默认值为 所有
所有 如果规则的名称位于
允许的
...以及生成这些文件的任何规则。 根据 gcc 惯例,不同的扩展名表示不同的编程语言。 |
hdrs
|
标签列表;默认值为 强烈建议在此位置声明描述库接口的头文件。这些标头将可供此规则或相关规则中的来源包含。
不打算由相应库的客户端包含的标头应列在 |
additional_compiler_inputs
|
标签列表;默认值为 |
additional_linker_inputs
|
标签列表;默认值为 例如,此处可以提供已编译的 Windows .res 文件,以便将其嵌入到二进制目标中。 |
alwayslink
|
布尔值;默认值为 srcs 中列出的文件的所有对象文件,即使其中一些文件不包含二进制文件引用的符号也是如此。
如果您的代码未被二进制文件中的代码显式调用,例如,如果您的代码注册为接收由某些服务提供的回调,则此方法非常有用。
如果 alwayslink 在 Windows 上无法与 VS 2017 搭配使用,这是由于已知问题所致,请将 VS 2017 升级到最新版本。 |
copts
|
字符串列表;默认值为
此属性中的每个字符串都会按给定顺序添加到
如果软件包声明了 feature
|
defines
|
字符串列表;默认值为 -D 并添加到相应目标的编译命令行以及依赖于该目标的每个规则中。请务必谨慎操作,因为这可能会产生深远的影响。如果不确定,请改为将定义值添加到 local_defines 。
|
implementation_deps
|
标签列表;默认值为 deps 不同,这些库(及其所有传递依赖项)的头文件和包含路径仅用于编译相应库,而不用于依赖于相应库的库。使用 implementation_deps 指定的库仍会链接到依赖于此库的二进制目标中。
目前,使用范围仅限于 cc_libraries,并受标志 |
include_prefix
|
字符串;默认值为 设置后,此规则的 系统会先移除 |
includes
|
字符串列表;默认值为
需进行“创建变量”替换。
每个字符串都以 标头必须添加到 srcs 或 hdrs 中,否则在沙盒化编译(默认)时,依赖规则将无法使用这些标头。 |
linkopts
|
字符串列表;默认值为 LINKOPTS 。
此列表中不以 |
linkstamp
|
标签;默认值为 base 软件包中需要。
|
linkstatic
|
布尔值;默认值为 cc_binary 和 cc_test :以静态模式关联二进制文件。对于 cc_library.linkstatic :请参阅下文。
默认情况下,此选项对
如果已启用且这是二进制文件或测试,此选项会告知 build 工具尽可能链接用户库的 实际上,关联可执行文件有三种不同的方式:
如果
如果值为 |
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
由 foo_shared
导出。baz
不会被 foo_shared
假定为已导出。exports_filter
匹配的每个目标也被假定为已导出。
示例中的每个 cc_library
最多只能出现在一个 cc_shared_library
中。如果我们还想将 baz
链接到 bar_shared
中,则需要向 baz
添加 tags = ["LINKABLE_MORE_THAN_ONCE"]
。
由于存在 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 是目标平台时,才应使用此属性。 它可用于在链接共享库期间 导出符号。 |
cc_static_library
查看规则来源cc_static_library(name, deps, tags)
生成的静态库包含 deps
中列出的目标及其传递依赖项的对象文件,并优先考虑 PIC
对象。
输出组
linkdeps
一个文本文件,其中包含 deps
中列出的目标的传递依赖项的标签,这些依赖项未向静态库贡献任何对象文件,但至少提供了一个静态库、动态库或接口库。生成的静态库可能需要在链接时提供这些库。
linkopts
一个文本文件,其中包含 deps
中列出的目标的所有传递依赖项的用户提供的 linkopts
。
重复的符号
默认情况下,cc_static_library
规则会检查生成的静态库是否不包含任何重复符号。如果存在,build 会失败,并显示一条错误消息,其中列出了重复的符号以及包含这些符号的对象文件。
您可以通过设置 features = ["-symbol_check"]
或通过 --features=-symbol_check
全局停用此检查,也可以按目标或按软件包停用此检查。
针对 symbol_check
的工具链支持
随 Bazel 提供的自动配置的 C++ 工具链在所有平台上都支持 symbol_check
功能。自定义工具链可以通过以下两种方式之一添加对它的支持:
- 实现
ACTION_NAMES.validate_static_library
操作,并通过symbol_check
功能启用该操作。操作中的工具集会使用两个实参进行调用,即要检查重复符号的静态库和检查通过时必须创建的文件的路径。 - 启用
symbol_check
功能会添加归档器标志,导致创建静态库的操作因符号重复而失败。
参数
属性 | |
---|---|
name |
名称;必需 相应目标的唯一名称。 |
deps
|
标签列表;默认值为 不提供任何对象文件的依赖项不会包含在静态库中,但其标签会收集在 |
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
|
字符串列表;默认值为
需进行“创建变量”替换。
每个字符串都以 标头必须添加到 srcs 或 hdrs 中,否则在沙盒化编译(默认)时,依赖规则将无法使用这些标头。 |
link_extra_lib
|
标签;默认值为
默认情况下,C++ 二进制文件会与 |
linkopts
|
字符串列表;默认值为 LINKOPTS 。
此列表中不以 |
linkstatic
|
布尔值;默认值为 cc_binary 和 cc_test :以静态模式关联二进制文件。对于 cc_library.linkstatic :请参阅下文。
默认情况下,此选项对
如果已启用且这是二进制文件或测试,此选项会告知 build 工具尽可能链接用户库的 实际上,关联可执行文件有三种不同的方式:
如果
如果值为 |
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
结尾的其他属性完成的。这些属性最常见的是包含所有必需文件的 filegroup。 -
为 C++ 操作生成正确的命令行。这是通过使用
CcToolchainConfigInfo
提供程序(详见下文)完成的。
使用 toolchain_config
属性配置 C++ 工具链。
另请参阅此
页面
,了解详细的 C++ 工具链配置和工具链选择文档。
使用 tags = ["manual"]
可防止在调用 bazel build //...
时不必要地构建和配置工具链
参数
属性 | |
---|---|
name |
名称;必需 相应目标的唯一名称。 |
all_files
|
标签;必需 所有 cc_toolchain 制品的集合。这些制品将作为输入添加到所有 rules_cc 相关操作中(使用以下属性中更精确的制品集的操作除外)。Bazel 假设all_files 是所有其他提供制品的属性的超集(例如,链接时间戳编译需要编译文件和链接文件,因此它采用 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", }, ) |