Skip to content

Commit adf60e0

Browse files
tac0turtletac0turtle
andauthored
fix: proto inclusion (#2515)
<!-- Please read and fill out this form before submitting your PR. Please make sure you have reviewed our contributors guide before submitting your first PR. NOTE: PR titles should follow semantic commits: https://www.conventionalcommits.org/en/v1.0.0/ --> ## Overview Due to how we have the repo setup, there is an issue about including the proto files in the crate, this is a solution to fix this --------- Co-authored-by: tac0turtle <[email protected]>
1 parent 04637e6 commit adf60e0

File tree

2 files changed

+54
-19
lines changed

2 files changed

+54
-19
lines changed

client/crates/types/README.md

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# rollkit-types
1+
# ev-types
22

3-
Proto-generated types for Rollkit.
3+
Proto-generated types for Ev-node.
44

55
## Features
66

@@ -13,7 +13,7 @@ Proto-generated types for Rollkit.
1313

1414
```toml
1515
[dependencies]
16-
rollkit-types = "0.1"
16+
ev-types = "0.0.1"
1717
```
1818

1919
### Types only (without gRPC)
@@ -22,12 +22,12 @@ If you only need the message types without gRPC client/server code:
2222

2323
```toml
2424
[dependencies]
25-
rollkit-types = { version = "0.1", default-features = false }
25+
ev-types = { version = "0.0.1", default-features = false }
2626
```
2727

2828
This is useful when:
2929

30-
- You only need to serialize/deserialize Rollkit messages
30+
- You only need to serialize/deserialize Ev-node messages
3131
- You're using a different RPC framework
3232
- You want to minimize dependencies
3333
- You're building for environments where gRPC is not needed
@@ -36,33 +36,41 @@ This is useful when:
3636

3737
This crate generates two versions of the protobuf code:
3838

39-
1. **`rollkit.v1.messages.rs`** - Contains only the message types (structs/enums) with no gRPC dependencies
40-
2. **`rollkit.v1.services.rs`** - Contains everything including gRPC client/server code
39+
1. **`evnode.v1.messages.rs`** - Contains only the message types (structs/enums) with no gRPC dependencies
40+
2. **`evnode.v1.services.rs`** - Contains everything including gRPC client/server code
4141

4242
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.
4343

4444
## Building
4545

46-
The proto files are automatically generated during the build process:
46+
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.
4747

4848
```bash
4949
cargo build
5050
```
5151

52+
The build script will:
53+
1. Check if pre-generated files exist (`src/proto/evnode.v1.*.rs`)
54+
2. If they exist, use them (this is the default behavior)
55+
3. If they don't exist, attempt to generate them from source proto files
56+
5257
## Proto Generation
5358

5459
The generated code is committed to the repository. If you modify the proto files, you need to regenerate:
5560

5661
```bash
57-
# From the repository root
58-
make rust-proto-gen
62+
# Force regeneration by setting the environment variable
63+
EV_TYPES_FORCE_PROTO_GEN=1 cargo build
5964

60-
# Or directly
61-
cd client/crates/rollkit-types
62-
cargo build
65+
# Or from the repository root (if a make target exists)
66+
make rust-proto-gen
6367
```
6468

65-
**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.
69+
**Important**:
70+
- The build process generates both `evnode.v1.messages.rs` and `evnode.v1.services.rs`
71+
- Both files should be committed to ensure users can use the crate without needing to regenerate
72+
- When publishing to crates.io, the pre-generated files are included in the package
73+
- Users installing from crates.io will use the pre-generated files automatically
6674

6775
## Version Consistency
6876

client/crates/types/build.rs

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,39 @@ use walkdir::WalkDir;
44
fn main() -> Result<(), Box<dyn std::error::Error>> {
55
let manifest_dir_str = env::var("CARGO_MANIFEST_DIR")?;
66
let manifest_dir = Path::new(&manifest_dir_str);
7+
8+
// Create output directories
9+
let proto_dir = manifest_dir.join("src/proto");
10+
fs::create_dir_all(&proto_dir)?;
11+
12+
// Check if generated files already exist
13+
let messages_file = proto_dir.join("evnode.v1.messages.rs");
14+
let services_file = proto_dir.join("evnode.v1.services.rs");
15+
16+
// Check for environment variable to force regeneration
17+
let force_regen = env::var("EV_TYPES_FORCE_PROTO_GEN").is_ok();
18+
19+
// If files exist and we're not forcing regeneration, skip generation
20+
if !force_regen && messages_file.exists() && services_file.exists() {
21+
println!("cargo:warning=Using pre-generated proto files. Set EV_TYPES_FORCE_PROTO_GEN=1 to regenerate.");
22+
return Ok(());
23+
}
24+
725
// Make the include dir absolute and resolved (no "..", symlinks, etc.)
8-
let proto_root = manifest_dir.join("../../../proto").canonicalize()?;
26+
let proto_root = match manifest_dir.join("../../../proto").canonicalize() {
27+
Ok(path) => path,
28+
Err(e) => {
29+
// If proto files don't exist but generated files do, that's ok
30+
if messages_file.exists() && services_file.exists() {
31+
println!("cargo:warning=Proto source files not found at ../../../proto, using pre-generated files");
32+
return Ok(());
33+
}
34+
// Otherwise, this is a real error
35+
return Err(
36+
format!("Proto files not found and no pre-generated files available: {e}").into(),
37+
);
38+
}
39+
};
940

1041
// Collect the .proto files
1142
let proto_files: Vec<_> = WalkDir::new(&proto_root)
@@ -16,10 +47,6 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
1647
})
1748
.collect();
1849

19-
// Create output directories
20-
let proto_dir = manifest_dir.join("src/proto");
21-
fs::create_dir_all(&proto_dir)?;
22-
2350
// Always generate both versions and keep them checked in
2451
// This way users don't need to regenerate based on features
2552

0 commit comments

Comments
 (0)