Put .proto compilation result to $OUT_DIR/

Sometimes CI build fails with

error: couldn't read storage_broker/src/../proto/storage_broker.rs: No such file or directory (os error 2)
  --> storage_broker/src/lib.rs:14:5
   |
14 |     include!("../proto/storage_broker.rs");
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

The root cause is not clear, but it looks like interference with cachepot. Per
cargo docs, build scripts shouldn't output to anywhere but OUT_DIR; let's follow
this and see if it helps.
This commit is contained in:
Arseny Sher
2022-11-28 19:08:28 +04:00
committed by Arseny Sher
parent 0a4e5f8aa3
commit 52166799bd
2 changed files with 9 additions and 5 deletions

View File

@@ -1,7 +1,11 @@
fn main() -> Result<(), Box<dyn std::error::Error>> { fn main() -> Result<(), Box<dyn std::error::Error>> {
// Generate code to deterministic location to make finding it easier. // Generate rust code from .proto protobuf.
tonic_build::configure() //
.out_dir("proto/") // put generated code to proto/ // Note: we previously tried to use deterministic location at proto/ for
.compile(&["proto/broker.proto"], &["proto/"])?; // easy location, but apparently interference with cachepot sometimes fails
// the build then. Anyway, per cargo docs build script shouldn't output to
// anywhere but $OUT_DIR.
tonic_build::compile_protos("proto/broker.proto")
.unwrap_or_else(|e| panic!("failed to compile protos {:?}", e));
Ok(()) Ok(())
} }

View File

@@ -11,7 +11,7 @@ use proto::{
// Code generated by protobuf. // Code generated by protobuf.
pub mod proto { pub mod proto {
include!("../proto/storage_broker.rs"); tonic::include_proto!("storage_broker");
} }
pub mod metrics; pub mod metrics;