I am working on a Rust workspace with several crates, including libp2p (version 0.54). During the build process (cargo build), I notice that protobuf-src is being compiled, which significantly increases the build time:
Compiling libp2p v0.54.1
Building [=======================> ] 496/512: protobuf-src(build)
Details of My Setup:
Rust version: 1.71
libp2p version: 0.54
[workspace.dependencies]
libp2p = { version = "0.54", features = ["gossipsub", "kad", "tcp", "noise", "serde", "yamux"] }
Environment:
OS: [e.g., Ubuntu 22.04]
Installed protoc version: 3.21.9 (system-installed via apt)
Problem:
The protobuf-src dependency appears to compile Protobuf from source during the build, even though I already have Protobuf installed system-wide. This happens repeatedly and increases build time significantly.
Installed Protobuf System-Wide:
sudo apt install protobuf-compiler libprotobuf-dev
Verified the protoc version:
protoc --version
# Output: libprotoc 3.21.9
Set the PROTOC Environment Variable: Set PROTOC to point to the system-installed protoc binary:
export PROTOC=/usr/bin/protoc
Re-ran cargo build, but protobuf-src is still being compiled.
I have Searched for libp2p Features: Looked into the libp2p documentation for features to disable Protobuf-related functionality, but couldn’t find any specific flags for this.
Precompiled Protobuf Files: Considered precompiling .proto files and committing the generated Rust code, but I am unsure how to integrate this cleanly with libp2p.
Question:
How can I avoid compiling protobuf-src during the build process for libp2p? Is there a way to force libp2p or its dependencies to use the pre-installed Protobuf binaries on my system?
Additional Context:
My project is large, with several crates, and is built in both local and CI environments. Avoiding protobuf-srccompilation would save significant build time.
If libp2p uses an indirect dependency (like prost-build) that triggers this, is there a workaround?
Any help or suggestions would be greatly appreciated!
Vinay Vijay Sawant is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1