bazel-contrib / bazel-contrib/rules_python
Avoid downloading protobuf dependancy when not needed
- 主要言語
- Starlark
- スター
- 688
- フォーク
- 721
- 平均マージ
- 15時間 7分
- マージ済み PR(30日)
- 76
説明
Hi we recently migrated a project from workspace to bzlmod and noticed our builds now pull in more things from the internet as a result.
In particular we saw that our builds started to download protobuf (from https://github.com/protocolbuffers/protobuf/releases/download/v29.0-rc2/protobuf-29.0-rc2.zip).
This was despite none of our targets referencing (either directly nor indirectly) `py_proto_library` (or any other protobuf target from `rules_python` or any other module).
It seems that in a workspace project dependencies are fetched lazily [1] whereas in a bzlmod project, dependencies are fetched eagerly.
Reading the source of this library, I saw a comment in the MODULE.bzl https://github.com/bazelbuild/rules_python/blob/29fdcc2c292d64e7c66746d1c701ab67aa05c79b/MODULE.bazel#L12 that suggests the `protobuf` dep will be loaded only if the `py_proto_library` is used. However, that doesn't match my tests where `protobuf` is download by all projects that depend on `rules_python` even if they do not use _any_ rules from it [2].
I am wondering
1. if there is a way to use `rules_python` without pulling `protobuf` if we do not need protobuf support?
2. If the comment linked above needs updating/removing?
#### Related
I think https://github.com/bazelbuild/rules_python/issues/2498 is similar although that is about rules_kotlin and is more about toolchains fetched as module extensions rather than modules downloaded directly.
#### Notes
1: https://bazel.build/extending/repo#when_is_the_implementation_function_executed
2: You can test this by creating a custom registry (https://bazel.build/external/registry) and modifying the `source.json` file of all the protobuf modules to set the `url` field to something that does not exist. Building a bzlmod project that uses rules_python but does not have any `py_proto_library` targets will then fail showing that bazel does try to fetch protobuf.
コントリビューションガイド
調査の方向性
まず MODULE.bzl の12行目付近を読み、bzlmod 下で protobuf 依存関係が py_proto_library とどのように関係しているかを追跡します。protobuf のソース URL が無効なカスタムレジストリを使い、rules_python に依存しているものの protobuf ターゲットを定義していないプロジェクトで、その動作を再現します。対応するサポートが使用されない限り、プロジェクトが protobuf の取得を試みなくなり、コメントまたはドキュメントがその動作と一致していれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- build-system
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100