ToolchainResolution 为错误的平台选择了工具链
我定义了一个新的 Rust 工具链,如下所示(从 https://github.com/bazelbuild/rules_rust 分叉):
toolchain(
name = "toolchain_for_armv7-linux-androideabi",
exec_compatible_with = ["@platforms//cpu:x86_64", "@platforms//os:windows"],
target_compatible_with = ["@platforms//cpu:armv7", "@platforms//os:android"],
toolchain = "@rust_windows_x86_64//:toolchain_for_armv7-linux-androideabi_impl",
toolchain_type = "@rules_rust//rust:toolchain",
)
还有一个如下定义的现有工具链:
toolchain(
name = "toolchain_for_x86_64-apple-darwin",
exec_compatible_with = ["@platforms//cpu:x86_64", "@platforms//os:osx"],
target_compatible_with = ["@platforms//cpu:x86_64", "@platforms//os:osx"],
toolchain = "@rust_darwin_x86_64//:toolchain_for_x86_64-apple-darwin_impl",
toolchain_type = "@rules_rust//rust:toolchain",
)
并为该平台构建目标:
bazel build --toolchain_resolution_debug=@rules_rust//rust:toolchain --experimental_platforms_api vrst-test/android --platforms=//platforms:android_armv7
这是 ToolchainResolution 调试信息的片段:
INFO: ToolchainResolution: Type @rules_rust//rust:toolchain: target platform @local_config_platform//:host: execution @local_config_platform//:host: Selected toolchain @rust_darwin_x86_64//:toolchain_for_x86_64-apple-darwin_impl
INFO: ToolchainResolution: Type @rules_rust//rust:toolchain: target platform @local_config_platform//:host: Rejected toolchain @rust_darwin_x86_64//:toolchain_for_armv7-linux-androideabi_impl; mismatching values: armv7, android
出于某种原因,目标平台是 @local_config_platform//:host
尽管我明确指定平台为 android_armv7,其定义如下:
platform(
name = "android_armv7",
constraint_values = [
"@platforms//cpu:armv7",
"@platforms//os:android",
],
)```
I defined a new rust toolchain as follows (forked from https://github.com/bazelbuild/rules_rust):
toolchain(
name = "toolchain_for_armv7-linux-androideabi",
exec_compatible_with = ["@platforms//cpu:x86_64", "@platforms//os:windows"],
target_compatible_with = ["@platforms//cpu:armv7", "@platforms//os:android"],
toolchain = "@rust_windows_x86_64//:toolchain_for_armv7-linux-androideabi_impl",
toolchain_type = "@rules_rust//rust:toolchain",
)
There is also an existing toolchain defined like this:
toolchain(
name = "toolchain_for_x86_64-apple-darwin",
exec_compatible_with = ["@platforms//cpu:x86_64", "@platforms//os:osx"],
target_compatible_with = ["@platforms//cpu:x86_64", "@platforms//os:osx"],
toolchain = "@rust_darwin_x86_64//:toolchain_for_x86_64-apple-darwin_impl",
toolchain_type = "@rules_rust//rust:toolchain",
)
And building a target for that platform:
bazel build --toolchain_resolution_debug=@rules_rust//rust:toolchain --experimental_platforms_api vrst-test/android --platforms=//platforms:android_armv7
Here is a snippet of ToolchainResolution debug info:
INFO: ToolchainResolution: Type @rules_rust//rust:toolchain: target platform @local_config_platform//:host: execution @local_config_platform//:host: Selected toolchain @rust_darwin_x86_64//:toolchain_for_x86_64-apple-darwin_impl
INFO: ToolchainResolution: Type @rules_rust//rust:toolchain: target platform @local_config_platform//:host: Rejected toolchain @rust_darwin_x86_64//:toolchain_for_armv7-linux-androideabi_impl; mismatching values: armv7, android
For some reason, target platform is @local_config_platform//:host
despite me explicitly specifying the platform as android_armv7, which is defined as follows:
platform(
name = "android_armv7",
constraint_values = [
"@platforms//cpu:armv7",
"@platforms//os:android",
],
)```
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
虽然这个问题是一年前提出的,但我还是尝试回答一下,希望对您有所帮助。
来自 bazel 文档:https://bazel.build/extending/toolchains#toolchain-resolution
和:
因此,您的工具链与您的执行平台不兼容,即 @local_config_platform//:host
该平台 @local_config_platform//:host 由 bazel 自动生成,并且根据不同的系统而有所不同。因此,为了确保选择您的工具链,您需要:
bazel query @local_config_platform//:host --output=build
进行检查。--platforms=//label/to/your/toolchain:toolchain_name
Although this question was asked one years ago, I tried to answer and hope it helps.
From bazel documentation: https://bazel.build/extending/toolchains#toolchain-resolution
And:
Hence, your toolchain is not compatible with your execution platform, which is @local_config_platform//:host
This platform, @local_config_platform//:host, is generated by bazel automatically and it varies for different systems. Hence, to ensure your toolchain is selected, you need to:
bazel query @local_config_platform//:host --output=build
.--platforms=//label/to/your/toolchain:toolchain_name
Bazel 解析由
--platforms
指定的目标平台和 主机平台,由--host_platform
指定。如果您确实希望为toolchain_for_armv7-linux-androideabi
构建主机工具,则需要设置--host_platform
。Bazel resolves toolchains both for the target platforms, specified by
--platforms
, and the host platform, specified by--host_platform
. If you actually want host tools to be built fortoolchain_for_armv7-linux-androideabi
, you will want to set--host_platform
.