Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,7 @@ import %workspace%/specialized_configs.bazelrc
import %workspace%/buildbuddy.bazelrc

try-import user.bazelrc

# TODO: Delete before merging. rules_runfiles_group's describer API isn't in the
# BCR yet; see https://github.com/bazelbuild/rules_java/pull/368.
common --registry=https://bazel-contrib.github.io/rules_runfiles_group --registry=https://bcr.bazel.build
1 change: 1 addition & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ bazel_dep(name = "bazel_skylib", version = "1.8.2")
bazel_dep(name = "package_metadata", version = "0.0.7")
bazel_dep(name = "platforms", version = "0.0.11")
bazel_dep(name = "rules_cc", version = "0.2.17")
bazel_dep(name = "rules_runfiles_group", version = "99.0.0-dev.20261019.1.d105dfa")
bazel_dep(name = "toml.bzl", version = "0.4.1")

# Those are loaded only when using py_proto_library
Expand Down
3 changes: 3 additions & 0 deletions examples/bzlmod/.bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,6 @@ test --test_output=errors --enable_runfiles
# Windows requires these for multi-python support:
build --enable_runfiles
common:bazel7.x --incompatible_python_disallow_native_rules

# TODO: Delete before merging; see the root .bazelrc.
common --registry=https://bazel-contrib.github.io/rules_runfiles_group --registry=https://bcr.bazel.build
3 changes: 3 additions & 0 deletions examples/multi_python_versions/.bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ build --enable_runfiles

coverage --java_runtime_version=remotejdk_11
common:bazel7.x --incompatible_python_disallow_native_rules

# TODO: Delete before merging; see the root .bazelrc.
common --registry=https://bazel-contrib.github.io/rules_runfiles_group --registry=https://bcr.bazel.build
3 changes: 3 additions & 0 deletions examples/pip_parse/.bazelrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# https://docs.bazel.build/versions/main/best-practices.html#using-the-bazelrc-file
try-import %workspace%/user.bazelrc
common --incompatible_python_disallow_native_rules

# TODO: Delete before merging; see the root .bazelrc.
common --registry=https://bazel-contrib.github.io/rules_runfiles_group --registry=https://bcr.bazel.build
3 changes: 3 additions & 0 deletions gazelle/.bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,6 @@ build --enable_runfiles
common --noincompatible_no_implicit_file_export

common:bazel7.x --incompatible_python_disallow_native_rules

# TODO: Delete before merging; see the root .bazelrc.
common --registry=https://bazel-contrib.github.io/rules_runfiles_group --registry=https://bcr.bazel.build
3 changes: 3 additions & 0 deletions gazelle/examples/bzlmod_build_file_generation/.bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@ common:bazel7.x --incompatible_python_disallow_native_rules
# rules_python code. In the BCR presubmits, this override is removed
# and the bazel_dep version of rules_python is used.
common --override_module=rules_python=../../../

# TODO: Delete before merging; see the root .bazelrc.
common --registry=https://bazel-contrib.github.io/rules_runfiles_group --registry=https://bcr.bazel.build
6 changes: 3 additions & 3 deletions internal_dev_deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,9 @@ def rules_python_internal_deps():

http_archive(
name = "bazel_features",
sha256 = "d7787da289a7fb497352211ad200ec9f698822a9e0757a4976fd9f713ff372b3",
strip_prefix = "bazel_features-1.9.1",
url = "https://github.com/bazel-contrib/bazel_features/releases/download/v1.9.1/bazel_features-v1.9.1.tar.gz",
sha256 = "5450bfb2c8b4bc961c75368838f86156f563cc9adef1be7d504fc5619d54daab",
strip_prefix = "bazel_features-1.51.0",
url = "https://github.com/bazel-contrib/bazel_features/releases/download/v1.51.0/bazel_features-v1.51.0.tar.gz",
)

