-
Notifications
You must be signed in to change notification settings - Fork 386
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
Missing documentation and best practices for bzlmod #1715
Comments
The docs exist, they just aren't sufficiently discoverable: https://github.com/bazelbuild/rules_go/blob/master/docs/go/core/bzlmod.md @tyler-french What do you think, is it time to make the Bzlmod instructions the default? |
I would say that a monorepo should really have one |
Thank you for the quick answer guys! 🙏 Version Bazel: MODULE.bazel module(
name="bazel_project",
version="1.0.0"
)
bazel_dep(name = "rules_go", version = "0.44.2")
bazel_dep(name = "gazelle", version = "0.35.0") Errors: > bazel run //:gazelle
WARNING: Target pattern parsing failed.
ERROR: Skipping '//:gazelle': error loading package '': Unable to find package for @@[unknown repo 'bazel_gazelle' requested from @@]//:def.bzl: The repository '@@[unknown repo 'bazel_gazelle' requested from @@]' could not be resolved: No repository visible as '@bazel_gazelle' from main repository.
ERROR: error loading package '': Unable to find package for @@[unknown repo 'bazel_gazelle' requested from @@]//:def.bzl: The repository '@@[unknown repo 'bazel_gazelle' requested from @@]' could not be resolved: No repository visible as '@bazel_gazelle' from main repository.
INFO: Elapsed time: 0.087s
INFO: 0 processes.
ERROR: Build did NOT complete successfully
ERROR: Build failed. Not running target If I change the module(
name="bazel_project",
version="1.0.0"
)
bazel_dep(name = "rules_go", version = "0.44.2", repo_name = "io_bazel_rules_go")
bazel_dep(name = "gazelle", version = "0.35.0", repo_name = "bazel_gazelle") I get a different error: >bazel run //:gazelle
INFO: Repository gazelle~0.35.0~non_module_deps~bazel_gazelle_go_repository_cache instantiated at:
<builtin>: in <toplevel>
Repository rule go_repository_cache defined at:
/private/var/tmp/_bazel_xxx/231abc74738b39afb97d17a62e2fa9f9/external/gazelle~0.35.0/internal/go_repository_cache.bzl:71:38: in <toplevel>
ERROR: An error occurred during the fetch of repository 'gazelle~0.35.0~non_module_deps~bazel_gazelle_go_repository_cache':
Traceback (most recent call last):
File "/private/var/tmp/_bazel_xxx/231abc74738b39afb97d17a62e2fa9f9/external/gazelle~0.35.0/internal/go_repository_cache.bzl", line 38, column 27, in _go_repository_cache_impl
go_root = str(ctx.path(go_sdk_label).dirname)
Error in path: Unable to load package for @@rules_go~0.44.0~go_sdk~go_default_sdk//:ROOT: The repository '@@rules_go~0.44.0~go_sdk~go_default_sdk' could not be resolved: Repository '@@rules_go~0.44.0~go_sdk~go_default_sdk' is not defined
ERROR: <builtin>: fetching go_repository_cache rule //:gazelle~0.35.0~non_module_deps~bazel_gazelle_go_repository_cache: Traceback (most recent call last):
File "/private/var/tmp/_bazel_xxx/231abc74738b39afb97d17a62e2fa9f9/external/gazelle~0.35.0/internal/go_repository_cache.bzl", line 38, column 27, in _go_repository_cache_impl
go_root = str(ctx.path(go_sdk_label).dirname)
Error in path: Unable to load package for @@rules_go~0.44.0~go_sdk~go_default_sdk//:ROOT: The repository '@@rules_go~0.44.0~go_sdk~go_default_sdk' could not be resolved: Repository '@@rules_go~0.44.0~go_sdk~go_default_sdk' is not defined
ERROR: no such package '@@gazelle~0.35.0~go_deps~com_github_pmezard_go_difflib//difflib': no such package '@@gazelle~0.35.0~non_module_deps~bazel_gazelle_go_repository_cache//': Unable to load package for @@rules_go~0.44.0~go_sdk~go_default_sdk//:ROOT: The repository '@@rules_go~0.44.0~go_sdk~go_default_sdk' could not be resolved: Repository '@@rules_go~0.44.0~go_sdk~go_default_sdk' is not defined
ERROR: /private/var/tmp/_bazel_xxx/231abc74738b39afb97d17a62e2fa9f9/external/gazelle~0.35.0/cmd/gazelle/BUILD.bazel:10:11: no such package '@@gazelle~0.35.0~go_deps~com_github_pmezard_go_difflib//difflib': no such package '@@gazelle~0.35.0~non_module_deps~bazel_gazelle_go_repository_cache//': Unable to load package for @@rules_go~0.44.0~go_sdk~go_default_sdk//:ROOT: The repository '@@rules_go~0.44.0~go_sdk~go_default_sdk' could not be resolved: Repository '@@rules_go~0.44.0~go_sdk~go_default_sdk' is not defined and referenced by '@@gazelle~0.35.0//cmd/gazelle:gazelle_lib'
ERROR: Analysis of target '//:gazelle' failed; build aborted: Analysis failed
INFO: Elapsed time: 0.170s, Critical Path: 0.00s
INFO: 1 process: 1 internal.
ERROR: Build did NOT complete successfully
ERROR: Build failed. Not running target
FAILED:
Fetching repository @@gazelle~0.35.0~go_deps~com_github_pmezard_go_difflib; Restarting. I have just created this public repository so you can probably find more easily the issue: |
Related to my previous comment @fmeum, it seems the error comes from the bazel_dep(name = "rules_go", version = "0.44.0", repo_name = "io_bazel_rules_go")
bazel_dep(name = "gazelle", version = "0.35.0", repo_name = "bazel_gazelle") So, I am wondering about this part:
Am I in this condition? It is not clear to me :/ My WORKSPACE is completely empty. For all these issues, I added the comments in the repo here: |
You are affected by this bug: bazelbuild/bazel#20721 Could you try again with Bazel 7.0.1rc1? |
Same error @fmeum:
Both for:
Same like before. It still works only with:
|
That error means that you need to update the |
Thank you @fmeum for the fix.
Is it caused by:
? Or something related to this? I have updated the repository in case you want to take a look. 🙏 |
That failure is expected, you aren't declaring any external dependencies. That is what the |
This let's us call `bazel build ...` from the packages directory or the root directory. Since we have a monorepo, a single MODULE.bazel file should be enough anyway. See, bazel-contrib/bazel-gazelle#1715 (comment) CMK-17767 Change-Id: I86603b70f8f9203242b0e40afb206b74e4f6abeb
I tried to follow the tutorial for the migration from the legacy WORKSPACE (version 6.3.2) to
bzlmod
(enabled by default using version 7.0.0, the version that I am migrating to).Considering my current environment, a monorepo composed of multiple Go projects using go-modules and docker rules to create build/push the images, I am finding it quite tricky to follow.
First of all, I have the feeling there are no "best practices" for Go projects with Bazel.
Example
Should I prefer a design where I have a MODULE.bazel for each project in the monorepo?
Or should I have one single MODULE.bazel for the entire monorepo at the WORKSPACE level (as suggested in the tutorial)?
Secondly, I am not able to find documentation to adapt gazelle with bzlmod.
Thank you in advance for your help.
The text was updated successfully, but these errors were encountered: