Skip to content

Module repo is fully materialized under --experimental_remote_repo_contents_cache #143

Description

@spencer1872ai

--experimental_remote_repo_contents_cache (Bazel 9) is supposed to keep @@rules_req_compile+ as an in-memory overlay and only pull blobs that are actually read. Consumers with that flag on still see this on essentially every command:

DEBUG: Materializing remote repo @@rules_req_compile+

That means the whole module tree is copied onto disk instead of staying in the overlay.

Cause

The overlay can serve individual files. Bazel's own loading (load(), BUILD files) already does that; .bzl files are even prefetched.

module_ctx.path(Label) / repository_ctx.path(Label) / ctx.read(Label) do not. They all go through getPathFromLabel, which unconditionally calls ensureMaterialized on any non-main repo before returning a host path:

https://github.com/bazelbuild/bazel/blob/master/src/main/java/com/google/devtools/build/lib/bazel/repository/starlark/StarlarkBaseExternalContext.java

path() is the "give me a native filesystem path" API (the same one execute() uses), so Bazel dumps the entire overlay rather than one blob. read(Label) is implemented as getPath() then readContent, so switching path() to read() does not avoid this.

isMain() skips materialization, so consumer lockfiles in the main repo are fine.

Call sites (1.1.3 / current main)

These all path() labels inside this module, and they run for every consumer (not dev_dependency):

  1. sdist_deps in private/sdist.bzlparse_requirements_locksctx.path(Label("//private:sdist_requirements.txt")).
  2. requirements.parse for @req_compile_deps in MODULE.bazelpath() of the five //3rdparty/requirements.*.txt lockfiles (once in the module extension, again when the hub repo rule runs).
  3. whl_repository in private/whl_repo.bzl — default _compiler = Label("//private:sdist_compiler.py") on every wheel repo. Bazel also walks label attrs up front (enforceLabelAttributes), so this fires even when no sdist is built.

Suggested fix

Do not convert labels in this module into host paths.

  • load() the sdist lockfile and the req_compile_deps lockfiles as .bzl string constants; parse those strings instead of ctx.path()/ctx.read(Label).
  • Drop the default _compiler file label. When an sdist actually needs building, write the compiler script into the generated wheel repo (repository_ctx.file(...)) and path() that local file (a string path, not a Label into this module).

.bzl load() is the overlay-prefetch path, so it does not materialize.

I have a working consumer-side patch along those lines if useful as a starting point.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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