22 releases (9 breaking)

new 0.10.0 Apr 16, 2025
0.9.0 Mar 5, 2025
0.8.0 Jan 20, 2025
0.7.0 Dec 16, 2024
0.1.0-rc.4 Jul 24, 2024

#258 in Magic Beans

Download history 1543/week @ 2024-12-27 3821/week @ 2025-01-03 5597/week @ 2025-01-10 5778/week @ 2025-01-17 4100/week @ 2025-01-24 3024/week @ 2025-01-31 5740/week @ 2025-02-07 4665/week @ 2025-02-14 3386/week @ 2025-02-21 6929/week @ 2025-02-28 5679/week @ 2025-03-07 7087/week @ 2025-03-14 5953/week @ 2025-03-21 4846/week @ 2025-03-28 4988/week @ 2025-04-04 6515/week @ 2025-04-11

23,928 downloads per month
Used in 62 crates (9 directly)

MIT/Apache

40KB
717 lines

Generates rust code from the proto files.

Protobuf files are collected recursively from $CARGO_MANIFEST_DIR/<input_root>/ directory. Corresponding "cargo:rerun-if-changed=..." line is printed to stdout, so that the build script running this function is rerun whenever proto files change. A single rust file is generated and stored at $OUT_DIR/<input_root>/gen.rs file.

Protobuf files are compiled to a protobuf descriptor stored at $OUT_DIR/<input_root>/gen.binpb. Additionally a "PROTOBUF_DESCRIPTOR=" line is printed to stdout. This can be used to collect all the descriptors across the build as follows:

  1. Checkout the repo to a fresh directory and then run "cargo build --all-targets" We need it fresh so that every crate containing protobufs has only one build in the cargo cache.
  2. grep through all target/debug/build/*/output files to find all "PROTOBUF_DESCRIPTOR=..." lines and merge the descriptor files by simply concatenating them.

Note that you can run this procedure for 2 revisions of the repo and look for breaking changes by running "buf breaking <after.binpb> --against <before.binpb>" where before.binpb and after.binpb are the concatenated descriptors from those 2 revisions.

The proto files are not expected to be self-contained - to import proto files from different crates you need to specify them as dependencies in the Config.dependencies. It is not possible to depend on a different proto bundle within the same crate (because these are being built simultaneously from the same build script).

Dependencies

~13–24MB
~337K SLoC