Skip to content

Commit

Permalink
fix: register autodetecting toolchain automatically
Browse files Browse the repository at this point in the history
@bazel_tools depends on rules_python, but the version is currently
specifies (0.22.0) doesn't register a toolchain by default. This means
the Bazel builtin Python rules aren't usable because no toolchain
is registered for them.

Registering the toolchain directly in @bazel_tools inverts the problem:
a toolchain is now always registered, but will usually always have
precedence over any that rules_python registers (because @bazel_tools
typically comes earlier in the module graph ordering).

Upgrading bazel_tools past to 0.23.0 or higher (which register a Python
toolchain automatically) is possible, but results in many failures in
Bazel CI that are hard to figure out.

To fix, we make rules_python register the autodetecting toolchain.
Later rules_python versions register a different toolchain, but this
at least gives Bazel something it can set as the minimum version that
preserves existing behavior.

Work towards bazelbuild/bazel#20458
  • Loading branch information
rickeylev committed Dec 19, 2023
1 parent 693a158 commit 153b533
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,12 @@ use_repo(

python = use_extension("@rules_python//python/extensions:python.bzl", "python")
use_repo(python, "pythons_hub")

# Necessary so that some toolchain is available so that the Python rules
# work in some minimal capacity.
# The @bazel_tools repo depends on rules_python, so expects rules_python
# to register a toolchain. @bazel_tools can't register a Python toolchain
# itself because @bazel_tools will typically come sooner in the module
# graph BFS order (it is an implicit dep of every module), and would thus
# override any toolchain rules_python registers.
register_toolchains("@bazel_tools//tools/python:autodetecting_toolchain")

0 comments on commit 153b533

Please sign in to comment.