-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide module extensions with a way to reference extension repos #19055
Comments
CC @Wyverald @meteorcloudy, I am especially interested in your opinion on the alternative approach. If it is feasible, I could see this being better than introducing new API. |
The alternative approach might not be possible since you could do this: def _extension_impl(mctx):
repo_rule(name="foo")
print(str(Label("@foo//:abc")))
# or with the API
print(mctx.extension_repo_label("@foo//:abc")) To clarify, we can't really "smartly" handle the first |
Do we really want users to construct |
I'm undecided. The decision probably needs more input data. Design doc time :) |
It's interesting to see how rules_java works around this: It basically passes the label ( |
Eager fetching of all labels listed in repo rule attributes was introduced as a performance optimization to avoid costly restarts. Now that restarts are gone by default, this is no longer a benefit as it can cause unnecessary fetches and also create cycles where there wouldn't be any without this behavior (e.g. when two repos write each others labels into a file without resolving them). Work towards #19055 Closes #23371. PiperOrigin-RevId: 665744319 Change-Id: Ia27f207793a2da3fb8e37743b328483f9d45192c
Eager fetching of all labels listed in repo rule attributes was introduced as a performance optimization to avoid costly restarts. Now that restarts are gone by default, this is no longer a benefit as it can cause unnecessary fetches and also create cycles where there wouldn't be any without this behavior (e.g. when two repos write each others labels into a file without resolving them). Work towards bazelbuild#19055 Closes bazelbuild#23371. PiperOrigin-RevId: 665744319 Change-Id: Ia27f207793a2da3fb8e37743b328483f9d45192c
Since `Rule` logic drops a call stack entry, errors during repo rule instantiation in a module extension weren't reported with a useful `Location`. Work towards bazelbuild#19055 Closes bazelbuild#23363. PiperOrigin-RevId: 665468188 Change-Id: If67b5b6f290ac4e33b5743e9c1c361a93e1217ef
This was missed in bazelbuild#19055.
This was missed in bazelbuild#19055.
This was missed in bazelbuild#19055.
This was missed in bazelbuild#19055. Closes bazelbuild#23527. PiperOrigin-RevId: 672480631 Change-Id: Ib2ef0edb6b6c90a7336085da20e2794a93763182
@bazel-io fork 7.4.0 |
…23585) Fixes #19055 RELNOTES: Repository rules instantiated in the same module extensions can now refer to each other by their extension-specified names in label attributes. Closes #23369. PiperOrigin-RevId: 666893202 Change-Id: Ib2eaa55fcb563adc86e16dc4a357ac808228ebda --------- Co-authored-by: Fabian Meumertzheim <[email protected]>
This was missed in bazelbuild#19055. Closes bazelbuild#23527. PiperOrigin-RevId: 672480631 Change-Id: Ib2ef0edb6b6c90a7336085da20e2794a93763182
This was missed in bazelbuild#19055. Closes bazelbuild#23527. PiperOrigin-RevId: 672480631 Change-Id: Ib2ef0edb6b6c90a7336085da20e2794a93763182
This was missed in bazelbuild#19055. Closes bazelbuild#23527. PiperOrigin-RevId: 672480631 Change-Id: Ib2ef0edb6b6c90a7336085da20e2794a93763182
…ges (#23564) This was missed in #19055. Closes #23527. PiperOrigin-RevId: 672480631 Change-Id: Ib2ef0edb6b6c90a7336085da20e2794a93763182 Commit 926b574 --------- Co-authored-by: Fabian Meumertzheim <[email protected]> Co-authored-by: Xùdōng Yáng <[email protected]>
A fix for this issue has been included in Bazel 7.4.0 RC1. Please test out the release candidate and report any issues as soon as possible. |
What underlying problem are you trying to solve with this feature?
The repository mapping that applies to a module extension does not include the repositories it generates. This makes it very tricky to pass a reference to some file in such a repo to another repo rule instantiated by the same extension, e.g.:
This is a very common pattern, but requires major hacks to pull of without additional API:
<common prefix>~<apparent name>
and rely on that implementation detail to construct the canonical name oflang_sdk
inlang_toolchain
asctx.attr.name.removesuffix("lang_toolchain") + "lang_sdk"
.lang_sdk
is in the repo mapping of the repositories generated by the extension. By makingsdk_root
anattr.string
instead of anattr.label
and generating a.bzl
file in some other ("hub") repo in the the same extension that callsLabel
on a label string,lang_toolchain
can pass that literal through the correct repo mapping. This requires the module touse_repo
the hub repo and is overall pretty complex.Description of the feature request:
Provide a function on
module_ctx
that converts the name of a repository generated by the extension and a repo-relative label into an instance ofLabel
referencing the intended target.This could look as follows:
Alternative ideas for names:
label_in_repo
Alternative signatures:
Alternative approaches:
Label
instances until after the module extension has fully evaluated, at which point the names of all the repos it generates are known. Then use this information to convert label strings implicitly. This has the advantage that the "obvious" approach just works and the downside that its implementation is probably more involved.Which operating system are you running Bazel on?
N/A
What is the output of
bazel info release
?6.3.0
If
bazel info release
returnsdevelopment 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 master; 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
The text was updated successfully, but these errors were encountered: