forked from cockroachdb/cockroach
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build: generate .pb.go files in the bazel sandbox
We used to use the checked-in `.pb.go` files in our Bazel build, but these files should really be generated during the build (this is normal Bazel style, and avoids the weird extra step of having to run `make generate` and check in the `.pb.go` files whenever a `.proto` is updated). Some specific implementation notes: * Add a couple `go_proto_compiler`s for the `protoc-gen-gogoroach` plugin. * We enable Gazelle handling of `.proto` files in `BUILD.bazel`, and add `.pb.gw.go` generation for those files that need it as well. * In that file, we also add a bunch of `gazelle:resolve` and `gazelle:exclude` directives that fix some build issues. Generally, this is necessary for vendored protos, which Gazelle doesn't index correctly. * Add a couple ad-hoc manual fixes to make compilation work (they can generally be found by searching for lines in `BUILD.bazel` files that are marked `keep`). Usually, this is necessary because of annotations, which Gazelle can't properly track the dependencies for. * Do some extra dependency munging, which becomes necessary due to our usage of `rules_go`. First, move `go_repository()` declarations from `DEPS.bzl` to `WORKSPACE` so we can override the dependencies pulled in by `go_rules_dependencies()`. Finally, we have to patch some of the vendored code as well; the patches can be found in `build/patches`. We do this because Gazelle's default behavior would be to generate `proto_library()` and `go_proto_library()` declarations for every vendored `.proto` file, which is sometimes not what we want because it can introduce various compiler or linker issues. Where relevant, we use vendored pre-generated `.pb.go` files so we don't have to re-build those files ourselves. Elsewhere we need to replace the Gazelle-inferred dependencies on rules in `@io_bazel_rules_go//proto/wkt` with other Go libraries which can be safely linked. See [this thread](grpc-ecosystem/grpc-gateway#1847 (comment)) for additional context. Fixes cockroachdb#56067. Release note: None
- Loading branch information
1 parent
418c672
commit aac9021
Showing
92 changed files
with
1,771 additions
and
483 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# This directory contains patches for third-party vendored code. | ||
# This file is intentionally empty. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
This directory contains patches that are applied to third-party code | ||
(dependencies) before the Bazel build runs. The files here are named such that | ||
the patch `foo.patch` will be applied to the repo `@foo`. | ||
|
||
If you would like to add a new patch, also ensure that you update the root-level | ||
`DEPS.bzl` or `WORKSPACE` files accordingly. | ||
|
||
Generally speaking, the patches here "fix" `BUILD` files, which were either | ||
originally present in the repo, or which will be generated by Gazelle. A couple | ||
examples: | ||
|
||
* `com_github_gogo_protobuf.patch` adds a rule, `gogo_proto`, so that we can | ||
import `gogoproto/gogo.proto` in our own `.proto` files, while not updating | ||
the existing `gogoproto` rule that uses the pre-generated `.pb.go` file. | ||
* `com_github_grpc_ecosystem_grpc_gateway.patch` replaces some dependencies that | ||
Gazelle infers (those under `@io_bazel_rules_go//proto/wkt`) with the build | ||
targets using pre-generated `.pb.go` files under | ||
`@com_github_golang_protbuf//ptypes`. We do this because the `wkt` rules | ||
create conflicts in our build. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
diff -urN a/errorspb/BUILD.bazel b/errorspb/BUILD.bazel | ||
--- a/errorspb/BUILD.bazel 1969-12-31 19:00:00.000000000 -0500 | ||
+++ b/errorspb/BUILD.bazel 2000-01-01 00:00:00.000000000 -0000 | ||
@@ -1,4 +1,5 @@ | ||
load("@io_bazel_rules_go//go:def.bzl", "go_library") | ||
+load("@rules_proto//proto:defs.bzl", "proto_library") | ||
|
||
filegroup( | ||
name = "go_default_library_protos", | ||
@@ -36,3 +37,14 @@ | ||
actual = ":errorspb", | ||
visibility = ["//visibility:public"], | ||
) | ||
+ | ||
+#keep | ||
+proto_library( | ||
+ name = "errorspb_proto", | ||
+ srcs = ["errors.proto"], | ||
+ deps = [ | ||
+ "@com_github_gogo_protobuf//gogoproto:gogo_proto", | ||
+ "@com_google_protobuf//:any_proto", | ||
+ ], | ||
+ visibility = ["//visibility:public"], | ||
+) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
diff -urN a/gogoproto/BUILD.bazel b/gogoproto/BUILD.bazel | ||
--- a/gogoproto/BUILD.bazel 1969-12-31 19:00:00.000000000 -0500 | ||
+++ b/gogoproto/BUILD.bazel 2000-01-01 00:00:00.000000000 -0000 | ||
@@ -1,4 +1,5 @@ | ||
load("@io_bazel_rules_go//go:def.bzl", "go_library") | ||
+load("@rules_proto//proto:defs.bzl", "proto_library") | ||
|
||
go_library( | ||
name = "gogoproto", | ||
@@ -20,3 +21,11 @@ | ||
actual = ":gogoproto", | ||
visibility = ["//visibility:public"], | ||
) | ||
+ | ||
+# keep | ||
+proto_library( | ||
+ name = "gogo_proto", | ||
+ srcs = ["gogo.proto"], | ||
+ deps = ["@com_google_protobuf//:descriptor_proto"], | ||
+ visibility = ["//visibility:public"], | ||
+) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
diff -urN a/descriptor/BUILD.bazel b/descriptor/BUILD.bazel | ||
--- a/descriptor/BUILD.bazel 1969-12-31 19:00:00.000000000 -0500 | ||
+++ b/descriptor/BUILD.bazel 2000-01-01 00:00:00.000000000 -0000 | ||
@@ -21,7 +21,7 @@ | ||
visibility = ["//visibility:public"], | ||
deps = [ | ||
"//proto:go_default_library", | ||
- "@io_bazel_rules_go//proto/wkt:descriptor_go_proto", | ||
+ "@com_github_golang_protobuf//protoc-gen-go/descriptor:go_default_library", | ||
"@org_golang_google_protobuf//reflect/protodesc:go_default_library", | ||
"@org_golang_google_protobuf//reflect/protoreflect:go_default_library", | ||
"@org_golang_google_protobuf//runtime/protoimpl:go_default_library", |
Oops, something went wrong.