rules_python
rules_python copied to clipboard
Use response files for zipper arguments to prevent "Argument list too long" errors
🚀 feature request
Relevant Rules
py_binary, py_test (from @rules_python)
Description
When building Python binaries or tests using Bazel (specifically with py_binary and py_test), we encounter an "Argument list too long" error during the build process. This happens when our projects depend on a very large number of files, particularly those from large Python libraries managed by pip_parse (e.g., boto3, msgraph-sdk-python).
The root cause seems to be that Bazel calls the zipper tool by passing all file paths to be included in the package directly as command-line arguments. https://github.com/bazel-contrib/rules_python/blob/9429ae6446935059e79047654d3fe53d60aadc31/python/private/py_executable.bzl#L891-L957
This leads to the argument list exceeding the operating system's ARG_MAX limit.
This error makes our Bazel builds unstable and undermines the reliability of our CI/CD pipelines for large Python projects.
Describe the solution you'd like
We propose enhancing rules_python to always pass arguments to the zipper tool via a temporary response file, rather than directly on the command line.
Upon inspecting zipper's zip_main.cc source code, it appears to support reading arguments from a file using the @
By consistently utilizing this response file capability, rules_python can entirely bypass OS ARG_MAX limitations.