Skip to content

refactor!: own the interpreter runtime toolchain rules instead of rules_python's#1305

Draft
jbedard wants to merge 1 commit into
mainfrom
reduce-rpython-deps-runtime
Draft

refactor!: own the interpreter runtime toolchain rules instead of rules_python's#1305
jbedard wants to merge 1 commit into
mainfrom
reduce-rpython-deps-runtime

Conversation

@jbedard

@jbedard jbedard commented Jul 16, 2026

Copy link
Copy Markdown
Member

Generated interpreter repos now instantiate a rules_py py_runtime_toolchain (py/private/interpreter/runtime.bzl, with a rules_py PyRuntimeInfo) instead of rules_python's py_runtime + py_runtime_pair + py_exec_tools_toolchain. One :runtime target per repo backs both toolchain registrations. Toolchain types are unchanged (@bazel_tools python type; rules_python's exec_tools type, with its exec_tools.exec_runtime/precompiler payload shape preserved), so rules_python-provisioned interpreters still satisfy whl_install/site-merge and rules_py still consumes user-registered rules_python py_runtime toolchains.

This shrinks each interpreter repo's rules_python loads from 31 .bzl files to the 12 of the deliberately kept py_cc_toolchain chain, insulating provisioned toolchains from rules_python implementation churn, and leaves the runtime layer pinning no rules_python minimum version.

New coverage: e2e/rules-python-interop (isolated module) pins that a module mixing both rulesets shares one rules_python-provisioned interpreter, including a $(PYTHON3) location diff_test; e2e/cases/rules-python-consumers pins that rules_python's own toolchain consumers (current_py_toolchain, exec-tools readers) work against rules_py-backed toolchains.

