From 980077fb6f3e88780ec21e26922740f0cf3616b6 Mon Sep 17 00:00:00 2001 From: tac0turtle Date: Mon, 4 Aug 2025 11:19:27 +0200 Subject: [PATCH 1/3] modify build.rs --- client/crates/types/README.md | 36 +++++++++++++++++++++-------------- client/crates/types/build.rs | 35 +++++++++++++++++++++++++++++----- 2 files changed, 52 insertions(+), 19 deletions(-) diff --git a/client/crates/types/README.md b/client/crates/types/README.md index b1b9595acc..c2f0b5778e 100644 --- a/client/crates/types/README.md +++ b/client/crates/types/README.md @@ -1,6 +1,6 @@ -# rollkit-types +# ev-types -Proto-generated types for Rollkit. +Proto-generated types for Ev-node. ## Features @@ -13,7 +13,7 @@ Proto-generated types for Rollkit. ```toml [dependencies] -rollkit-types = "0.1" +ev-types = "0.0.1" ``` ### Types only (without gRPC) @@ -22,12 +22,12 @@ If you only need the message types without gRPC client/server code: ```toml [dependencies] -rollkit-types = { version = "0.1", default-features = false } +ev-types = { version = "0.0.1", default-features = false } ``` This is useful when: -- You only need to serialize/deserialize Rollkit messages +- You only need to serialize/deserialize Ev-node messages - You're using a different RPC framework - You want to minimize dependencies - You're building for environments where gRPC is not needed @@ -36,33 +36,41 @@ This is useful when: This crate generates two versions of the protobuf code: -1. **`rollkit.v1.messages.rs`** - Contains only the message types (structs/enums) with no gRPC dependencies -2. **`rollkit.v1.services.rs`** - Contains everything including gRPC client/server code +1. **`evnode.v1.messages.rs`** - Contains only the message types (structs/enums) with no gRPC dependencies +2. **`evnode.v1.services.rs`** - Contains everything including gRPC client/server code Both files are pre-generated and checked into the repository, so users don't need `protoc` installed or need to regenerate based on their feature selection. ## Building -The proto files are automatically generated during the build process: +The crate uses pre-generated proto files that are checked into version control. This ensures that the crate can be built from crates.io without requiring access to the original `.proto` files. ```bash cargo build ``` +The build script will: +1. Check if pre-generated files exist (`src/proto/evnode.v1.*.rs`) +2. If they exist, use them (this is the default behavior) +3. If they don't exist, attempt to generate them from source proto files + ## Proto Generation The generated code is committed to the repository. If you modify the proto files, you need to regenerate: ```bash -# From the repository root -make rust-proto-gen +# Force regeneration by setting the environment variable +EV_TYPES_FORCE_PROTO_GEN=1 cargo build -# Or directly -cd client/crates/rollkit-types -cargo build +# Or from the repository root (if a make target exists) +make rust-proto-gen ``` -**Important**: The build process generates both `rollkit.v1.messages.rs` and `rollkit.v1.services.rs`. Both files should be committed to ensure users can use the crate without needing to regenerate based on their feature selection. +**Important**: +- The build process generates both `evnode.v1.messages.rs` and `evnode.v1.services.rs` +- Both files should be committed to ensure users can use the crate without needing to regenerate +- When publishing to crates.io, the pre-generated files are included in the package +- Users installing from crates.io will use the pre-generated files automatically ## Version Consistency diff --git a/client/crates/types/build.rs b/client/crates/types/build.rs index 0e6aac7626..5ecaf4cde1 100644 --- a/client/crates/types/build.rs +++ b/client/crates/types/build.rs @@ -4,8 +4,37 @@ use walkdir::WalkDir; fn main() -> Result<(), Box> { let manifest_dir_str = env::var("CARGO_MANIFEST_DIR")?; let manifest_dir = Path::new(&manifest_dir_str); + + // Create output directories + let proto_dir = manifest_dir.join("src/proto"); + fs::create_dir_all(&proto_dir)?; + + // Check if generated files already exist + let messages_file = proto_dir.join("evnode.v1.messages.rs"); + let services_file = proto_dir.join("evnode.v1.services.rs"); + + // Check for environment variable to force regeneration + let force_regen = env::var("EV_TYPES_FORCE_PROTO_GEN").is_ok(); + + // If files exist and we're not forcing regeneration, skip generation + if !force_regen && messages_file.exists() && services_file.exists() { + println!("cargo:warning=Using pre-generated proto files. Set EV_TYPES_FORCE_PROTO_GEN=1 to regenerate."); + return Ok(()); + } + // Make the include dir absolute and resolved (no "..", symlinks, etc.) - let proto_root = manifest_dir.join("../../../proto").canonicalize()?; + let proto_root = match manifest_dir.join("../../../proto").canonicalize() { + Ok(path) => path, + Err(e) => { + // If proto files don't exist but generated files do, that's ok + if messages_file.exists() && services_file.exists() { + println!("cargo:warning=Proto source files not found at ../../../proto, using pre-generated files"); + return Ok(()); + } + // Otherwise, this is a real error + return Err(format!("Proto files not found and no pre-generated files available: {}", e).into()); + } + }; // Collect the .proto files let proto_files: Vec<_> = WalkDir::new(&proto_root) @@ -16,10 +45,6 @@ fn main() -> Result<(), Box> { }) .collect(); - // Create output directories - let proto_dir = manifest_dir.join("src/proto"); - fs::create_dir_all(&proto_dir)?; - // Always generate both versions and keep them checked in // This way users don't need to regenerate based on features From 0f177936a15923a7fabe8336891d1c6a998afd96 Mon Sep 17 00:00:00 2001 From: tac0turtle Date: Mon, 4 Aug 2025 11:35:26 +0200 Subject: [PATCH 2/3] fmt --- client/crates/types/build.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/client/crates/types/build.rs b/client/crates/types/build.rs index 5ecaf4cde1..02bd19b56d 100644 --- a/client/crates/types/build.rs +++ b/client/crates/types/build.rs @@ -4,24 +4,24 @@ use walkdir::WalkDir; fn main() -> Result<(), Box> { let manifest_dir_str = env::var("CARGO_MANIFEST_DIR")?; let manifest_dir = Path::new(&manifest_dir_str); - + // Create output directories let proto_dir = manifest_dir.join("src/proto"); fs::create_dir_all(&proto_dir)?; - + // Check if generated files already exist let messages_file = proto_dir.join("evnode.v1.messages.rs"); let services_file = proto_dir.join("evnode.v1.services.rs"); - + // Check for environment variable to force regeneration let force_regen = env::var("EV_TYPES_FORCE_PROTO_GEN").is_ok(); - + // If files exist and we're not forcing regeneration, skip generation if !force_regen && messages_file.exists() && services_file.exists() { println!("cargo:warning=Using pre-generated proto files. Set EV_TYPES_FORCE_PROTO_GEN=1 to regenerate."); return Ok(()); } - + // Make the include dir absolute and resolved (no "..", symlinks, etc.) let proto_root = match manifest_dir.join("../../../proto").canonicalize() { Ok(path) => path, @@ -32,7 +32,10 @@ fn main() -> Result<(), Box> { return Ok(()); } // Otherwise, this is a real error - return Err(format!("Proto files not found and no pre-generated files available: {}", e).into()); + return Err(format!( + "Proto files not found and no pre-generated files available: {e}" + ) + .into()); } }; From 9caf9e6f9fb52a9fbe8fa3e66ae17056c5f993fc Mon Sep 17 00:00:00 2001 From: tac0turtle Date: Mon, 4 Aug 2025 16:10:11 +0200 Subject: [PATCH 3/3] format --- client/crates/types/build.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/client/crates/types/build.rs b/client/crates/types/build.rs index 02bd19b56d..13bad04728 100644 --- a/client/crates/types/build.rs +++ b/client/crates/types/build.rs @@ -32,10 +32,9 @@ fn main() -> Result<(), Box> { return Ok(()); } // Otherwise, this is a real error - return Err(format!( - "Proto files not found and no pre-generated files available: {e}" - ) - .into()); + return Err( + format!("Proto files not found and no pre-generated files available: {e}").into(), + ); } };