1+ // Build script for hedera-proto-wasm
2+ // This compiles ALL Hedera protobuf definitions using prost-build for WASM compatibility
3+
4+ use anyhow:: Result ;
5+ use std:: path:: Path ;
6+ use walkdir:: WalkDir ;
7+
8+ fn main ( ) -> Result < ( ) > {
9+ println ! ( "cargo:warning=Building COMPLETE Hedera protobufs for WASM using prost-build" ) ;
10+
11+ let proto_root = "../protobufs/services/hapi/hedera-protobuf-java-api/src/main/proto" ;
12+
13+ if !Path :: new ( proto_root) . exists ( ) {
14+ anyhow:: bail!( "Proto root directory not found: {}. Make sure git submodules are initialized." , proto_root) ;
15+ }
16+
17+ // Find all .proto files recursively
18+ let mut proto_files = Vec :: new ( ) ;
19+ for entry in WalkDir :: new ( proto_root) . into_iter ( ) . filter_map ( |e| e. ok ( ) ) {
20+ if entry. path ( ) . extension ( ) . and_then ( |s| s. to_str ( ) ) == Some ( "proto" ) {
21+ proto_files. push ( entry. path ( ) . to_string_lossy ( ) . to_string ( ) ) ;
22+ }
23+ }
24+
25+ if proto_files. is_empty ( ) {
26+ anyhow:: bail!( "No .proto files found in {}. Check your git submodules." , proto_root) ;
27+ }
28+
29+ println ! ( "cargo:warning=Found {} proto files" , proto_files. len( ) ) ;
30+
31+ // Brief summary of found files
32+ if proto_files. len ( ) > 5 {
33+ println ! ( "cargo:warning=Including {} proto files (showing first 5):" , proto_files. len( ) ) ;
34+ for ( i, file) in proto_files. iter ( ) . take ( 5 ) . enumerate ( ) {
35+ println ! ( "cargo:warning= {}: {}" , i + 1 , file. split( '/' ) . last( ) . unwrap_or( file) ) ;
36+ }
37+ } else {
38+ for file in & proto_files {
39+ println ! ( "cargo:warning=Including: {}" , file. split( '/' ) . last( ) . unwrap_or( file) ) ;
40+ }
41+ }
42+
43+ // Configure prost-build
44+ let mut config = prost_build:: Config :: new ( ) ;
45+
46+ // Set output file
47+ config. include_file ( "hedera_protos.rs" ) ;
48+
49+ // Configure prost for clean protobuf generation
50+
51+ // Compile all proto files
52+ config. compile_protos ( & proto_files, & [ proto_root] ) ?;
53+
54+ println ! ( "cargo:warning=Successfully compiled {} protobuf files for WASM" , proto_files. len( ) ) ;
55+
56+ // Tell cargo to rerun if proto files change
57+ println ! ( "cargo:rerun-if-changed={}" , proto_root) ;
58+
59+ Ok ( ( ) )
60+ }
0 commit comments