actr-web-protoc-codegen
Protoc code generator for creating actr-web code from Protobuf definitions.
Features
- ✅ Generate Rust WASM actor code from
.protofiles - ✅ Generate TypeScript type definitions
- ✅ Generate TypeScript ActorRef wrapper classes
- ✅ Optionally generate React Hooks
- 🔄 Automated code formatting
- 🔄 Custom template support
Usage
Option 1: use it from build.rs (recommended)
// build.rs
Option 2: use it through actr-cli
# Install `actr-cli` with web support
# Generate code
Option 3: use the programmatic API
use ;
let config = WebCodegenConfig ;
let codegen = new;
let files = codegen.generate?;
// Write files
files.write_to_disk?;
Generated Layout
Rust side (WASM)
src/generated/
├── mod.rs
├── echo.rs # EchoActor
└── ...
TypeScript side
src/generated/
├── index.ts
├── echo.types.ts # type definitions
├── echo.actor-ref.ts # EchoActorRef class
├── use-echo.ts # optional useEcho hook
└── ...
Configuration Options
| Option | Type | Required | Description |
|---|---|---|---|
proto_files |
Vec<PathBuf> |
✅ | List of proto files |
rust_output_dir |
PathBuf |
✅ | Rust output directory |
ts_output_dir |
PathBuf |
✅ | TypeScript output directory |
generate_react_hooks |
bool |
❌ | Generate React Hooks, default false |
includes |
Vec<PathBuf> |
❌ | Proto include paths |
format_code |
bool |
❌ | Format generated code, default false |
custom_templates_dir |
Option<PathBuf> |
❌ | Custom template directory |
Status
- Base architecture and configuration
- Full proto parsing with a handwritten parser
- Rust actor method generation
- TypeScript type generation
- TypeScript ActorRef method generation
- React Hooks generation
- Streaming method support
- Formatting integration with
rustfmtandprettier/dprint - Unit tests
- Optional
prost-buildintegration - Custom template support
- Integration tests
- Performance tuning
Examples
See the example projects under examples/:
examples/echo/- basic Echo service exampleexamples/simple-rpc/- end-to-end RPC example
License
Apache License 2.0