|
| 1 | +//! `wsdl-gen` binary entrypoint. |
| 2 | +
|
| 3 | +use std::path::PathBuf; |
| 4 | + |
| 5 | +use anyhow::{Context, Result}; |
| 6 | +use clap::Parser; |
| 7 | +use wsdl_gen::emitter; |
| 8 | +use wsdl_gen::parser; |
| 9 | + |
| 10 | +/// Generate .proto files and Rust types from XSD schemas. |
| 11 | +#[derive(Parser, Debug)] |
| 12 | +#[command(name = "wsdl-gen", version)] |
| 13 | +struct Args { |
| 14 | + /// Directory tree to scan for `.xsd` files (recursive). |
| 15 | + #[arg(short, long)] |
| 16 | + input: PathBuf, |
| 17 | + |
| 18 | + /// Root of the generated proto tree (`proto/` in MOD-140); XSD shards go under `types/xsd/`. |
| 19 | + #[arg(long, default_value = "generated/proto")] |
| 20 | + out_proto: PathBuf, |
| 21 | + |
| 22 | + /// Output directory for generated Rust source files. |
| 23 | + #[arg(long, default_value = "generated/rust")] |
| 24 | + out_rust: PathBuf, |
| 25 | +} |
| 26 | + |
| 27 | +fn main() -> Result<()> { |
| 28 | + let args = Args::parse(); |
| 29 | + |
| 30 | + eprintln!("wsdl-gen: reading XSD files from {}", args.input.display()); |
| 31 | + |
| 32 | + let loaded = parser::load_schemas(&args.input).context("failed to parse XSD schemas")?; |
| 33 | + |
| 34 | + eprintln!("wsdl-gen: found {} type definitions", loaded.types.len()); |
| 35 | + |
| 36 | + std::fs::create_dir_all(&args.out_proto) |
| 37 | + .with_context(|| format!("creating {}", args.out_proto.display()))?; |
| 38 | + std::fs::create_dir_all(&args.out_rust) |
| 39 | + .with_context(|| format!("creating {}", args.out_rust.display()))?; |
| 40 | + |
| 41 | + let written = emitter::proto::write_partitioned_xsd_protos(&loaded, &args.out_proto) |
| 42 | + .context("write partitioned proto shards")?; |
| 43 | + for path in &written { |
| 44 | + eprintln!("wsdl-gen: wrote {}", path.display()); |
| 45 | + } |
| 46 | + |
| 47 | + let rust_src = emitter::rust::emit(&loaded.types); |
| 48 | + let rust_path = args.out_rust.join("messages.rs"); |
| 49 | + std::fs::write(&rust_path, &rust_src) |
| 50 | + .with_context(|| format!("writing {}", rust_path.display()))?; |
| 51 | + eprintln!("wsdl-gen: wrote {}", rust_path.display()); |
| 52 | + |
| 53 | + Ok(()) |
| 54 | +} |
0 commit comments