規則
- 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
|
字串清單;預設值為
此屬性中的每個字串都會按照指定順序新增至
如果套件宣告了「功能」 |
defines
|
字串清單;預設值為 -D ,並新增至編譯指令列,以及所有依附於該目標的規則。請務必小心,因為這可能會造成嚴重影響。如有疑問,請改為在 local_defines 中新增定義值。
|
includes
|
字串清單;預設值為
取決於「Make 變數」替代。每個字串前面都會加上 您必須將標頭新增至 srcs 或 Hdrs,否則在採用沙箱機制的編譯時,相依規則無法使用標頭 (預設)。 |
link_extra_lib
|
標籤;預設值為
根據預設,C++ 二進位檔會與 |
linkopts
|
字串清單;預設值為 LINKOPTS ,然後再連結二進位目標。
這份清單中每個開頭不是 |
linkshared
|
布林值;nonconfigurable;預設值為 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)
標頭納入檢查
凡是建構作業中使用的標頭檔案,都必須在 cc_*
規則的 hdrs
或 srcs
中宣告。系統會強制執行這項政策。
以 cc_library
規則來說,hdrs
中的標頭可包含程式庫的公開介面,且可以直接從程式庫本身的 hdrs
和 srcs
檔案,以及 deps
中 hdrs
和 srcs
規則 (在 deps
中列出程式庫) 加入。cc_*
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
參數提出要求。Bazel 提供的工具鍊僅支援在 Unix 和 macOS 上使用 clang。
引數
屬性 | |
---|---|
name |
名稱 (必填) 此目標的專屬名稱。 |
deps
|
標籤清單;預設值為 目標可以是 |
srcs
|
標籤清單;預設值為 系統會編譯所有
所有 如果規則名稱位於
允許的
...以及產生這些檔案的任何規則。不同的擴充功能會按照 GCC 慣例表示不同的程式設計語言。 |
hdrs
|
標籤清單;預設值為 強烈建議您使用此位置宣告標頭檔案,用於描述程式庫的介面。這些標頭可讓來源納入這項規則或依附規則。即使標頭包含在已發布的標頭中,不應納入這個程式庫的用戶端也應列入 |
additional_compiler_inputs
|
標籤清單;預設值為 |
additional_linker_inputs
|
標籤清單;預設值為 舉例來說,您可以在這裡提供已編譯的 Windows .res 檔案,以嵌入二進位檔目標。 |
alwayslink
|
布林值;預設值為 srcs 中列出的檔案所有物件檔案中,即使某些檔案不含二進位檔參照的符號也一樣。如果二進位檔中的程式碼未明確呼叫程式碼 (例如程式碼註冊接收部分服務提供的回呼),這項功能就能派上用場。如果「一律連結」無法在 Windows 上與 VS 2017 搭配運作 (也就是因為已知問題),請將 VS 2017 升級至最新版本。 |
copts
|
字串清單;預設值為
此屬性中的每個字串都會按照指定順序新增至
如果套件宣告了「功能」 |
defines
|
字串清單;預設值為 -D ,並新增至編譯指令列,以及所有依附於該目標的規則。請務必小心,因為這可能會造成嚴重影響。如有疑問,請改為在 local_defines 中新增定義值。
|
implementation_deps
|
標籤清單;預設值為 deps 不同,這些程式庫的標頭和包含路徑 (及其所有遞移依附元件) 只會用於這個程式庫的編譯作業,不會用於依附該程式庫的程式庫。使用 implementation_deps 指定的程式庫仍會在依附於這個程式庫的二進位檔目標中連結。目前僅限使用 cc_libraries,並受到標記 |
include_prefix
|
字串;預設值為 設定之後,即可存取這項規則的 系統會先移除 |
includes
|
字串清單;預設值為
取決於「Make 變數」替代。每個字串前面都會加上 您必須將標頭新增至 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
是由 foo_shared
匯出。foo_shared
不會假設 baz
匯出。凡是與 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`
這表示開發人員可以透過任何 cc_shared_library
依附元件連上 deps
轉換關閉中的程式庫,但該程式庫已連結至 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
|
字串清單;預設值為
此屬性中的每個字串都會按照指定順序新增至
如果套件宣告了「功能」 |
defines
|
字串清單;預設值為 -D ,並新增至編譯指令列,以及所有依附於該目標的規則。請務必小心,因為這可能會造成嚴重影響。如有疑問,請改為在 local_defines 中新增定義值。
|
includes
|
字串清單;預設值為
取決於「Make 變數」替代。每個字串前面都會加上 您必須將標頭新增至 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 是所有其他成果提供屬性的超集 (例如連結標記編譯需要編譯和連結檔案,因此採用 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
|
字串;nonconfigurable;預設值為
直到問題 #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", }, ) |