daml/BAZEL-go.md

21 lines
586 B
Markdown
Raw Normal View History

Update protobuf docs plugin (#11880) * Try to upgrade protobuf docs plugin changelog_begin changelog_end * Fix extension number 65020 is already registered Building `//ledger-api/grpc-definitions:ledger-api-docs` [failed with](https://github.com/digital-asset/daml/issues/11761#issuecomment-978947565) ``` panic: proto: extension number 65020 is already registered on message google.protobuf.FieldOptions ``` Go dependencies are now pulled in via Gazelle. By default Gazelle will generate new proto rules for any `.proto` files encountered in third party Go dependencies. However, many of these already have pregenerated `.pb.go` files generate with the appropriate configuration. The problem can be avoided by configuring Gazelle to not generate new proto rules, but instead use pre-existing `.pb.go` files. For reference the field number is set in [go-proto-validators](https://github.com/mwitkow/go-proto-validators/blob/32a686adf8b5194d3ea07d632d49b6fb344af678/validator.proto#L19) which is an indirect dependency through protoc-gen-doc. In this case we need to update protoc-gen-validate to v0.6.2 to include https://github.com/envoyproxy/protoc-gen-validate/commit/4f41f10dde19ec4dd9dd8cf6f7537139f52fb58b which fixes unknown label errors. * ./fmt * Expose gRPC status.proto for Haskell bindings * Update Gazelle to support embedsrcs on Windows `protoc-gen-doc` relies on `go:embed` file embedding https://github.com/pseudomuto/protoc-gen-doc/blob/2dde01902b28e8b2201d935467bc4308ec912255/resources.go#L8. Gazelle supports `embedsrcs`, however, it did not generate the attribute correctly on Windows due to the different directory separator. This is fixed in https://github.com/bazelbuild/bazel-gazelle/pull/1101. * Add gazelle to compatibility workspace It's loaded into `@daml`'s top-level `BUILD` file and ends up being a dependency of the compatibility workspace as well. * shift go_googleapis import * Delete dead code protobuf is imported transitively. * Document how to add Go dependencies Co-authored-by: Moritz Kiefer <moritz.kiefer@purelyfunctional.org> Co-authored-by: Andreas Herrmann <andreas.herrmann@tweag.io>
2021-11-25 23:51:24 +03:00
# Working with Go in Bazel
## Dependencies
Go dependencies are managed by [`go.mod`][go-deps] and [Gazelle][gazelle].
To add a new Go dependency
1. Run `go get` to add the dependency to `go.mod`. E.g.
```
go get github.com/envoyproxy/protoc-gen-validate@v0.6.2
```
This should update `go.mod` and `go.sum`.
2. Run Gazelle to import the dependencies to Bazel.
```
bazel run //:gazelle-update-repos
```
This should update `go_deps.bzl`.
[go-deps]: https://go.dev/doc/modules/managing-dependencies
[gazelle]: https://github.com/bazelbuild/bazel-gazelle