Skip to content

Commit

Permalink
fix: can't build when there are no .proto files
Browse files Browse the repository at this point in the history
  • Loading branch information
Yumeo0 committed Nov 10, 2024
1 parent d2eb805 commit ff8d277
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 2 deletions.
38 changes: 38 additions & 0 deletions proto_gen/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion proto_gen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ path = "lib.rs"

[dependencies]
protobuf = "3.7.1"

serde = { version = "1.0.214", features = ["derive"] }
serde_json = "1.0.132"

[build-dependencies]
tracing = "0.1.40"
protobuf-codegen = "3.7.1"
protobuf = "3.7.1"
12 changes: 11 additions & 1 deletion proto_gen/build.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use protobuf_codegen::Codegen;
use std::fs;
use std::path::PathBuf;
use tracing::warn;

fn main() {
// Define paths
Expand All @@ -13,10 +14,19 @@ fn main() {
// Create the output directory if it doesn't exist
fs::create_dir_all(proto_out).expect("Failed to create output directory");

let proto_files = get_proto_files(proto_src);
if proto_files.len() == 0 {
warn!(
"Skipping protobuf generation: no .proto files found in {}",
proto_src
);
return;
}

// Generate Rust files from .proto
Codegen::new()
.out_dir(proto_out)
.inputs(&get_proto_files(proto_src))
.inputs(&proto_files)
.includes(&[proto_src])
.run()
.expect("Failed to generate protobuf Rust files");
Expand Down

0 comments on commit ff8d277

Please sign in to comment.