Cannot run native python binary script without C++ toolchain
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 50/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 冷清
- 技术栈
- python
- 领域
- build-system
调研方向
从最小的 MODULE.bazel 和 BUILD.bazel 示例开始,然后在将 BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN 设置为 1 的情况下运行报告中的 bazel run、cquery 和 aquery 命令。比较已解析的工具链和操作,以确定纯 py_binary 是否可以避免解析 C++ 工具链;行为得到修复或其有意要求得到记录即表示完成。
由索引模型根据 Issue 内容生成。
描述
🐞 bug report
Affected Rule
py_binary
Is this a regression?
Not tested, unlikely.
Description
A trivial pure-Python py_binary appears to require C++ toolchain resolution even though it does not produce any C++ compile or link actions.
In a minimal example, bazel cquery //:hello_world --toolchain_resolution_debug='.*' shows that Bazel resolves both:
@@bazel_tools//tools/python:toolchain_type@@bazel_tools//tools/cpp:toolchain_type
However, bazel aquery //:hello_world only shows Python-related actions such as Python bytecode precompilation and bootstrap/template generation. There are no C++ compile or link actions for the target.
This is surprising for Python-only projects. In environments where no C++ toolchain is configured or available, this can cause a trivial py_binary to fail analysis even though the target itself does not build native code.
From a user perspective, I would expect a pure py_binary with no native extensions and no C/C++ deps to avoid requiring successful C++ toolchain resolution, or at least for the requirement to be documented if it is intentional.
🔬 Minimal Reproduction
MODULE.bazel
module(
name = "bazel_hello_py",
version = "0.1.0",
)
bazel_dep(name = "rules_shell", version = "0.6.1")
bazel_dep(name = "rules_python", version = "1.7.0")
BUILD.bazel
load("@rules_python//python:defs.bzl", "py_binary")
py_binary(
name = "hello_world",
srcs = ["hello_world.py"],
)
hello_world.py
print("hello world")
bazel run //:hello_world --repo_env=BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=<0|1>
bazel cquery //:hello_world --toolchain_resolution_debug='.*'
bazel aquery //:hello_world
Observed behavior:
bazel run //:hello_worldsucceeds if therepo_envis set to0but fails on1cquery shows that @@bazel_tools//tools/cpp:toolchain_typeis resolved for the target.aqueryshows only Python-related actions and no C++ compile/link actions.
This suggests the C++ toolchain resolution is happening even for a pure-Python binary with no actual C++ build work.
🔥 Exception or Error
$ bazel run //:hello_world --repo_env=BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1
ERROR: .../external/bazel_tools/src/tools/launcher/BUILD:75:10: While resolving toolchains for target @@bazel_tools//src/tools/launcher:launcher_maker (04bf134): No matching toolchains found for types:
@@bazel_tools//tools/cpp:toolchain_type
To debug, rerun with --toolchain_resolution_debug='@@bazel_tools//tools/cpp:toolchain_type'
For more information on platforms or toolchains see https://bazel.build/concepts/platforms-intro.
ERROR: Analysis of target '//:hello_world' failed; build aborted: Analysis failed
INFO: Elapsed time: 0.107s, Critical Path: 0.01s
INFO: 1 process: 1 internal.
ERROR: Build did NOT complete successfully
ERROR: Build failed. Not running target
🌍 Your Environment
Operating System:
Linux (Ubuntu LTS 24.04)
Output of bazel version:
Bazelisk version: v1.29.0 Build label: 9.2.0 Build target: @@//src/main/java/com/google/devtools/build/lib/bazel:BazelServer Build time: Mon Jul 13 18:15:04 2026 (1783966504) Build timestamp: 1783966504 Build timestamp as int: 1783966504
Rules_python version:
1.7.0
Anything else relevant?
Related issues I found while searching:
rules_python #1857 discusses py_binary and C++ toolchain resolution in cross-compilation scenarios.
rules_python #2500 discusses replacing the stage1 bootstrap with a native launcher.
My main question is whether this C++ toolchain resolution for a pure py_binary is intentional.
- 主要语言
- Starlark
- 星标
- 690
- 派生
- 722
- 平均合并
- 1 天 55 分钟
- 30 天内合并 PR
- 38
环境准备
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
bazel-contrib/rules_python 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 70/100
bazel-contrib/rules_python#4179 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
bazel-contrib/rules_python#4164 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
bazel-contrib/rules_python#3821 ·
维护者通常 1 天内回复
-
难度 3/5 1-2 天 新手友好度 45/100
bazel-contrib/rules_python#4181 ·
维护者通常 1 天内回复
-
Release 2.4.0未关闭type: release
难度 4/5 3-5 天 新手友好度 25/100
bazel-contrib/rules_python#4175 · 3 条评论 ·
维护者通常 1 天内回复
查看 bazel-contrib/rules_python 的全部 Issue
相似的 Issue
-
package-update
难度 2/5 1-3 小时 新手友好度 78/100
-
bug p:1-highest pydanty:bug
难度 2/5 1-3 小时 新手友好度 78/100
pydantic/pydantic-ai#8841 · 1 条评论 ·
维护者通常 1 天内回复
-
bug good first issue
难度 1/5 1 小时以内 新手友好度 88/100
yunaremaia/diff-contract#79 ·
-
self-care self-care:docs-build-time-investigator
难度 2/5 1-3 小时 新手友好度 76/100
githubnext/gh-aw-cao#14184 ·
维护者通常 1 天内回复
-
backlog
难度 2/5 1-3 小时 新手友好度 74/100
维护者通常 1 天内回复