Repository navigation
Replies: 6 comments 17 replies
|
Thanks for this proposal, sounds very convincing for me, but would love to see a prototype to test against our cared use cases (like with protobuf).
Do you have a link to those modules?
@Wyverald We should think about how to smoothly migrate them out of bazel_tools. |
|
Popping in to mention that "utility module that brings in toolchains" is a real concern to remember! This transition is feasible for us, but we do rely on this behavior and would need to migrate. However, the behavioral improvement is a huge net positive so I think we'd migrate as soon as able. |
|
This sounds good. I think most of the concerning cases are around modules that define CC toolchains, which will arguably be more clear and correct after this is implemented. My biggest concern is Speaking of changes to CC toolchains, I feel we should make the proposed change to move local CC toolchain detection into a separate module and out of |
|
Limiting If I'm understanding correctly, the main functional benefit of this proposal is that Bazel can assume that A few preliminary questions:
Flag vs MODULE.bazelMy main feedback/request is: for users that will need to migrate anyway by explicitly registering their toolchain in the root module, can we recommend that they use the The A potential long-term story that I think fits together nicely is that toolchains are eventually referenced either:
That is the core proposition of my proposal Make Toolchain Resolution Local. This proposal overlaps in recognizing that two modules are "special" when it comes to toolchains: the module that defines the toolchain type and the root module. Compared with "Make Toolchain Resolution Local"I view this proposal as a more incremental version of Make Toolchain Resolution Local that captures some of the benefits while requiring fewer changes from users. In particular, it accomplishes these benefits from the other proposal:
In the future we could consider trying to land Make Toolchain Resolution Local, which would be made easier if this proposal lands first. That would bring the following additional benefits:
|
|
I thought a bit more about the 'escape hatch' idea we discussed at today's SIG meeting. The basic idea: with this proposal, to resolve toolchains of type T, Bazel only looks at the toolchain registrations of the root module and the owner of T. As an escape hatch, a module M can declare that it needs to register toolchains of a 'foreign' type T even when it's not the root module, so that Bazel also considers it for T. This is an API that should be used sparingly. I had a few ideas regarding the exact API, all of which are MODULE.bazel additions -- which would need to be backported, so we should try to decide soon. In the order of my preference:
|
|
I tried the #32487 prototype against a real non-LTS JDK catalog A catalog can reduce the consumer change to one root registration. The catalog previously registered runtime toolchains from generated per-JDK The same registration is accepted on Bazel 9.3.0 and on the prototype. On 9.3.0, This looks like a useful concrete example for the migration docs — authors can The pre-migration failure sequence (stock rules_java), for testing guidance. At prototype The native helper is an analysis dependency of the selected stock Java toolchain If a non-root integration fixture would help the Java/C++ type migrations, this |
Uh oh!
There was an error while loading. Please reload this page.
In the Bzlmod BoF session at BazelCon 2026 and in other channels, the following challenges with Bzlmod have come up repeatedly:
bazel_deps can cause noticeable overhead (bytes downloaded from the network, time spent extracting archives, …) even when they aren't directly connected to the current build. For example, building a Bazel workspace with just ansh_binarycurrently fetches 65 repos, which requires 19 downloads of 32 MB in total, while only 9 repos and 4 downloads of 0.1 MB total are actually used in the build.bazel_deps can register unwanted toolchains that result in surprising injection of behavior. For example, some BCR modules currently register custom Python interpreters.There have been a few proposals that aim to address these issues, such as by introducing a feature system that supports optional deps or by requiring toolchain types to exhaustively list their toolchain implementations. A more drastic idea has been to disallow any toolchain registration outside the root module, perhaps gradually controlled via one or more flags.
I am currently exploring ways to make progress on 1. and 2. without adding new API to Bazel and without requiring changes to a considerable share of modules in the BCR. I'm looking for feedback on the following idea.
Limiting toolchain registrations to the module defining a toolchain type
Behind an incompatible flag, Bazel would ignore all toolchain registrations for a toolchain type defined in a repo A unless the registering module is one of
It would also ignore (or even disallow) all registered non-dev execution platforms in non-root modules (there are none in the entire BCR).
This would address issue 1 for builds as the sources of all the extra downloads are that Bazel needs to resolve the patterns for all toolchain registrations in all modules since it doesn't know what types they will ultimately resolve to.
This would also address a good chunk of issue 2 as the only source for a
langtoolchain beyond the root module would then berules_lang'sMODULE.bazel, which greatly narrows down the scope for inspection and (if necessary) patching. This also ensures that registration ordering across modules (which is deterministic, but difficult to keep stable as deps are added) can't affect the outcome of resolutions anymore.With the exception of seven C++ toolchain and three other modules in the BCR whose users would have to start explicitly registering the toolchains they provide, a survey of all latest versions of all BCR modules found no other cases where intentional behavior would necessarily be broken. Six modules would have to release new versions to remain functional with this change, but users would not be impacted beyond having to update to them. A few modules would no longer leak their registrations, which appeared unintentional upon inspection, to consumers.
rules_java,rules_ccandrules_python's toolchain types would move frombazel_toolsinto the respective modules, which is independently useful for the ongoing work to decouple the Bazel core from specific rulesets.Since registrations that don't follow these rules are ignored and not an error, the only consequence can be that a certain toolchain is no longer registered or that the order of registrations changes across modules. Note that making this an error wouldn't actually be possible without reintroducing the eager fetching, but BCR CI exercises this path since it tests all modules as non-root modules.
Users with custom registries would also be affected by this change. If they rely on utility modules that bring in toolchains, those would now need to be registered with an explicit
register_toolchainscall in the root module. If more complex aggregation from transitive toolchains is needed, a module extension could collect and stamp out the toolchains so that a single wildcard pattern can match them.Notes
bazel mod depsorbazel mod tidy, which forcibly evaluate all module extensions to ensure that the resulting lockfile is complete. This can cause a lot of fetches and requires further changes (e.g., the introduction of a default scope for the lockfile), but also benefits from more restricted toolchain registrations.rules_multitoolis an example that even dynamically generates toolchain types). Crucially, this would now require explicit opt-in by providing a dedicated extension interface.All reactions