Skip to content

refactor(zipapp): add dev-only toolchain for the Rust exe_zip_maker - #4215

Open
rickeylev wants to merge 7 commits into
bazel-contrib:mainfrom
rickeylev:dev_toolchain_plan_execution
Open

rickeylev wants to merge 7 commits into
bazel-contrib:mainfrom
rickeylev:dev_toolchain_plan_execution

Conversation

@rickeylev

@rickeylev rickeylev commented Oct 5, 2026 •

Copy link
Copy Markdown
Collaborator

PR #4151 added a Rust implementation of exe_zip_maker, but nothing used
it. This wires it in as dev-only, from-source toolchain so it can be
used and tested. For now, usage is gated by a private flag.

A new optional toolchain type,
//python/private/toolchain_types:exe_zip_maker, is consulted by the
py_zipapp_* rules. If not found, the Python based tool is used.

Analysis tests verify the Rust tool is selected when the flag is on and
the Python fallback is used when off.

Work towards #4216

PR bazel-contrib#4151 added a Rust implementation of `exe_zip_maker`, but nothing used
it. This wires it in for rules_python development only, leaving downstream
users on the Python implementation.

A new optional toolchain type,
`//python/private/toolchain_types:exe_zip_maker`, is consulted by
`py_binary`/`py_test` and `py_zipapp_*` when creating self-executable
zips. If no toolchain is resolved (or it provides no tool), the rules
fall back to the existing `_exe_zip_maker` attribute, so users and
WORKSPACE mode need no new registration and see no behavior change. When
the toolchain's tool is used, the action is bound to that toolchain type
so it runs on the exec platform the tool was built for.

A dev-only toolchain in `dev/dev_only_toolchains/` points at
`//crates/exe_zip_maker` and is registered with `dev_dependency = True`.
The `toolchain()` and its implementation live in separate packages so
registration doesn't load the implementation. It is gated behind
`--//dev/dev_only_toolchains:use_rust_exe_zip_maker`, which defaults to
off.

Analysis tests verify the Rust tool is selected when the flag is on and
the Python fallback is used when off.

Work towards bazel-contrib#4151
Use a string flag so `auto` can later let rules_python decide; for now
`auto` behaves as `no`. Also wrap a long load() line.
The `--build_python_zip` path in py_executable is deprecated, so there's
no need to wire the toolchain into py_binary/py_test. Restrict the
toolchain lookup to the py_zipapp rules and adjust the tests to cover
both flag states through py_zipapp instead.
`//python/private:distribution` auto-discovers subpackages and expects
each to declare a `:distribution` filegroup. The new `toolchain_types`
package lacked one, causing loading-phase errors in every CI job that
builds `//...`.
On Windows, py_zipapp emits the Bazel launcher instead of a
self-executable zip, so the PyZipAppCreateExecutableZip action the
tests assert on never exists there.
@rickeylev
rickeylev requested a review from jvolkman October 5, 2026 16:15
@rickeylev
rickeylev marked this pull request as ready for review October 5, 2026 16:18
@rickeylev
rickeylev requested a review from aignas as a code owner October 5, 2026 16:18
@rickeylev

Copy link
Copy Markdown
Collaborator Author

Ready for review. This is just the basics to use it via a toolchain and lay the groundwork for productionization.

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.

1 participant