Changes are visible to end-users: yes

  • Searched for relevant documentation and updated as needed: yes

  • Breaking change (forces users to change their own code or config): yes

  • Suggested release notes appear below: yes

  • Generated interpreter repo targets are renamed: @python_X//:py3_runtime, :runtime_pair, and :exec_tools_toolchain are now a single @python_X//:runtime. Only direct label references need updating; toolchain resolution is unaffected.

  • rules_py-provisioned runtimes carry rules_py's PyRuntimeInfo, not rules_python's. Provider-indexed access (target[PyRuntimeInfo] with rules_python's symbol) on these targets or resolved toolchains breaks; duck-typed field access keeps working. As a consequence, rules_python's py_binary/py_test cannot execute on rules_py-provisioned toolchains (they read provider fields rules_py does not carry) — the same one-way interop direction refactor: use simplified rules_py providers #1231 establishes for PyInfo.

  • The exec-tools toolchain rules_py registers provides precompiler = None; enabling rules_python precompiling while @python_interpreters toolchains are registered first is unsupported.

Test plan

  • Covered by existing test cases

@aspect-workflows

aspect-workflows Bot commented Jul 16, 2026

Copy link
Copy Markdown

✨ Aspect Workflows Tasks

📅 Thu Jul 16 08:30:48 UTC 2026

✅ 2 successful tasks

  • ✅ test-e2e-bazel-9 [test] · ⏱ 2m 29s · 🐙 GitHub Actions
    💬 Bazel test complete (191/191 passed)
  • ✅ test-examples-protobuf-bazel-9 [test] · ⏱ 2m 15s · 🐙 GitHub Actions · ☑️ Check
    💬 Bazel test complete (1/1 passed)

⏱ Last updated Thu Jul 16 08:33:12 UTC 2026 · 📊 GitHub API quota 427/15,000 (3% used, resets in 43m)
🚀 Powered by Aspect CLI (v2026.28.2)  |  Aspect Build · X · LinkedIn · YouTube

@github-actions

github-actions Bot commented Jul 16, 2026

Copy link
Copy Markdown

py_binary startup benchmark

Version Mean (ms) Median (ms) ± stddev vs BCR vs main Build (s)
BCR 1.11.7 (baseline) 174.358 174.268 ±0.886 35.23
HEAD main 56.026 55.808 ±1.568 -67.9% 10.06
This PR 56.241 55.703 ±2.076 -67.7% +0.4% 8.28

Measured with hyperfine --warmup 5 --runs 50 on Linux
Gate: PR vs HEAD main (threshold: 10%). BCR is shown only as a historical baseline.
Build time: cold bazel build //:bench with isolated output base, no disk cache.

sys.path quality

Version sys.path entries distinct site-packages roots duplicate realpaths
BCR 1.11.7 (baseline) 6 1 0
HEAD main 7 2 0
This PR 7 2 0

sys.path quality measured by bench_syspath inside the assembled venv. Duplicate realpaths indicate symlink redundancy; many distinct site-packages roots suggest an inefficient venv layout.

Bazel analysis benchmark

Version Mean (ms) Median (ms) ± stddev vs BCR vs main Packages Targets
BCR 2.0.0-alpha.4 (baseline) 10982.282 10955.149 ±151.564 101 301
HEAD main 10458.960 10404.051 ±240.645 -4.8% 101 301
This PR 10185.628 10192.962 ±128.652 -7.3% -2.6% 101 301

Measured with hyperfine --warmup 1 --runs 10 on Linux
Gate: PR vs HEAD main (threshold: 10%). BCR is shown only as a historical baseline.
Command: cold bazel build --nobuild //workspace/... with isolated output base, no disk cache.

Auxiliary metrics

Version Loaded packages Configured targets
BCR 2.0.0-alpha.4 (baseline) 101 301
HEAD main 101 301
This PR 101 301

@jbedard jbedard force-pushed the reduce-rpython-deps-runtime branch 3 times, most recently from 63a1aad to 40bff69 Compare July 16, 2026 05:21
…s_python's

Generated interpreter repos now instantiate a rules_py py_runtime_toolchain
(py/private/interpreter/runtime.bzl, with a rules_py PyRuntimeInfo) instead of
rules_python's py_runtime + py_runtime_pair + py_exec_tools_toolchain. One
:runtime target per repo backs both toolchain registrations. Toolchain types
are unchanged (@bazel_tools python type; rules_python's exec_tools type, with
its exec_tools.exec_runtime/precompiler payload shape preserved), so
rules_python-provisioned interpreters still satisfy whl_install/site-merge and
rules_py still consumes user-registered rules_python py_runtime toolchains.

This shrinks each interpreter repo's rules_python loads from 31 .bzl files to
the 12 of the deliberately kept py_cc_toolchain chain, insulating provisioned
toolchains from rules_python implementation churn, and leaves the runtime
layer pinning no rules_python minimum version.

New coverage: e2e/rules-python-interop (isolated module) pins that a module
mixing both rulesets shares one rules_python-provisioned interpreter,
including a $(PYTHON3) location diff_test; e2e/cases/rules-python-consumers
pins that rules_python's own toolchain consumers (current_py_toolchain,
exec-tools readers) work against rules_py-backed toolchains.

Narrow breaks:
- Generated interpreter repo targets are renamed: @python_X//:py3_runtime,
  :runtime_pair, and :exec_tools_toolchain are now a single @python_X//:runtime.
  Only direct label references need updating; toolchain resolution is unaffected.
- rules_py-provisioned runtimes carry rules_py's PyRuntimeInfo, not
  rules_python's. Provider-indexed access (target[PyRuntimeInfo] with
  rules_python's symbol) on these targets or resolved toolchains breaks;
  duck-typed field access keeps working. As a consequence, rules_python's
  py_binary/py_test cannot execute on rules_py-provisioned toolchains (they
  read provider fields rules_py does not carry) — the same one-way interop
  direction #1231 establishes for PyInfo.
- The exec-tools toolchain rules_py registers provides precompiler = None;
  enabling rules_python precompiling while @python_interpreters toolchains are
  registered first is unsupported.
@jbedard jbedard force-pushed the reduce-rpython-deps-runtime branch from 40bff69 to 29f2165 Compare July 16, 2026 08:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant