`use_repo_rule` doesn't allow macros that invoke repository rules
- Dominant language
- Java
- Stars
- 25.8k
- Forks
- 4.6k
- Avg merge
- 2d 20h
- Merged PRs (30d)
- 72
Description
### Description of the feature request:
We have a macro that wraps `http_archive`, that looks like this:
```starlark
def github_archive(*, name, owner, sha256, version = None, commit = None, prefix = None, **kwargs):
nwo = "%s/%s" % (owner, name)
if int(bool(version)) + int(bool(commit)) != 1:
fail("Exactly one between commit and version must be provided for %s" % nwo)
if version:
download = "archive/refs/tags/v%s.tar.gz" % version
else:
download = "archive/%s.tar.gz" % commit
strip_prefix = "%s-%s" % (name, version or commit)
if prefix:
strip_prefix = "%s/%s" % (strip_prefix, prefix)
http_archive(
name = name.lower(),
sha256 = sha256,
patch_args = ["-p1"],
strip_prefix = strip_prefix,
url = "https://github.com/%s/%s" % (nwo, download),
**kwargs
)
```
We want to use this from `MODULE.bazel` like this:
```starlark
github_archive = use_repo_rule("//:github_archive.bzl", "github_archive")
github_archive(
name = "...",
owner = "...",
commit = "...",
sha256 = "...",
)
```
This currently fails with
```
ERROR: //:github_archive.bzl does not export a repository_rule called github_archive, yet its use is requested at XXX/MODULE.bazel:58:15
```
It'd be great if calling a macro that wraps a repository_rule would be compatible with `use_repo_rule`. Right now, we need a module extension that calls the macro, and thread through the name to `use_repo` on that module extension, too.
### Which category does this issue belong to?
External Dependency
### What underlying problem are you trying to solve with this feature?
Make wrapping repository rules easier to use with bzlmod.
In the old workspace world, there was no difference between invoking a repository rule, and a macro that wraps one.
### Which operating system are you running Bazel on?
_No response_
### What is the output of `bazel info release`?
release 7.0.2
### If `bazel info release` returns `development version` or `(@non-git)`, tell us how you built Bazel.
_No response_
### What's the output of `git remote get-url origin; git rev-parse HEAD` ?
_No response_
### Have you found anything relevant by searching the web?
_No response_
### Any other information, logs, or outputs that you want to share?
_No response_
Contributor guide
Research direction
Start with the github_archive.bzl and MODULE.bazel examples in the issue and reproduce the current use_repo_rule failure on Bazel 7.0.2. Trace how use_repo_rule identifies exported repository rules and how macros invoking them are represented. Done means a macro wrapping a repository_rule can be used from MODULE.bazel without requiring a module extension and separate use_repo wiring.
Written by the indexing model from the issue text.
Assessment
- Domain
- build-system
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100