Skip to content
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

bzlmod/go_deps: bazel mod tidy adds repos that are loaded as bazel modules #1935

Open
tyler-french opened this issue Sep 25, 2024 · 3 comments

Comments

@tyler-french
Copy link
Contributor

To reproduce:

MODULE.bazel

bazel_dep(name = "flatbuffers", version = "24.3.25", repo_name = "com_github_google_flatbuffers")

go.mod (includes direct dep)

	github.com/google/flatbuffers v2.0.8+incompatible

bazel mod tidy:

ported incorrect imports of repositories via use_repo():

Not imported, but reported as direct dependencies by the extension (may cause the build to fail):
    com_github_google_flatbuffers

Fix the use_repo calls by running 'bazel mod tidy'.
INFO: Updated use_repo calls for @bazel_gazelle//:extensions.bzl%go_deps

Build failure caused:

tfrench@go(tfrench.devpod-us-va) ~/go-code
 % bazel mod --enable_bzlmod tidy
INFO: Invocation ID: ff5667e5-9cef-425c-b978-77434bfebe7d
ERROR: Traceback (most recent call last):
        File "/home/user/go-code/MODULE.bazel", line 209, column 8, in <toplevel>
                include("//third_party:go_deps.MODULE.bazel")
        File "<builtin>", in include
        File "/home/user/go-code/third_party/go_deps.MODULE.bazel", line 17, column 9, in <toplevel>
                use_repo(
Error in use_repo: The repo name 'com_github_google_flatbuffers' is already being used by a bazel_dep at /home/user/go-code/MODULE.bazel:40:10
ERROR: error executing MODULE.bazel file for <root>. Type 'bazel help mod' for syntax and help.
@fmeum
Copy link
Member

fmeum commented Sep 25, 2024

In Bazel 7.4.0 and 8, you will be able to have go_deps reuse the bazel_dep via override_repo. I will add a test case to verify that bazel mod tidy behaves correctly in that case.

@tyler-french
Copy link
Contributor Author

I wonder if for now we can just look at all the repo_name of the bazel_dep in the root MODULE.bazel, and then skip adding these to direct dependencies?

@fmeum
Copy link
Member

fmeum commented Sep 30, 2024

The Gazelle extension can't do this as it doesn't have access to MODULE files.

Having looked into this more, I think that it's actually a feature (but not with a good error message): You have the same dep show up under two different names in your dep tree, which can result in linker errors. Instead, when Bazel 7.4.0 lands, you should use override_repo to replace the extension repo with the Bazel dep.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants