Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
freem
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Openai/695a2b27-bfe4-8005-959b-536ec4f485aa
(section)
Add languages
Page
Discussion
English
Read
Edit
Edit source
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
Edit source
View history
General
What links here
Related changes
Special pages
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== Assistant: 先把关键点讲清楚: === 先把关键点讲清楚: 你的 Bazel 版本根本没有 <code>cc_toolchain_config.bzl</code>,也没有 <code>cc_toolchain_config</code> 这个符号。 也就是说: 你遇到的所有 load 报错,其实是因为 你参考的是新版文档,但你本机 Bazel 是老版本。 ==== ### ==== 没有 cc_toolchain_config.bzl 也没有 cc_toolchain_config 只有: <syntaxhighlight>@bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl </syntaxhighlight> 里面确实 只有 feature / flag_set / flag_group / tool_path / action_config 等,没有顶层入口。 老版本必须用 cc_toolchain_suite,并把配置写进: <syntaxhighlight>cc_toolchain( toolchain_config = ":my_config", ) </syntaxhighlight> 其中 my_config 是: <syntaxhighlight>filegroup(srcs = ["CROSSTOOL"]) </syntaxhighlight> 也就是老式 CROSSTOOL,不支持新 API。 ===== 才第一次引入: ===== <syntaxhighlight>@bazel_tools//tools/cpp:cc_toolchain_config.bzl └── cc_toolchain_config(...) </syntaxhighlight> 所以若你报: <syntaxhighlight>no such file @bazel_tools//tools/cpp:cc_toolchain_config.bzl </syntaxhighlight> 👉 100% 说明你是在 Bazel 4.x 或更低版本 (或者使用的环境里 @bazel_tools 不是你以为的版本) ==== 运行: ==== <syntaxhighlight>bazel --version </syntaxhighlight> 我 99% 确定你会看到: <syntaxhighlight>bazel 4.x.x 或更低 </syntaxhighlight> ==== 结论: ==== 不支持用 .bzl 创建新 toolchain,必须用旧式 CROSSTOOL 格式。 你只能写: <syntaxhighlight>CROSSTOOL </syntaxhighlight> 在里面加: <syntaxhighlight>compiler_flag: "-fsanitize=address" cxx_flag: "-fsanitize=address" linker_flag: "-fsanitize=address" </syntaxhighlight> 然后注册: <syntaxhighlight lang="bzl">cc_toolchain_suite( name = "asan_suite", toolchains = { "local|clang": ":asan_toolchain", }, ) cc_toolchain( name = "asan_toolchain", toolchain_identifier = "asan", toolchain_config = ":local_clang_crosstool", ) </syntaxhighlight> 再用: <syntaxhighlight>--crosstool_top=//toolchain:asan_suite </syntaxhighlight> 即:老版只能走 CROSSTOOL,不可能用 cc_toolchain_config API。 ==== 唯一解法: ==== ===== 例如: ===== <syntaxhighlight>brew upgrade bazel </syntaxhighlight> 然后路径就会存在: <syntaxhighlight>@bazel_tools//tools/cpp:cc_toolchain_config.bzl </syntaxhighlight> 你才能写: <syntaxhighlight lang="bzl">load("@bazel_tools//tools/cpp:cc_toolchain_config.bzl", "cc_toolchain_config") </syntaxhighlight> ==== 你遇到的错误: ==== <syntaxhighlight>@bazel_tools//tools/cpp:cc_toolchain_config.bzl no such file </syntaxhighlight> 原因不是写错路径,是你的 Bazel 版本太老,不含该文件。 如果你愿意告诉我: <syntaxhighlight>bazel --version </syntaxhighlight> 我能给你完全匹配你版本的正确配置方案。
Summary:
Please note that all contributions to freem are considered to be released under the Creative Commons Attribution-ShareAlike 4.0 (see
Freem:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)