Skip to content

feat(packaging): support Python toolchain make variables in py_wheel - #4257

Merged
rickeylev merged 3 commits into
bazel-contrib:mainfrom
rickeylev:py_wheel_makevar_support
Oct 13, 2026
Merged

rickeylev merged 3 commits into
bazel-contrib:mainfrom
rickeylev:py_wheel_makevar_support

Conversation

@rickeylev

Copy link
Copy Markdown
Collaborator

Setting version-specific wheel tags (python_tag, abi, platform)
and python_requires metadata in py_wheel previously required custom
select() expressions or TemplateVariableInfo rules. Additionally,
platform and python_requires did not expand make variables.

Populate TemplateVariableInfo on py_runtime_pair with Python
version, implementation, and wheel tag variables (such as
PY_WHEEL_PYTHON_TAG, PY_WHEEL_ABI_TAG, and PY_MAJOR_DOT_MINOR),
and forward them through current_py_toolchain. Attach the target
Python toolchain to py_wheel so these variables are available by
default, and expand make variables in platform and python_requires.

Setting version-specific wheel tags (`python_tag`, `abi`, `platform`)
and `python_requires` metadata in `py_wheel` previously required custom
`select()` expressions or `TemplateVariableInfo` rules. Additionally,
`platform` and `python_requires` did not expand make variables.

Populate `TemplateVariableInfo` on `py_runtime_pair` with Python
version, implementation, and wheel tag variables (such as
`PY_WHEEL_PYTHON_TAG`, `PY_WHEEL_ABI_TAG`, and `PY_MAJOR_DOT_MINOR`),
and forward them through `current_py_toolchain`. Attach the target
Python toolchain to `py_wheel` so these variables are available by
default, and expand make variables in `platform` and `python_requires`.
In Bazel 7 and WORKSPACE builds, `py_runtime_pair` may receive a legacy
`BuiltinPyRuntimeInfo` provider, which does not define `abi_flags`,
`implementation_name`, or `interpreter_version_info`.

Check `hasattr(py3_runtime, "abi_flags")` before reading those fields
when populating `TemplateVariableInfo`.
@rickeylev
rickeylev requested a review from jvolkman October 13, 2026 05:04
@rickeylev
rickeylev marked this pull request as ready for review October 13, 2026 05:43
@rickeylev
rickeylev requested a review from aignas as a code owner October 13, 2026 05:43
Python 2 is no longer supported by `py_runtime_pair`, so `py3_runtime`
is always used.

Remove the `py2_runtime` branch and make `py3_runtime` handling
non-conditional in `_get_template_vars`.
@rickeylev
rickeylev added this pull request to the merge queue Oct 13, 2026
@rickeylev

Copy link
Copy Markdown
Collaborator Author

Ah, I'm recalling a conversation where we talked about moving the filename generation to use the heuristics that auditwheel (or repairwheel?) uses to determine the platform (by inspecting the .so file symbols etc). I think ultimately we should have that as the default behavior, with values like "auto" to trigger that. but for now, this is a step forward.

A coworker also mentioned that rules_ml_toolchain does provide the manywheel compliance level as a setting somewhere, so maybe there is a way to plumb that up into py_wheel via, idk, the cc toolchain or something and into a makevar.

@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 13, 2026
@rickeylev
rickeylev added this pull request to the merge queue Oct 13, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 13, 2026
@rickeylev
rickeylev added this pull request to the merge queue Oct 13, 2026
Merged via the queue into bazel-contrib:main with commit fa2aa24 Oct 13, 2026
5 checks passed
@rickeylev
rickeylev deleted the py_wheel_makevar_support branch October 13, 2026 18:14
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.

2 participants