Closed hbjydev closed 2 years ago
The target gazelle-buf-bin
doesn't include the go
language extension. The # gazelle:prefix
directive is part of the go
extension. Adding the go
language extension should solve this:
load("@bazel_gazelle//:def.bzl", "gazelle", "gazelle_binary")
# gazelle:prefix pkg.name
# gazelle:proto disable_global
# gazelle:resolve go pkg.name/users/pkg/apis/users/v1 //users/pkg/apis/users/v1:users
gazelle(name = "gazelle")
gazelle(
name = "gazelle-update-repos",
args = [
"-from_file=go.mod",
"-to_macro=deps.bzl%go_dependencies",
"-prune",
"-build_file_proto_mode=disable_global",
],
command = "update-repos",
)
gazelle_binary(
name = "gazelle-buf-bin",
languages = [
"@bazel_gazelle//language/proto:go_default_library",
+ "@bazel_gazelle//language/go:go_default_library",
"@rules_buf//gazelle/buf:buf",
],
)
gazelle(
name = "gazelle-buf",
gazelle = ":gazelle-buf-bin",
)
gazelle(
name = "gazelle-buf-update-repos",
args = [
"--from_file=buf.work.yaml",
"-to_macro=deps.bzl%buf_dependencies",
"-prune",
],
command = "update-repos",
gazelle = ":gazelle-buf-bin",
)
The config can be further simplified:
load("@bazel_gazelle//:def.bzl", "gazelle", "gazelle_binary")
# gazelle:prefix pkg.name
# gazelle:proto disable_global
# gazelle:resolve go pkg.name/users/pkg/apis/users/v1 //users/pkg/apis/users/v1:users
gazelle(name = "gazelle", gazelle = ":gazelle-bin")
gazelle(
name = "gazelle-update-repos",
args = [
"-from_file=go.mod",
"-to_macro=deps.bzl%go_dependencies",
"-prune",
"-build_file_proto_mode=disable_global",
],
command = "update-repos",
)
gazelle(
name = "gazelle-buf-update-repos",
args = [
"--from_file=buf.work.yaml",
"-to_macro=deps.bzl%buf_dependencies",
"-prune",
],
command = "update-repos",
gazelle = ":gazelle-bin",
)
gazelle_binary(
name = "gazelle-bin",
languages = [
"@bazel_gazelle//language/proto:go_default_library",
"@bazel_gazelle//language/go:go_default_library",
"@rules_buf//gazelle/buf:buf",
],
)
Closing this issue for now. Feel free to reopen if this didn't work as expected.
This is my BUILD file in the root of my repo. It has stuff in it for generating Go gazelle things too, but whenever I run
bazel run //:gazelle-buf
, it fails and saysgazelle: /dir/BUILD: unknown directive: gazelle:prefix
.