Bug: 158620710

Clone this repo:
  1. 94de443 Make protobuf-codegen available to product and vendor am: 67cc991324 by Matthew Maurer · 3 weeks ago emu-33-release master
  2. 67cc991 Make protobuf-codegen available to product and vendor by Matthew Maurer · 3 weeks ago
  3. dcf8cf0 Merge "Update protobuf-codegen to 2.27.1" am: 78338078b5 am: ad6438f959 am: eef6b8189c by Treehugger Robot · 1 year, 1 month ago android13-dev android13-mainline-go-adservices-release android13-mainline-go-odp-release android13-qpr2-release android13-qpr2-s1-release android13-qpr2-s2-release android13-qpr2-s3-release android13-qpr2-s5-release android13-qpr2-s6-release main-16k main-16k-with-phones aml_go_ads_330913000 aml_go_odp_330912000 android-13.0.0_r32 android-13.0.0_r33 android-13.0.0_r34 android-13.0.0_r35 android-13.0.0_r36 android-13.0.0_r37 t_frc_ase_330444010 t_frc_odp_330442000
  4. eef6b81 Merge "Update protobuf-codegen to 2.27.1" am: 78338078b5 am: ad6438f959 by Treehugger Robot · 1 year, 1 month ago
  5. ad6438f Merge "Update protobuf-codegen to 2.27.1" am: 78338078b5 by Treehugger Robot · 1 year, 1 month ago

Protobuf code generator

This crate contains protobuf code generator implementation and a protoc-gen-rust protoc plugin.

This crate:

  • provides protoc-gen-rust plugin for protoc command
  • implement protobuf codegen

This crate is not meant to be used directly, in fact, it does not provide any public API (except for protoc-gen-rust binary).

Code can be generated with either:

  • protoc-gen-rust plugin for protoc or
  • protoc-rust crate (code generator which depends on protoc binary for parsing of .proto files)
  • protobuf-codegen-pure crate, similar API to protoc-rust, but uses pure rust parser of .proto files.

protoc-gen-rust plugin for protoc

When non-cargo build system is used, consider using standard protobuf code generation pattern: protoc command does all the work of handling paths and parsing .proto files. When protoc is invoked with --rust_out= option, it invokes protoc-gen-rust plugin. provided by this crate.

When building with cargo, consider using protoc-rust or protobuf-codegen-pure crates.

How to use protoc-gen-rust if you have to

(Note protoc can be invoked programmatically with protoc crate)

  1. Install protobuf for protoc binary.

On OS X Homebrew can be used:

brew install protobuf

On Ubuntu, protobuf-compiler package can be installed:

apt-get install protobuf-compiler

Protobuf is needed only for code generation, rust-protobuf runtime does not use protobuf library.

  1. Install protoc-gen-rust program (which is protoc plugin)

It can be installed either from source or with cargo install protobuf command.

  1. Add protoc-gen-rust to $PATH

If you installed it with cargo, it should be

PATH="$HOME/.cargo/bin:$PATH"
  1. Generate .rs files:
protoc --rust_out . foo.proto

This will generate .rs files in current directory.

Version 2

This is documentation for version 2 of the crate.

Version 3 of the crate (currently in development) encapsulates both protoc and pure codegens in this crate.