Skip to content

feat(rules): describe runfiles groups for rules_runfiles_group - #4254

Open
FrankPortman wants to merge 6 commits into
bazel-contrib:mainfrom
FrankPortman:runfiles_group_describers
Open

FrankPortman wants to merge 6 commits into
bazel-contrib:mainfrom
FrankPortman:runfiles_group_describers

Conversation

@FrankPortman

@FrankPortman FrankPortman commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Gives py_library, py_binary/py_test and py_runtime_pair runfiles group describers for rules_runfiles_group, so packagers like rules_img's image_from_binary can split a Python binary into layers instead of shipping one big one.

A packager walks the binary with its own aspect and asks each target what it adds, so nothing runs unless you package. No flags. The groups:

  • rules_python#runtime: interpreter and stdlib, merged in from the Python toolchain. Every binary on that toolchain shares it.
  • rules_python#pypi/<name>: one per wheel. With venvs_site_packages=yes, the venv's links to a wheel's shared libraries go in that wheel's group too, so they stay next to the files they point at.
  • One per py_library, and one per rule target in data.
  • The binary itself, as the executable group.

A binary whose pyc_collection differs from the configuration's, or that generates legacy __init__.py files, keeps its deps in its own group, since their groups wouldn't match its runfiles.

Notes:

  • Walking the toolchain needs Bazel 8.8+. On older versions packaging fails; normal builds are unaffected.
  • Adds PyInfo.direct_implicit_pyc_files and PyExecutableInfo.venv_runfiles, since describers only see providers.
  • Only python/private/BUILD.bazel loads rules_runfiles_group, so there's no autoload cycle on Bazel 8.

Before merging:

  • Needs a rules_runfiles_group release. The DO NOT MERGE commit points the nested workspaces at the dev registry and gets reverted then.

Tested with runfiles_group_analysis_test, which checks the groups add up to exactly default_runfiles with no overlap, across a bunch of binary shapes, and end to end with rules_img.

Supersedes #3962. Written with LLM help (Claude); I've been through all of it and can own it in review.

Fixes #3757

Give py_library, py_binary and py_test runfiles group describers, so
packaging rules that use rules_runfiles_group (e.g. rules_img's
image_from_binary) can split a binary's runfiles into layers: the
runtime, one group per PyPI package, one per library and per rule
target in data, and the binary's own files.

Groups are collected on demand by a packager's aspect, so nothing runs
otherwise. The runtime group comes from a singleton target resolving
the same toolchain as the binary, so a packager builds it once per
configuration. A binary whose pyc_collection differs from the
configuration's, or that generates legacy __init__.py files, keeps its
dependencies in its own group.

Describers only see providers, so this adds PyInfo.direct_implicit_pyc_files
and PyExecutableInfo.venv_runfiles.

Fixes bazel-contrib#3757
Port to rules_runfiles_group's current API: the describers are held by
_aspect_rule_hints, and the runtime group is merged in from the Python
toolchain, described by py_runtime_pair. This drops the singleton
python_runtime_runfiles target.

Also fix two issues found testing against a real image:

* A Python target in srcs (whl_library's :pkg wraps its :srcs)
  describes its own files, so the wrapper no longer claims them too.
* With venvs_site_packages=yes, the venv's links to a wheel's files
  (shared libraries) go into that wheel's group instead of the
  binary's, so packagers keep them next to the files they point to.
…kspaces

Revert once rules_runfiles_group is released.
@FrankPortman
FrankPortman marked this pull request as ready for review October 19, 2026 13:43
Picks up the analysis test comparing symlinks by path and target.
rules_runfiles_group's lib.bzl loads its packager code, which needs a
recent bazel_features that WORKSPACE users don't have. Its new
describe.bzl doesn't, so loading the Python rules works in WORKSPACE
again without extra setup.

The analysis tests still go through the packager, so the dev WORKSPACE
gets bazel_features 1.51.0, and the tests are skipped on Bazel versions
whose aspects can't walk toolchains.

This branch has not been deployed

No deployments
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.

Emit RunfilesGroupInfo in py_binary targets

1 participant