-
Notifications
You must be signed in to change notification settings - Fork 380
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
Allow "go_deps.module_override" tag in non-root Bazel modules #1543
Comments
All Go modules (transitively) declared in a Bazel project participate in Minimum Version Resolution, so there can only ever be one Go module per module path (in this case All of this breaks if two different modules have a dep on the same Go module, but with different patches applied, which is why we made this a hard failure. Could you explain your use case in more detail? What are you using the module for - in particular, will it be exposed to other modules as part of a |
For LLVM in rules_ll we apply all patches in order through importers, but that's usually a situation where users know exactly what patches and what external deps are being used in all places and there is little chance for clashing patches. This isn't the case for go dependencies though where one quickly "imports the world". I wonder whether it would be an option to separate patched go modules in a way that they are only used by the bazel module that declares the patch. Something like "usually everything is reused, but if you patch something you get a duplicate dep". AFAIK this is the approach used by nix. This can make build graphs larger if misconfigured (similar to toolchain transitions), but allows for different variations of deps when needed. This is originally what I wanted for LLVM, but it wasn't a viable approach there since rebuilds are gigantic. Go has very low compile times though, so duplicating deps might be viable here. It's unclear to me how one would work around the uniqueness of go module paths though.
The target is a go binary to create and configure a local Kubernetes development cluster. It's exposed via nix scripts that invoke It could be the case that we "libraryrize" this binary at some point since importers might want to extend/customize it.
I'm not not sure. The patch fixes a cgo dependency that isn't detected by gazelle. It just adds some missing However, this might also be a good thing since the actual repo isn't patched at all. It's just the generated build files. There might be more room for "flexibility" for such cases. Maybe a difference between "patching before gazelle" and "patching after gazelle"? |
Thanks for the context, this information is very helpful. I would propose either of the following, in order of preference:
What do you think? |
Sounds very good! I also agree on your order of preference.
Yes. This would be nice if it completely removes the need for any manual patching. I believe the error is raised by this include (and another similar one). There might be some magic go flag that might help gazelle to detect the missing header. I can set up smaller reproducer if that would help. (Though it's basically just invoking gazelle on this go.mod file).
Tbh I'm not familiar enough with gazelle yet to determine how this works, but sounds reasonable. (Edit: Ah do you mean
I've already played around with generating buildfiles with gazelle and patching them in via a bazel module so that gazelle doesn't actually run on module import. That seemed fairly hacky though and required the So this works, but isn't pretty. It's still an option if
I can see that changing (or "liberating") the current behavior might have far reaching consequences. This stuff is also notoriously hard to work on since one would probably need (several?) "demo" bazel registries to test it properly. |
That looks sufficiently reproducible that I won't need a separate reproducer. I will take a look.
I had something much simpler in mind: Check out circl locally, run Gazelle on it and make the necessary changes to the BUILD files. Generate a patch out of all of this (including the changes Gazelle made) and load the original archive with this patch as an |
I looked into this in more detail and don't think that making Gazelle aware of this setup automatically is going to be feasible in the short term - we would need to either export files or generate Instead, I think that #1526 may help with this. After that functionality has become available, |
#1526 now has an example of what depending on |
Gazelle Commit 23226de.
rules_go version 0.39.1 from bzlmod
Bazel 6.2 from nixpkgs
x86_64 Gentoo/Clang
Does this issue reproduce with the latest releases of all the above?
Non-minimal reproducer:
What did you do?
After #1521 we have something like this in our
MODULE.bazel
:Unfortunately this causes errors for importers of the module:
This looks like the behavior of something like
local_path_override
applies togo_deps.module_override
which seems wrong. The patch not being allowed to propagate to importers means that importers can't build targets the same way that upstream builds them.I think it should be fine (and probably default behavior) to allow patches to propagate to importers or somehow bind them to the bazel module that declares them.
I've had similar issues with LLVM where we need to patch the repo but also have downstream users that need the ability to "repatch" it. We currently append the importer patches to the existing ones, which has worked fine so far (https://github.com/eomii/bazel-eomii-registry/blob/11e289ec5b9c2ed9c4ebb0455133ff8455831233/modules/llvm-project-overlay/17-init-bcr.3/patches/00_add_bzlmod_support.patch#L141).
That said, it also seems like a viable solution to just remove the
_fail_on_non_root_overrides
here:https://github.com/bazelbuild/bazel-gazelle/blob/31064705f5a481149d060a94adb48cd2c03347b7/internal/bzlmod/go_deps.bzl#L230-L237
cc @seh @fmeum @tyler-french
The text was updated successfully, but these errors were encountered: