Skip to content

Commit 6a27457

Browse files
Modify WSDL-Gen to no longer emit a single root proto file (#24)
* Add directories * Add changeset * Fix roundtrip * Fix post merge issues * Update test fixtures * Remove stale allows * Update file swap * Cargo fmt * Fix clippy call out * Fix temp race and extension bug
1 parent 1e4e010 commit 6a27457

14 files changed

Lines changed: 696 additions & 156 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@spear-ai/webway": minor
3+
---
4+
5+
**wsdl-gen (MOD-151):** Emit XSD protobuf types as one file per schema stem under `types/xsd/{schema_filename}.proto` with `package spear.v1.{schema_filename}` (MOD-140 layout). `--out-proto` is the proto tree root; the single root `messages.proto` is no longer written. Cross-schema `TypeRef::Named` edges emit sorted `import` lines and fully qualified types across packages. Duplicate `.xsd` filename stems in different directories fail codegen; cyclic cross-schema type references fail codegen. Rust output remains one `messages.rs`. The `wsdl-gen` crate is now a library plus binary (`src/lib.rs`, `src/bin/wsdl-gen.rs`).

CLAUDE.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ cargo test -p spear-lib
3030

3131
```bash
3232
# XSD → proto + Rust
33-
cargo run -p wsdl-gen -- --input schemas/synthetic --out-proto generated/types.proto --out-rust generated/types.rs
33+
cargo run -p wsdl-gen -- --input schemas/synthetic --out-proto generated/proto --out-rust generated/rust
3434

3535
# C headers → Rust structs + proto + mapping
3636
cargo run -p header-gen -- --input headers/ --include /usr/include --endian little --word-size 32 --define LINUX --out-rust generated/rust --out-proto generated/proto --out-mapping generated/mapping
@@ -64,7 +64,7 @@ Workspace-shared dependencies live in the root `Cargo.toml`. Key ones: `prost`,
6464

6565
### Testing patterns
6666

67-
`wsdl-gen` tests use round-trip encode/decode with synthetic schemas in `schemas/synthetic/` (five representative XSD files). Fixtures live under `crates/wsdl-gen/tests/fixtures/`. Tests verify: `encode_raw → decode_raw` roundtrip and `encoded_size` accuracy.
67+
`wsdl-gen` tests use round-trip encode/decode with synthetic schemas in `schemas/synthetic/`. Fixtures live under `crates/wsdl-gen/tests/fixtures/`. Tests verify: `encode_raw → decode_raw` roundtrip and `encoded_size` accuracy.
6868

6969
### Airgapped deployment
7070

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# podman exec -it spear-dev bash
1313
#
1414
# Inside the container:
15-
# wsdl-gen --input /workspace/xsds --out-proto /workspace/types.proto --out-rust /workspace/types.rs
15+
# wsdl-gen --input /workspace/xsds --out-proto /workspace/proto --out-rust /workspace/rust
1616
# header-gen --input /workspace/headers --endian little --word-size 32 \
1717
# --out-rust /workspace/rust --out-proto /workspace/proto --out-mapping /workspace/mapping
1818
# cp /workspace/types.rs /spear/crates/spear-gateway/src/types.rs

crates/wsdl-gen/Cargo.toml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,19 @@ name = "wsdl-gen"
33
version = "0.4.4"
44
edition = "2021"
55

6+
[lib]
7+
path = "src/lib.rs"
8+
69
[[bin]]
710
name = "wsdl-gen"
8-
path = "src/main.rs"
11+
path = "src/bin/wsdl-gen.rs"
912

1013
[dependencies]
1114
roxmltree = { workspace = true }
1215
clap = { workspace = true }
1316
anyhow = { workspace = true }
17+
tempfile = { workspace = true }
1418

1519
[dev-dependencies]
1620
prost = { workspace = true }
1721
serde = { workspace = true }
18-
tempfile = { workspace = true }
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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

Comments
 (0)