Chih-Hung Hsieh | 92ff605 | 2020-06-10 20:18:39 -0700 | [diff] [blame] | 1 | # protobuf-codegen |
| 2 | |
| 3 | This crate contains protobuf code generator and a `protoc-gen-rust` `protoc` plugin. |
| 4 | |
| 5 | ## protoc-gen-rust |
| 6 | |
| 7 | `protoc-gen-rust` implements standard protobuf `protoc` plugin conventions. |
| 8 | |
| 9 | Probably you do not want to use it directly in Rust environment, there are easier to use alternatives: |
| 10 | |
| 11 | * [protoc-rust crate](https://github.com/stepancheg/rust-protobuf/tree/master/protoc-rust) |
| 12 | which can be invoked programmatically from `build.rs` of your project |
| 13 | which requires only `protoc` in `$PATH` but not `protoc-gen-rust`. |
| 14 | * [protobuf-codegen-pure crate](https://github.com/stepancheg/rust-protobuf/tree/master/protobuf-codegen-pure) |
| 15 | which behaves like protoc-rust, but does not depend on `protoc` binary |
| 16 | |
| 17 | ## But if you really want to use that plugin, here's the instruction |
| 18 | |
| 19 | (Note `protoc` can be invoked programmatically with |
| 20 | [protoc crate](https://github.com/stepancheg/rust-protobuf/tree/master/protoc/)) |
| 21 | |
| 22 | 0) Install protobuf for `protoc` binary. |
| 23 | |
| 24 | On OS X [Homebrew](https://github.com/Homebrew/brew) can be used: |
| 25 | |
| 26 | ``` |
| 27 | brew install protobuf |
| 28 | ``` |
| 29 | |
| 30 | On Ubuntu, `protobuf-compiler` package can be installed: |
| 31 | |
| 32 | ``` |
| 33 | apt-get install protobuf-compiler |
| 34 | ``` |
| 35 | |
| 36 | Protobuf is needed only for code generation, `rust-protobuf` runtime |
| 37 | does not use `protobuf` library. |
| 38 | |
| 39 | 1) Install `protoc-gen-rust` program (which is `protoc` plugin) |
| 40 | |
| 41 | It can be installed either from source or with `cargo install protobuf` command. |
| 42 | |
| 43 | 2) Add `protoc-gen-rust` to $PATH |
| 44 | |
| 45 | If you installed it with cargo, it should be |
| 46 | |
| 47 | ``` |
| 48 | PATH="$HOME/.cargo/bin:$PATH" |
| 49 | ``` |
| 50 | |
| 51 | 3) Generate .rs files: |
| 52 | |
| 53 | ``` |
| 54 | protoc --rust_out . foo.proto |
| 55 | ``` |
| 56 | |
| 57 | This will generate .rs files in current directory. |