| Crates.io | dydx-proto |
| lib.rs | dydx-proto |
| version | 0.4.0 |
| created_at | 2024-10-28 11:39:10.134944+00 |
| updated_at | 2025-09-04 14:22:37.23897+00 |
| description | Compiled dYdX protobuf files |
| homepage | |
| repository | https://github.com/dydxprotocol/v4-chain/tree/main/v4-proto-rs |
| max_upload_size | |
| id | 1425519 |
| size | 2,365,052 |
Cargo.toml
[dependencies]
dydx-proto = "0.4.0"
Note: by default, rust stub files are not rebuilt (see Q&A below)
For more idiomatic Rust you can use conversions (try_into and into) for the following types:
prost_types::Timestamp -> std::time::SystemTimeprost_types::Duration-> std::time::DurationThen for a code (re-)generation run
V4_PROTO_REBUILD=1 cargo build -vv
Before publishing make sure to run (and fix all warnings and errors)
cargo fmt
cargo clippy
cargo deny check licenses advisories sources
Why do we put autogenerated files to the crate (and git) and do not (re-)generate them at compilation?
For several reasons:
protoc and buf are only needed for code generation)But if a user wants to (re-)generate at compilation time, he/she can set an environment variable V4_PROTO_REBUILD (to any value).
Why do I need a protoc for this crate development? I thought prost-build crate generates everything natively with Rust?
The main work (parsing, linking, etc. - have a look https://protobuf.com/docs/descriptors) is done by protoc.
The result of the protoc work is a "file descriptor" (think of it as IR assembly language like LLVM IR) - a binary file. This file descriptor is an input for a language-specific code generator like prost. Think of prost crate as a compiler target which generates a ISA-specific "assembly" (in our case, Rust) as an output.
prost-build always used the protoc but since version 0.11 of prost-build it requires protoc (the protobuf compiler) to be already installed on the system - before the protoc could be compiled during the prost-build build (https://github.com/tokio-rs/prost/blob/v0.10.4/prost-build/build.rs#L77).
Why do we use tonic-build crate and not just prost-build?
prost-build generates only serialization-deserialization stubs for messages, but we also need a client implementation (generated by tonic-build) because packages in other language implementations of v4-chain have ones.
Why do we need buf?
Buf is a tool whose primary function is to resolve dependencies in protobuf files. Protobuf specifications can refer to 3rd-party protobuf specifications and use types declared there. Basically, buf builds a list of all used protobuf files, downloads them, and allows exporting (=copying) them to a specified directory. The proto files in this repository and downloaded 3rd-party proto files (aka "includes") are an input for the protoc.