Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Cannot run native python binary script without C++ toolchain

Đang mở
#4,040 2 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
50/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Ít trao đổi
Công nghệ
python
Lĩnh vực
build-system

Hướng nghiên cứu

Bắt đầu với ví dụ MODULE.bazel và BUILD.bazel tối thiểu, sau đó chạy các lệnh bazel run, cquery và aquery đã được báo cáo với BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN được đặt thành 1. So sánh các toolchain và action đã được phân giải để xác định liệu một py_binary thuần có thể tránh việc phân giải C++ toolchain hay không; hoàn tất khi hành vi này được sửa hoặc yêu cầu có chủ đích của nó được ghi lại.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

🐞 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:

  1. bazel run //:hello_world succeeds if the repo_env is set to 0 but fails on 1
  2. cquery shows that @@bazel_tools//tools/cpp:toolchain_type is resolved for the target.
  3. aquery shows 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.

Ngôn ngữ chính
Starlark
Star
690
Fork
722
Merge trung bình
1 ngày 55 phút
Pull request đã merge (30 ngày)
38

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của bazel-contrib/rules_python

Tất cả issue của bazel-contrib/rules_python

Issue tương tự

Thêm issue về Build System

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.