How would I add a RUST plugin for a buf command line to generate rust libraries for protofile

729 Views Asked by At

I am working on a gRPC experiment at this githib repo, using buf cli to generate the gRPC server and Client libraries. I have it working in GoLang but I want to generate libraries for RUST.

The git repo is at: https://github.com/vinceyoumans/wc6

The buf file is at: buf.gen.yaml

I have RUST code commented out but I believe the problem is that I do not have correct plugin for RUST. The documentation to use the buf cli is almost nonexistent with buf. I am not a RUST expert either way. I am looking for guidance for strategies on how this should be done.

yaml file to use buf is...

 Documentation: https://docs.buf.build/configuration/v1/buf-gen-yaml
version: v1
plugins:
  - name: go # Synonym with: protoc-gen-<name>
    out: gen/go
    opt: paths=source_relative
  - name: go-grpc
    out: gen/go
    opt:
      - paths=source_relative
      - require_unimplemented_servers=false
#  - name: rust
#    out: gen/rust
#    opt: paths=source_relative
#  - name: rust
#    out: gen/rust
#    opt: paths=source_relative
2

There are 2 best solutions below

0
On

Take a look at https://docs.rs/protoc-gen-prost/latest/protoc_gen_prost/

There's configuration for using prost. Something like.

version: v1
plugins:
  - name: prost
    out: gen
    opt:
      - bytes=.
      - compile_well_known_types
      - extern_path=.google.protobuf=::pbjson_types
      - file_descriptor_set
      - type_attribute=.helloworld.v1.HelloWorld=#[derive(Eq\, Hash)]
0
On

Another alternative if you do not want to manually install and manage the plugins locally on your machine is to use the Remote Plugins feature of the Buf Schema Registry. A bit more details from the documentation site: https://buf.build/docs/bsr/remote-plugins/usage/

For that specific plugin, the Buf team packaged it and made it available here:

https://buf.build/community/neoeinstein-prost

And here's an example of how to use it:

# buf.gen.yaml
version: v1
plugins:
  - plugin: buf.build/community/neoeinstein-prost
    out: gen

Now you can run buf generate buf.build/bufbuild/eliza (this is referencing a published module from the BSR, but it could be your .proto files directly).

tree gen/                                     
gen/
└── buf.connect.demo.eliza.v1.rs