Skip to content

Limit toolchain registration to only toolchain-containing packages. #83

@rickeylev

Description

@rickeylev

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions