Cannot run native python binary script without C++ toolchain
Les mainteneurs répondent en général sous 1 jour
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Accessibilité débutants
- 50/100
- Type d'issue
- Bug
- Clarté
- Plutôt claire
- Activité
- Calme
- Stack technique
- python
- Domaine
- build-system
Piste de recherche
Commencez par l’exemple minimal de MODULE.bazel et BUILD.bazel, puis exécutez les commandes bazel run, cquery et aquery signalées avec BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN défini à 1. Comparez les toolchains et les actions résolues afin de déterminer si un py_binary pur peut éviter la résolution de la toolchain C++ ; le travail est terminé lorsque le comportement est corrigé ou que son exigence intentionnelle est documentée.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
🐞 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.
- Langage dominant
- Starlark
- Étoiles
- 688
- Forks
- 724
- Merge moyen
- 1 j 12 h
- PR mergées (30 j)
- 65
Préparer son environnement
- Aucun Dockerfile ni fichier Docker Compose
- Propose un modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de bazel-contrib/rules_python
-
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
bazel-contrib/rules_python#4251 · 1 réaction ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 88/100
bazel-contrib/rules_python#4201 · 3 commentaires ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
bazel-contrib/rules_python#4164 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
go:embed stdlib_list.txt file in gazelle/python/std_modules.go is missingPeut-être pris @udaya2899 l’a pris il y a 13 jours. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
bazel-contrib/rules_python#3821 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 5/5 Plus d'une semaine Accessibilité débutants 20/100
bazel-contrib/rules_python#4250 ·
Les mainteneurs répondent en général sous 1 jour
Toutes les issues de bazel-contrib/rules_python
Issues similaires
-
Difficulté 1/5 Moins d'une heure Accessibilité débutants 85/100
-
[Bug]: Three default prefs with JSON values are never set (override.sh escapes their quotes twice)Ouvertebug
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
Floorp-Projects/Floorp#2913 ·
Les mainteneurs répondent en général sous 1 jour
-
enhancement good first issue
Difficulté 2/5 1-3 heures Accessibilité débutants 76/100
Les mainteneurs répondent en général sous 1 jour
-
documentation severity/minor
Difficulté 1/5 1-3 heures Accessibilité débutants 88/100
Les mainteneurs répondent en général sous 1 jour
-
AssignTargetPath does not recognize forward slashes in relative path specifiersPeut-être pris @AustinAviv l’a pris aujourd’hui. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 79/100
Les mainteneurs répondent en général sous 2 jours