Hi.
I'm trying to migrate our build to bzlmod. One of our dependencies (
bazel-latex) doesn't use modules, and makes use of a repository rule to set up its dependencies:
# Root WORKSPACE.bazel
http_archive(name="bazel-latex", ... )
load("@bazel_latex//:repositories.bzl", "latex_repositories")
latex_repositories()
I have a custom registry for our internal dependencies, and I'm using an overlay to add a MODULE.bazel to bazel-latex.
As I understand it, I have two options to migrate this to bzlmod:
1. I can manually introduce every dependency pulled in by latex_repositories() into the overlaid module file, or,
2. I can invoke latex_repositories() via a module extension.
I prefer the latter since it allows me to gracefully capture any changes to the set of dependencies brought in by latex_repositories(). (Indeed, option 1 isn't super-easy since the function's behavior depends on the platform, and there are a lot of dependencies to define.)
1. Add an extensions.bzl to bazel-latex (via an overlay) that loads //:repositories.bzl and wraps latex_repositories in a module extension:
# extensions.bzl
load("//:repositories.bzl", "latex_repositories")
def _latex_deps_impl(ctx):
latex_repositories()
latex_deps = module_extension(implementation = _latex_deps_impl)
2. In the overlaid MODULE.bazel, invoke the extension:
# MODULE.bazel
latex_deps = use_extension("//:extensions.bzl", "latex_deps")
use_repo(latex_deps, "some_random_name")
To test this I cloned the bazel-latex repo, added the two files above, and tried building bazel-latex. I expected the build to succeed, but instead it complains that the dependencies specified by latex_repositories() aren't defined e.g.:
ERROR: no such package '@@[unknown repo 'texlive_texmf__texmf-dist__tex__luatex__luaotfload' requested from @@]//': The repository '@@[unknown repo 'texlive_texmf__texmf-dist__tex__luatex__luaotfload' requested from @@]' could not be resolved: No repository visible as '@texlive_texmf__texmf-dist__tex__luatex__luaotfload' from main repository
Interestingly, when playing around with this, I had a typo in use of use_extension, where I had misspelled "latex_deps" as "latek_deps". The build complained in the same way (no repo visible from the main repo), which suggests that it wasn't actually looking for the extension correctly.
I did try approach 1 of explicitly pulling in the repos added by latex_repositories (which did seem to work), but there are almost 200 such dependencies, and that way lies madness, I believe. I've reached the limit of my ability to debug what's going on, so any advice would be appreciated.