git.iko.soy/opencode-android
on master help sign in
35 lines 1.4 kB history raw
1//! Crux type-generation for the shared domain (built with `--features typegen`).
2//!
3//! Demonstrates the Crux type-sharing pipeline: the core's view types are the
4//! single source of truth, and this binary emits matching JVM type definitions
5//! for the shell to consume across an FFI boundary. In this NDK-less build the
6//! Android shell hand-mirrors these types (see `app/.../core/ViewModel.kt`);
7//! wiring a real `.so` would have it consume the generated output instead.
8//!
9//! Run: `cd shared && cargo run --features typegen --bin codegen`
10//! Output: `generated/` (JVM/Java sources + the bincode serde runtime).
12use std::path::PathBuf;
14use anyhow::Result;
15use crux_core::typegen::TypeGen;
16use shared::{MessageStatus, MessageView, Screen, SessionView, ToolView, ViewModel};
18fn main() -> Result<()> {
19 let mut gen = TypeGen::new();
21 // Register leaf types before the aggregates that reference them.
22 gen.register_type::<Screen>()?;
23 gen.register_type::<MessageStatus>()?;
24 gen.register_type::<ToolView>()?;
25 gen.register_type::<SessionView>()?;
26 gen.register_type::<MessageView>()?;
27 gen.register_type::<ViewModel>()?;
29 let out = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../generated");
30 std::fs::create_dir_all(&out)?;
31 gen.java("soy.iko.opencode.shared", &out)?;
33 println!("Generated shared JVM types into {}", out.display());
34 Ok(())