-
Notifications
You must be signed in to change notification settings - Fork 22
Description
I noticed that in workspace, and now the bzlmod extension, the entire cc subdirectory is recursively registered:
register_toolchains("//cc/...")
https://github.com/google-ml-infra/rules_ml_toolchain/blob/main/WORKSPACE#L138
This is bad because it makes Bazel go through (at least) the loading phase for every build file recursively, which can incur many unncessary loads. In particular, it would process all the BUILD files under cc/impls, which is where the toolchain implementation targets live -- thus it has to loading-phase all the implementations, which largely defeats the point of toolchains (to defer such evaluation unless actually necessary). (I'm not sure how much, if any, of analysis phase is processed by register_toolchains, but at least loading is performed).
Instead, a dedicated directory with a single BUILD.bazel file of toolchain() calls should be created and registered. A single BUILD file of toolchain() calls is best because the order of processing of toolchains is well defined. A tree of BUILD files could also be used, it's just less clear about ordering.
In any case, the key attribute is that whatever pattern is used with register_toolchains(...), it expands to only toolchain() calls.