-
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
update-repos: set build_naming_convention for modules that already have build files #890
Comments
How is the external repository declared? Could you provide a small example? If it's a If the repository is not declared, or if it's declared with a rule other than |
It still use |
Thanks. Looks like the issue is that this repository already has its own build files. I guess You could set those attributes manually for now. |
Just hit the same problem when trying to add https://github.com/go-resty/resty as a dependency. |
thanks!
works without |
It would actually be really great if |
It's currently near impossible to use gazelle for something complex (e.g. attempt to build cortexmetrics). Is it an option to revert the naming changes or offer a global kill switch for gazelle (don't do the renaming on update or when invoked through go_repository) until there is a better migration path? I do run into #892 (I attempt to build cortex, that depends on prometheus, prometheus pulls in grpc_gateway for some of the pre-generated potobuf code). The generated build files for prometheus refer to @grpc_gateway//runtime:runtime. I have put the above workaround into the deps.bzl file. In the local //:BUILD.bazel I tried to use both naming conventions options to use the old way. To no extend. The most annoying thing is that this is painful to debug. If I could hit a breakpoint to when go_repository runs gazelle and look at the state it would certainly be less painful. EDIT: I got it to build. In addition to editing the com_github_grpc_ecosystem_grpc_gateway I had to use naming_convention inside the go_repository rule for prometheus. And as prometheus is used by thanos also modify the thanos go_repository rule. Is this transitivity intended? |
No, this won't be reverted.
That doesn't seem right? By default,
That's what this issue is about. The main problem is that it requires |
@zecke if it helps, this is what we ultimately checked in for grpc-gateway: go_repository(
name = "com_github_grpc_ecosystem_grpc_gateway",
build_directives = ["gazelle:exclude **/**_test.go", "gazelle:exclude examples"],
build_file_generation = "on",
build_file_name = "BUILD.bazel",
build_file_proto_mode = "disable_global",
importpath = "github.com/grpc-ecosystem/grpc-gateway",
sum = "h1:YuM9SXYy583fxvSOkzCDyBPCtY+/IMSHEG1dKFMLZsA=",
version = "v1.14.1",
) It's a little heavy-handed, but basically forcing build file generation on to overwrite their build files and then aggressively excluding their tests and examples did it for me. |
I added @dragonsinth 's `go_repository. I am now getting an error with prometheus not being able to find prompb_proto.
Adding |
@dragonsinth
|
@base698
When looking at your prompb repo, I got past that error by adding gazelle resolve directives to the grpc_gateway go_repository.
After that, I added |
* Update Bazel build to work with 4.0.0 This includes several updates to the BUILD and WORKSPACE files, so that they now work with Bazel 4.0.0, Gazelle 0.23 and rules_go 0.27. By default, [Gazelle now uses](bazel-contrib/bazel-gazelle#863) the last component of the Bazel package, rather than `go_default_library` as the `go_library name`. This causes problems when the naming conventions do not match. bazel-contrib/bazel-gazelle#890 (comment) Adding support for the new naming convention should not break anything that depends on using the old naming convention, because the Gazelle option `import_alias` makes aliases to the libraries and this allows the old naming convention to still work.
I had something very similar to what @tanyabouman shared previously and it worked, but now that I am upgrading to v1.16.0, its breaking with this:
I updated to the exact |
* Update Bazel build to work with 4.0.0 This includes several updates to the BUILD and WORKSPACE files, so that they now work with Bazel 4.0.0, Gazelle 0.23 and rules_go 0.27. By default, [Gazelle now uses](bazel-contrib/bazel-gazelle#863) the last component of the Bazel package, rather than `go_default_library` as the `go_library name`. This causes problems when the naming conventions do not match. bazel-contrib/bazel-gazelle#890 (comment) Adding support for the new naming convention should not break anything that depends on using the old naming convention, because the Gazelle option `import_alias` makes aliases to the libraries and this allows the old naming convention to still work.
I was having the same issue when I introduced this new dependency in my project:
I solved by simply adding this to my go_repository(
name = "com_github_grpc_ecosystem_grpc_gateway_v2",
importpath = "github.com/grpc-ecosystem/grpc-gateway/v2",
sum = "h1:1JYBfzqrWPcCclBwxFCPAou9n+q86mfnu7NAeHfte7A=",
+ build_file_name = "BUILD.bazel", # keep: https://github.com/bazelbuild/bazel-gazelle/issues/890
version = "v2.15.0",
) But this shouldn't be necessary, if, according to the go_repository reference, the default value for
Any thoughts? |
I did almost identical thing except the dependency is v1 (so com_github_grpc_ecosystem_grpc_gateway) and have the same error message. But adding that line doesn't help. |
I'm using the upcoming bzlmod support in rules_buf and I've encountered this error. ERROR: /private/var/tmp/_bazel_debkanchan/969f704a68afbe6aa6f76e61ecfa9c99/external/gazelle~0.34.0~go_deps~com_github_bufbuild_protovalidate_go/celext/BUILD.bazel:3:11: no such target '@gazelle~0.34.0~go_deps~com_github_google_cel_go//cel:cel': target 'cel' not declared in package 'cel' defined by /private/var/tmp/_bazel_debkanchan/969f704a68afbe6aa6f76e61ecfa9c99/external/gazelle~0.34.0~go_deps~com_github_google_cel_go/cel/BUILD.bazel (Tip: use `query "@@gazelle~0.34.0~go_deps~com_github_google_cel_go//cel:*"` to see all the targets in that package) and referenced by '@gazelle~0.34.0~go_deps~com_github_bufbuild_protovalidate_go//celext:celext'
ERROR: /private/var/tmp/_bazel_debkanchan/969f704a68afbe6aa6f76e61ecfa9c99/external/gazelle~0.34.0~go_deps~com_github_bufbuild_protovalidate_go/celext/BUILD.bazel:3:11: no such target '@gazelle~0.34.0~go_deps~com_github_google_cel_go//common/overloads:overloads': target 'overloads' not declared in package 'common/overloads' defined by /private/var/tmp/_bazel_debkanchan/969f704a68afbe6aa6f76e61ecfa9c99/external/gazelle~0.34.0~go_deps~com_github_google_cel_go/common/overloads/BUILD.bazel (did you mean 'overloads.go'? Tip: use `query "@@gazelle~0.34.0~go_deps~com_github_google_cel_go//common/overloads:*"` to see all the targets in that package) and referenced by '@gazelle~0.34.0~go_deps~com_github_bufbuild_protovalidate_go//celext:celext'
ERROR: /private/var/tmp/_bazel_debkanchan/969f704a68afbe6aa6f76e61ecfa9c99/external/gazelle~0.34.0~go_deps~com_github_bufbuild_protovalidate_go/celext/BUILD.bazel:3:11: no such target '@gazelle~0.34.0~go_deps~com_github_google_cel_go//common/types:types': target 'types' not declared in package 'common/types' defined by /private/var/tmp/_bazel_debkanchan/969f704a68afbe6aa6f76e61ecfa9c99/external/gazelle~0.34.0~go_deps~com_github_google_cel_go/common/types/BUILD.bazel (Tip: use `query "@@gazelle~0.34.0~go_deps~com_github_google_cel_go//common/types:*"` to see all the targets in that package) and referenced by '@gazelle~0.34.0~go_deps~com_github_bufbuild_protovalidate_go//celext:celext'
ERROR: /private/var/tmp/_bazel_debkanchan/969f704a68afbe6aa6f76e61ecfa9c99/external/gazelle~0.34.0~go_deps~com_github_bufbuild_protovalidate_go/celext/BUILD.bazel:3:11: no such target '@gazelle~0.34.0~go_deps~com_github_google_cel_go//common/types/ref:ref': target 'ref' not declared in package 'common/types/ref' defined by /private/var/tmp/_bazel_debkanchan/969f704a68afbe6aa6f76e61ecfa9c99/external/gazelle~0.34.0~go_deps~com_github_google_cel_go/common/types/ref/BUILD.bazel (Tip: use `query "@@gazelle~0.34.0~go_deps~com_github_google_cel_go//common/types/ref:*"` to see all the targets in that package) and referenced by '@gazelle~0.34.0~go_deps~com_github_bufbuild_protovalidate_go//celext:celext'
ERROR: /private/var/tmp/_bazel_debkanchan/969f704a68afbe6aa6f76e61ecfa9c99/external/gazelle~0.34.0~go_deps~com_github_bufbuild_protovalidate_go/celext/BUILD.bazel:3:11: no such target '@gazelle~0.34.0~go_deps~com_github_google_cel_go//common/types/traits:traits': target 'traits' not declared in package 'common/types/traits' defined by /private/var/tmp/_bazel_debkanchan/969f704a68afbe6aa6f76e61ecfa9c99/external/gazelle~0.34.0~go_deps~com_github_google_cel_go/common/types/traits/BUILD.bazel (Tip: use `query "@@gazelle~0.34.0~go_deps~com_github_google_cel_go//common/types/traits:*"` to see all the targets in that package) and referenced by '@gazelle~0.34.0~go_deps~com_github_bufbuild_protovalidate_go//celext:celext'
ERROR: /private/var/tmp/_bazel_debkanchan/969f704a68afbe6aa6f76e61ecfa9c99/external/gazelle~0.34.0~go_deps~com_github_bufbuild_protovalidate_go/celext/BUILD.bazel:3:11: no such target '@gazelle~0.34.0~go_deps~com_github_google_cel_go//ext:ext': target 'ext' not declared in package 'ext' defined by /private/var/tmp/_bazel_debkanchan/969f704a68afbe6aa6f76e61ecfa9c99/external/gazelle~0.34.0~go_deps~com_github_google_cel_go/ext/BUILD.bazel (Tip: use `query "@@gazelle~0.34.0~go_deps~com_github_google_cel_go//ext:*"` to see all the targets in that package) and referenced by '@gazelle~0.34.0~go_deps~com_github_bufbuild_protovalidate_go//celext:celext' MODULE bazel_dep(name = "rules_go", version = "0.42.0")
bazel_dep(name = "gazelle", version = "0.34.0")
bazel_dep(name = "rules_pkg", version = "0.9.1")
bazel_dep(name = "rules_buf", version = "0.2.0")
bazel_dep(name = "rules_proto", version = "5.3.0-21.7")
bazel_dep(name = "rules_oci", version = "1.4.0")
bazel_dep(name = "container_structure_test", version = "1.16.0")
git_override(
module_name = "rules_buf",
commit = "27e9a19c6227cc3923abb1a4e703d9d42d9a1fa9",
remote = "https://github.com/bufbuild/rules_buf.git",
)
buf = use_extension("@rules_buf//buf:extensions.bzl", "buf")
# Override the default version of buf
buf.toolchains(version = "v1.28.1")
go_deps = use_extension("@gazelle//:extensions.bzl", "go_deps")
go_deps.from_file(go_mod = "//:go.mod")
use_repo(go_deps, "build_buf_gen_go_bufbuild_protovalidate_protocolbuffers_go", "build_buf_gen_go_ride_wallet_connectrpc_go", "build_buf_gen_go_ride_wallet_protocolbuffers_go", "com_connectrpc_connect", "com_github_bufbuild_protovalidate_go", "com_github_golang_jwt_jwt_v5", "com_github_google_wire", "com_github_ilyakaznacheev_cleanenv", "com_github_micahparks_keyfunc_v2", "com_github_mmcloughlin_geohash", "com_github_onsi_ginkgo_v2", "com_github_onsi_gomega", "com_google_cloud_go_firestore", "com_google_firebase_go_v4", "org_golang_google_genproto", "org_golang_google_genproto_googleapis_api", "org_golang_google_grpc", "org_golang_google_protobuf", "org_golang_x_net", "org_uber_go_mock", "org_uber_go_zap")
oci = use_extension("@rules_oci//oci:extensions.bzl", "oci")
oci.pull(
name = "distroless",
digest = "sha256:e7e79fb2947f38ce0fab6061733f7e1959c12b843079042fe13f56ca7b9d178c",
image = "gcr.io/distroless/static",
platforms = [
"linux/amd64",
"linux/arm64/v8",
],
)
use_repo(oci, "distroless") BUILD load("@gazelle//:def.bzl", "DEFAULT_LANGUAGES", "gazelle", "gazelle_binary")
gazelle_binary(
name = "gazelle-buf",
languages = DEFAULT_LANGUAGES + [
# Loads the Buf extension
"@rules_buf//gazelle/buf:buf",
# NOTE: This needs to be loaded after the proto language
],
)
# gazelle:prefix github.com/ride-app/driver-service
# gazelle:build_file_name BUILD.bazel
# gazelle:exclude infra
# gazelle:proto disable_global
gazelle(
name = "gazelle",
gazelle = ":gazelle-buf",
) Since bzlmod support means there's no |
What version of gazelle are you using?
upgrading from to v0.22.0
What version of rules_go are you using?
rules_go 0.24.0
What version of Bazel are you using?
0.3.2
Does this issue reproduce with the latest releases of all the above?
What operating system and processor architecture are you using?
linux
What did you do?
upgrade gazelle to 0.22.0 and run gazelle
What did you expect to see?
no build break
What did you see instead?
gazelle modified dependencies to external repositories (managed by bazel) to use import go naming convention, but the external repo still uses go_default_library naming convention.
I can fix this by adding
gazelle:go_naming_convention_external go_default_library
, but what is the best practice to migrate naming convention (especially if there are multiple external repos)?0.22.0 changed go_naming_convention to
import
(https://github.com/bazelbuild/bazel-gazelle/releases/tag/v0.22.0)but README still says
go_default_library
is the default? (https://github.com/bazelbuild/bazel-gazelle#directives)The text was updated successfully, but these errors were encountered: