Skip to content

bzlmod: Incompatible with pure MODULE.bazel setup due to "generate-then-load" pattern #36

@hugomano

Description

@hugomano

The Goal

I want to configure rules_ml_toolchain in a pure bzlmod project so I started to write an overlay to declare it as publishable module.

The Problem: "Generate-then-Load" Pattern

The current setup process is incompatible with a pure bzlmod workflow due to its reliance on a "generate-then-load" pattern. The setup requires a sequence of operations that cannot be expressed declaratively in MODULE.bazel.

For example, the CUDA setup follows these steps:

  1. Generate: The cuda_json_init_repository rule is called. It runs during the Analysis Phase and generates a new repository (@cuda_redist_json) containing a distributions.bzl file.
  2. Load: The script must then execute load("@cuda_redist_json//:distributions.bzl", "CUDA_REDISTRIBUTIONS") to get a variable from the file that was just created.
  3. Consume: This variable is then passed to another repository rule, cuda_redist_init_repositories.

This creates a fundamental conflict with Bazel's architecture:

  • All load() statements are processed during the Loading Phase.
  • Repository rules are executed later, during the Analysis Phase.

A pure MODULE.bazel setup cannot load() a file that will only be created in a future phase. This forces users to adopt the WORKSPACE.bzlmod file, which prevents a fully modern and clean Bazel setup.

Thank you for considering this enhancement.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions