Skip to content
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

Protobuf APIV2 #304

Merged
merged 10 commits into from
May 3, 2021
Merged

Protobuf APIV2 #304

merged 10 commits into from
May 3, 2021

Conversation

marioizquierdo
Copy link
Contributor

@marioizquierdo marioizquierdo commented Apr 16, 2021

Fixes: #222, #301
Related: #299, #280, #275

Description

The protobuf library has updated from APIV1 github.com/golang/protobuf to APIV2 google.golang.org/protobuf. Now Twirp generates code using the new types.

Changes:

  • Generated code no longer depends on github.com/golang/protobuf/jsonpb, it now uses google.golang.org/protobuf/protojson
  • Generated code no longer depends on github.com/golang/protobuf/proto, it now uses google.golang.org/protobuf/proto
  • Code generator (protoc-gen-twirp) works with the latest version of google.golang.org/protobuf
  • Code generator (protoc-gen-twirp) improved usage of command line flags. It now accepts paths=import (default), paths=source_relative, module={PREFIX} and works well with multiple --proto_path sources. This makes it fully compatible with the flags used on protoc-gen-go compiler invocation: https://developers.google.com/protocol-buffers/docs/reference/go-generated#invocation
  • Update go_package on test proto files to use a fully qualified go import path. This is required by new versions of protoc-gen-go.
  • Removed dependency on gogo-protobuf. Twirp still works with it, but requires a dependency with protobuf APIV1.
  • Removed generated python code on Go tests, that was cluttering the test folders and did not have any effect on them.
  • Simplified Makefile and generate commands, being more explicit makes it easier to know where the binaries are situated.

Update instructions

  • The runtime library github.com/twitchtv/twirp does not have any changes.
  • Generated clients and services (with protoc plugin github.com/twitchtv/twirp/protoc-gen-twirp) will update their imports from github.com/golang/protobuf/proto (APIV1) to google.golang.org/protobuf (APIV2). Projects that make use of the generated clients or service have to update the imports as well.
  • The new google.golang.org/protobuf (APIV2) is mostly backwards compatible, but not completely. Some changes that we found needed in our own tests:
    • In the proto file, the option go_package is mandatory and must include a "/" (it is supposed to be a full import path). If you have to add a full path to the go_package, you may want to generate with the options paths=source_relative. For example: protoc --go_out=. --go_opt=paths=source_relative --twirp_out=. --twirp_opt=paths=source_relative myfile.proto
    • Generated message models (structs) now contain a mutex, your linter may complain if the models are copied by value. The solution is to peass pointers instead, or disable the lint for lines where a copy is made on purpose.
    • Check protobuf go compatibility and their releases for more details.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

…larly with all the go_package definitions in all the examples
…versions of protoc-gen-go and the new options that are needed
…hey generate code on the proper destination. Cleanup make file and keep removing test python files that are unused.
…olang.org/protobuf, both in generator and generated code. Fix tests. Fix parameter reading.
@marioizquierdo
Copy link
Contributor Author

This PR will be released on May 3rd (next Monday) as v8.0.0.
We are doing some more testing and completing documentation meanwhile.

@marioizquierdo marioizquierdo merged commit dc74479 into master May 3, 2021
@marioizquierdo marioizquierdo deleted the google_golang_protobuf branch May 3, 2021 21:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support Protobuf APIV2
2 participants