http_archive(
Expand Down
5 changes: 5 additions & 0 deletions news/3757.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
(rules) `py_binary` and `py_test` describe their runfiles groups for
[rules_runfiles_group](https://github.com/bazel-contrib/rules_runfiles_group),
so packaging rules like rules_img's `image_from_binary` can put the runtime,
each PyPI package and each library in a layer of its own. Needs Bazel 8.8 or

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if this is ideal, but it can be a good default.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, it's meant as the default. there's now a test showing how to change it per binary through aspect_hints. central config is the open question, I put the options in a top level comment.

later ([#3757](https://github.com/bazel-contrib/rules_python/issues/3757)).
41 changes: 41 additions & 0 deletions python/private/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ load(":bazel_config_mode.bzl", "bazel_config_mode")
load(":distribution_filegroup.bzl", "distribution_filegroup")
load(":py_exec_tools_toolchain.bzl", "current_interpreter_executable")
load(":py_interpreter_program.bzl", "py_interpreter_program")
load(
":runfiles_groups.bzl",
"py_executable_runfiles_group_describer",
"py_library_runfiles_group_describer",
"py_runtime_pair_runfiles_group_describer",
)
load(":sentinel_impl.bzl", "sentinel")
load(":stamp_impl.bzl", "stamp_build_setting")
load(":uncachable_version_file.bzl", "define_uncachable_version_file")
Expand Down Expand Up @@ -849,6 +855,23 @@ bzl_library(
],
)

bzl_library(
name = "runfiles_groups",
srcs = ["runfiles_groups.bzl"],
deps = [
":attributes",
":common",
":flags",
":py_executable",
":py_executable_info",
":py_info",
":py_internal",
":py_library",
":reexports",
"@rules_runfiles_group//runfiles_group:describe",
],
)

bzl_library(
name = "runtime_env_repo",
srcs = ["runtime_env_repo.bzl"],
Expand Down Expand Up @@ -1044,3 +1067,21 @@ bzl_library(
name = "visibility",
srcs = ["visibility.bzl"],
)

# Runfiles group describers of the Python rules (see runfiles_groups.bzl), held
# by their _aspect_rule_hints attributes. Not actually public; only public
# because they're implicit dependencies of rules built via the rule builders.
py_library_runfiles_group_describer(
name = "py_library_runfiles_group_describer",
visibility = ["//visibility:public"],
)

py_executable_runfiles_group_describer(
name = "py_executable_runfiles_group_describer",
visibility = ["//visibility:public"],
)

py_runtime_pair_runfiles_group_describer(
name = "py_runtime_pair_runfiles_group_describer",
visibility = ["//visibility:public"],
)
7 changes: 7 additions & 0 deletions python/private/py_executable.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,17 @@ EXECUTABLE_ATTRS = dicts.add(
WINDOWS_CONSTRAINTS_ATTRS,
# starlark flags attributes
{
# Read by rules_runfiles_group's packaging aspects; see runfiles_groups.bzl.
"_aspect_rule_hints": attr.label_list(default = [
"//python/private:py_executable_runfiles_group_describer",
# What //python:toolchain_type is an alias of.
"@bazel_tools//tools/python:toolchain_type",
Comment thread
aignas marked this conversation as resolved.
]),
"_build_python_zip_flag": attr.label(default = "//python/config_settings:build_python_zip"),
"_default_to_explicit_init_py_flag": attr.label(default = "//python/config_settings:incompatible_default_to_explicit_init_py"),
"_python_import_all_repositories_flag": attr.label(default = "//python/config_settings:experimental_python_import_all_repositories"),
"_python_path_flag": attr.label(default = "//python/config_settings:python_path"),
"_runfiles_group_attrs": attr.string_list(default = ["_debugger_flag", "data", "deps", "srcs"]),
},
{
"interpreter_args": lambda: attrb.StringList(
Expand Down
5 changes: 5 additions & 0 deletions python/private/py_library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ This allows optimizing the generation of symlinks to be cheaper at analysis time
"_add_srcs_to_runfiles_flag": lambda: attrb.Label(
default = labels.ADD_SRCS_TO_RUNFILES,
),
# Read by rules_runfiles_group's packaging aspects; see runfiles_groups.bzl.
"_aspect_rule_hints": lambda: attrb.LabelList(
default = ["//python/private:py_library_runfiles_group_describer"],
),
"_runfiles_group_attrs": lambda: attrb.StringList(default = ["data", "deps", "srcs"]),
},
)

Expand Down
6 changes: 6 additions & 0 deletions python/private/py_repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ def py_repositories(transition_settings = []):
strip_prefix = "rules_cc-0.1.5",
urls = ["https://github.com/bazelbuild/rules_cc/releases/download/0.1.5/rules_cc-0.1.5.tar.gz"],
)
http_archive(
name = "rules_runfiles_group",
sha256 = "0c5a2998f970e8ec27daa9bc10c3cd0d4a7167371acd70974a75ab8aafb41c74",
strip_prefix = "rules_runfiles_group-d105dfab75fb550bcfc0d2cc033b27fad0dfc2e4",
url = "https://bazel-contrib.github.io/rules_runfiles_group/assets/rules_runfiles_group/99.0.0-dev.20261019.1.d105dfa/source.tar.gz",
)
http_archive(
name = "toml.bzl",
sha256 = "63633c762bdb4d836add5a9a81deeeae93c4b2edbd62ac032733020b5652b90a",
Expand Down
5 changes: 5 additions & 0 deletions python/private/py_runtime_pair_rule.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ The runtime to use for Python 3 targets. Must have `python_version` set to
`PY3`.
""",
),
# Read by rules_runfiles_group's packaging aspects; see runfiles_groups.bzl.
"_aspect_rule_hints": attr.label_list(
default = ["//python/private:py_runtime_pair_runfiles_group_describer"],
),
"_runfiles_group_attrs": attr.string_list(default = []),
"_visible_for_testing": attr.label(
default = labels.VISIBLE_FOR_TESTING,
),
Expand Down
Loading
Loading