bazel-contrib / bazel-contrib/rules_python

Add in-build toolchain registration to python.toolchain

未关闭
#2,216 4 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
help wanted
主要语言
Starlark
星标
688
派生
721
平均合并
15 小时 7 分钟
30 天内合并 PR
76

描述

# 🚀 feature request

### Relevant Rules

* `//python/extensions:python.bzl`: `python.toolchain`
* `//python:repositories.bzl`: `python_register_toolchains`

### Description

While the underlying rules for python toolchains/runtimes support python stacks which are actual Bazel-built targets passed in by label, `python_register_toolchains`, and by extension, the `python.toolchain` tag class, does not offer a way to do this. At present it supports only downloading hermetic toolchains from GitHub by version number. While one can technically do all the behind-the-scenes work that it performs using one's own module/workspace code, what exactly they do and what expectations they have for the repositories one points them at are not documented. Especially as we make more use of additional types of toolchains (cc toolchains, exec tools toolchains), discovering and writing this much code is an increasing burden. We should provide better support for people who supply their own python stacks, either built from source or precompiled.

### Describe the solution you'd like

Digging through `python_register_toolchains` and a bunch of other code, it looks like each platform expects three toolchains, a coverage tool, a config setting, and the seven other targets which `toolchain_aliases` repositories name. For each case like this, we can either define a contract for what targets the user-supplied repository+package needs to provide (perhaps using some helpful macros or tag classes from us), then ask them to tell us where to fetch it from and how to patch it; or prompt for each of these things individually. Either way, we could do this either by extending the existing `python_register_toolchains` and `py.toolchain`, or by defining a new pair of these things dedicated to this use case.

For python stacks built from source, we can allow people to supply just one repository+package to use everywhere and let Bazel do all the platform management for us. I don't know how best to build a good UX around this for python stacks supplied as binaries without forcing a lot of repetition onto people who want to support lots of platforms. But to an extent that work is also self-imposed, and people could use macros or a platform-based, `toolchain_aliases`-like repository to manage that complexity.

### Describe alternatives you've considered

Instead of supporting the in-build use case ourselves, we could document what people need to do in order to do it themselves and still be able to integrate with the python ecosystem correctly. That makes it far less likely that people will overlook things like they would with source code dives, but it does effectively force people to reimplement much of our finicky loading phase code. Most of the smaller bits comprising it aren't exposed publicly, but perhaps opening some of it up would help support that scenario a bit.

贡献指南

打开贡献指南

调研方向

从 `python/extensions/python.bzl` 和 `python/repositories.bzl` 开始,结合 issue 中描述的底层 toolchain 和 `toolchain_aliases` 预期,跟踪 `python.toolchain` 和 `python_register_toolchains`。确定 Bazel 构建的 Python stack 所需的 contract 或 interface,并将完成定义为:提供有文档说明、可在 build 中使用的注册机制,能够处理所需的平台 target,而无需重新实现 loading phase 的细节。

由索引模型根据 Issue 内容生成。

评估

技术栈
python
领域
build-system
Issue 类型
功能
难度
5/5
预计耗时
一周以上
活跃度
停滞
描述清晰度
需要澄清
新手友好度
25/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。