-
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
Support (restrictive) load in MODULE.bazel #17880
Comments
I don't think I'm exaggerating that much with the following claim: The availability of and reliance on Module extensions can accept label attributes on their tags and collect dependency information from the files pointed to by these labels. Without any changes to Bazel itself, rules_jvm_external could allow for the following usage where
This would keep your MODULE.bazel file clean and your external Java dependencies separated from all the others while still allowing for fast discovery of the entire dependency tree. |
What @fmeum said; although, we might explore allowing |
Would there be an option of using |
See this comment in #14632 for a previous abandonded attempt. We don't currently have the cycles to work on this. But if anyone is interested in picking up the work and writing a design for it (addressing the concerns in the comment above), we'd be happy to review PRs. |
We could:
The last restriction makes it less likely for two different loaded files to define conflicting load("//:go.bzl", "declare_go_overrides", "GO_REPOS")
go_deps = use_extension(...)
go_deps.from_file(go_mod = "//:go.mod")
declare_go_overrides(go_deps)
use_repo(go_deps, *GO_REPOS) |
The pain point of maintaining a large MODULE.bazel file is completely valid. But the solution of allowing Looking into the current Go ecosystem, I don't see anyone asking for the ability to "load / import" within So is it possible for us to solve this problem with better automation tooling than relying on dynamic template loading? For example: perhaps a |
The reason why go is allowed to do so is because the source of truth of dependencies relies in the source tree, therefore it's okay to let tool generate it. But for module.bazel, it's already the source of truth, and there are lots of human written parts in it, eg. repo override configurations, etc. Automation is not entirely feasible . |
@ashi009 In my mind, a command such as
I think at minimum, we should defer the addition of The reverse, however, is not feasible. Once |
@sluongng Totally agree on the first two. However, not true for the third. As at most of the time we are overriding the extension generated repos. In a relatively large mono repo, the number of repos that need a second touch is a lot. Our current non-bzlmod rules_go generated bzl file with lots of patches and custom gazelle directives is over 17k loc. I don't see how this gonna play out in a single module.bazel file with the help of any tool. Even that is feasible, reviewing that file is also challenging -- how do we delegate a portion of a file to some reviewer while other portion to some others? Also a note on mirroring the bcr, it's not a valid solution for most of the users, it adds too much toil for who ever maintaining that mirror -- just thinking about pulling upstream releases and resolving merge conflicts. |
I'm not sure this is feasible. Unlike Go where the import path fully identifies the module, in Bazel/Bzlmod you just see people using This is even less tractable if you consider module extensions and repos generated from them. |
@ashi009 Just a quick clarification. With the custom registry solution, you don't need to mirror the entire BCR. The custom registry only needs to contain the customized modules. |
@ashi009 I could be wrong, so please do correct me if I am. Here, I am not suggesting mirror-ing. I am suggesting using multiple registries on top of each others:
So you would only need to maintain your internal module customizations.
@Wyverald I think a best-effort lookup from the existing registries should be sufficient. For module extension, we could use the approach existing in |
I think @sluongng idea for an in-repo registry could be the answer. It satisfies two important criteria in my mind:
@Wyverald I have not dug into the Bazel code for the registry yet. At first blush, it seems that if the on-disk custom registry had the correct layout, it would just be a matter of saying to Bazel "look over here" instead of "download from there". Am I thinking about this correctly? |
Indeed. The only caveat is that you'd need to use a |
@Wyverald The doc is giving me the impression that
It does not imply the reverse which I think you are implying though:
Am I understanding this wrongly? Because I was expecting that |
You're right -- I didn't try to imply that you couldn't use the |
ModuleFileGlobals used to serve as both the definition of Starlark methods available in MODULE.bazel files, *and* the state tracker for a module being built. This commit brings it more in line with other Starlark evaluation contexts where there's a simple object that just holds methods, and the actual state is stored in the StarlarkThread. ModuleThreadContext is that state object. This commit is a pure mechanical refactor with no behavioral changes. It paves the way for us to allow root module MODULE.bazel files to import other files. Work towards #17880.
ModuleFileGlobals used to serve as both the definition of Starlark methods available in MODULE.bazel files, *and* the state tracker for a module being built. This commit brings it more in line with other Starlark evaluation contexts where there's a simple object that just holds methods, and the actual state is stored in the StarlarkThread. ModuleThreadContext is that state object. This commit is a pure mechanical refactor with no behavioral changes. It paves the way for us to allow root module MODULE.bazel files to import other files. Work towards #17880.
ModuleFileGlobals used to serve as both the definition of Starlark methods available in MODULE.bazel files, *and* the state tracker for a module being built. This commit brings it more in line with other Starlark evaluation contexts where there's a simple object that just holds methods, and the actual state is stored in the StarlarkThread. ModuleThreadContext is that state object. This commit is a pure mechanical refactor with no behavioral changes. It paves the way for us to allow root module MODULE.bazel files to import other files. Work towards #17880.
ModuleFileGlobals used to serve as both the definition of Starlark methods available in MODULE.bazel files, *and* the state tracker for a module being built. This commit brings it more in line with other Starlark evaluation contexts where there's a simple object that just holds methods, and the actual state is stored in the StarlarkThread. ModuleThreadContext is that state object. This commit is a pure mechanical refactor with no behavioral changes. It paves the way for us to allow root module MODULE.bazel files to import other files. Work towards #17880. Closes #21749. PiperOrigin-RevId: 619261497 Change-Id: Ibff3a311e1788f7d8089ca194933cfb5fcc53ee0
This new directive allows the root module to divide its MODULE.bazel into multiple segments. TODO: add more context RELNOTES: Added a new `module_import()` directive to MODULE.bazel files. TODO: elaborate a bit more Fixes #17880.
This new directive allows the root module to divide its MODULE.bazel into multiple segments. TODO: add more context RELNOTES: Added a new `include()` directive to MODULE.bazel files. TODO: elaborate a bit more Fixes #17880.
This new directive allows the root module to divide its MODULE.bazel into multiple segments. TODO: add more context RELNOTES: Added a new `include()` directive to MODULE.bazel files. TODO: elaborate a bit more Fixes #17880.
This new directive allows the root module to divide its MODULE.bazel into multiple segments. TODO: add more context RELNOTES: Added a new `include()` directive to MODULE.bazel files. TODO: elaborate a bit more Fixes #17880.
This new directive allows the root module to divide its MODULE.bazel into multiple segments. This directive can only be used by root modules; only files in the main repo may be included; variable bindings are only visible in the file they occur in, not in any included or including files. See the docs for `include()` (in `ModuleFileGlobals.java`) for more details. RELNOTES: Added a new `include()` directive to MODULE.bazel files. Fixes #17880.
This new directive allows the root module to divide its MODULE.bazel into multiple segments. This directive can only be used by root modules; only files in the main repo may be included; variable bindings are only visible in the file they occur in, not in any included or including files. See the docs for `include()` (in `ModuleFileGlobals.java`) for more details. RELNOTES: Added a new `include()` directive to MODULE.bazel files. Fixes #17880.
They must end in `.MODULE.bazel`. Follow-up for #17880
ModuleFileGlobals used to serve as both the definition of Starlark methods available in MODULE.bazel files, *and* the state tracker for a module being built. This commit brings it more in line with other Starlark evaluation contexts where there's a simple object that just holds methods, and the actual state is stored in the StarlarkThread. ModuleThreadContext is that state object. This commit is a pure mechanical refactor with no behavioral changes. It paves the way for us to allow root module MODULE.bazel files to import other files. Work towards bazelbuild#17880. Closes bazelbuild#21749. PiperOrigin-RevId: 619261497 Change-Id: Ibff3a311e1788f7d8089ca194933cfb5fcc53ee0
ModuleFileGlobals used to serve as both the definition of Starlark methods available in MODULE.bazel files, *and* the state tracker for a module being built. This commit brings it more in line with other Starlark evaluation contexts where there's a simple object that just holds methods, and the actual state is stored in the StarlarkThread. ModuleThreadContext is that state object. This commit is a pure mechanical refactor with no behavioral changes. It paves the way for us to allow root module MODULE.bazel files to import other files. Work towards #17880. Closes #21749. PiperOrigin-RevId: 619261497 Change-Id: Ibff3a311e1788f7d8089ca194933cfb5fcc53ee0 Commit 9facaaa Co-authored-by: Xdng Yng <wyverald@gmail.com>
This new directive allows the root module to divide its `MODULE.bazel` into multiple segments. This directive can only be used by root modules; only files in the main repo may be included; variable bindings are only visible in the file they occur in, not in any included or including files. See the docs for `include()` (in `ModuleFileGlobals.java`) for more details. In follow-ups, we'll need to address: 1. Enforcing the loaded files to have some sort of naming format (tentatively `foo.MODULE.bazel` where `foo` is anything) 2. Making `bazel mod tidy` work with included files RELNOTES: Added a new `include()` directive to `MODULE.bazel` files. Fixes #17880. Closes #21855. PiperOrigin-RevId: 627034184 Change-Id: Ifc2f616cf0791445daeeac9ca5ec4478e83382aa
This new directive allows the root module to divide its `MODULE.bazel` into multiple segments. This directive can only be used by root modules; only files in the main repo may be included; variable bindings are only visible in the file they occur in, not in any included or including files. See the docs for `include()` (in `ModuleFileGlobals.java`) for more details. In follow-ups, we'll need to address: 1. Enforcing the loaded files to have some sort of naming format (tentatively `foo.MODULE.bazel` where `foo` is anything) 2. Making `bazel mod tidy` work with included files RELNOTES: Added a new `include()` directive to `MODULE.bazel` files. Fixes bazelbuild#17880. Closes bazelbuild#21855. PiperOrigin-RevId: 627034184 Change-Id: Ifc2f616cf0791445daeeac9ca5ec4478e83382aa
They must end in `.MODULE.bazel`. Follow-up for bazelbuild#17880 Closes bazelbuild#22075. PiperOrigin-RevId: 627136756 Change-Id: If9b1797f2e7ddc1aebd929646329e832288bfd8a
A fix for this issue has been included in Bazel 7.2.0 RC1. Please test out the release candidate and report any issues as soon as possible. |
Description of the feature request:
Currently, the
MODULE.bazel
file must contain everything needed by the project within it, and cannot callload
statements to help make it easier to navigate.One situation in which it would be helpful to use
load
is when configuring external package managers, e.g. like withrules_jvm_external
. On a Java project it is not unusual to depend on several external jars. Putting that configuration inMODULE.bazel
can be considered as polluting the file and makes it more difficult to maintain.This was originally opened in bazel-contrib/rules_jvm_external#854 and that issue provides further details on a specific example with
rules_jvm_external
.Having the ability to use
load
to load constants or macros from other files would help us maintain a more organizedMODULE.bazel
.What underlying problem are you trying to solve with this feature?
No response
Which operating system are you running Bazel on?
Linux
What is the output of
bazel info release
?6.0.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: