18 releases (5 breaking)

0.6.0 Nov 14, 2024
0.5.0 Oct 9, 2024
0.4.0 Oct 9, 2024
0.3.0 Sep 26, 2024
0.1.0-rc.4 Jul 24, 2024

#728 in Magic Beans

Download history 9263/week @ 2024-08-07 12301/week @ 2024-08-14 14704/week @ 2024-08-21 14294/week @ 2024-08-28 13344/week @ 2024-09-04 14984/week @ 2024-09-11 6537/week @ 2024-09-18 6429/week @ 2024-09-25 8138/week @ 2024-10-02 12525/week @ 2024-10-09 9714/week @ 2024-10-16 11126/week @ 2024-10-23 7657/week @ 2024-10-30 6629/week @ 2024-11-06 6234/week @ 2024-11-13 3273/week @ 2024-11-20

25,857 downloads per month
Used in 55 crates (8 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

~12–23MB
~314K SLoC