Rust tooling for CGMES CIM data: struct generation, SHACL validation, decoding, and protobuf conversion.
| Crate | Description |
|---|---|
cimgen |
Code generator — reads ENTSO-E RDF/SHACL schemas and emits Rust source |
cimstructs |
Generated. Typed Rust structs for every CIM class |
cimvalidation |
Generated. One Check* function per SHACL constraint |
cimdecoder |
Deserialises CGMES RDF/XML into cimstructs types |
cimstructs/ and cimvalidation/ are fully generated — do not hand-edit them.
Clone with submodules (the ENTSO-E RDF schema and SHACL files are required):
git clone --recurse-submodules <url>
# or after a plain clone:
git submodule update --init --recursive# Build everything
cargo build -v
# Run all tests (requires submodules)
cargo test
# Regenerate cimstructs and cimvalidation from schema files
cargo run -p cimgen# Run all benchmarks
cargo bench -p cimdecoder
# Run a specific group (e.g. the import benchmark)
cargo bench -p cimdecoder --bench real_grid -- importBenchmarks are in cimdecoder/benches/real_grid.rs and use the RealGrid test dataset
from the CGMES-Test-Configurations submodule (must be initialised). The import
group measures decode_files_parallel with real file paths, matching what
cimoxide-cli import does. Add debug symbols to get useful flamegraphs:
# Cargo.toml
[profile.bench]
debug = truecimgen/tests/codegen.rs contains two hash-based tests that detect unintended drift in
the generated output — the same pattern used in cimgo:
cimstructs_codegen_stable— runs the RDF struct generator and hashescimstructs/src/cimvalidation_codegen_stable— runs the SHACL generator and hashescimvalidation/src/
Each test regenerates into a temporary directory under target/ and compares the
directory hash against a stored expected value. A mismatch means either the generator
logic or the schema files changed and the checked-in generated code needs to be updated.
After the initial generation, or after any intentional schema/generator change, update the stored hashes:
- Run the tests and let them fail — the actual hash is printed in the failure message:
cargo test -p cimgen --test codegen -- --nocapture - Copy the printed hash into the corresponding
assert_eq!incimgen/tests/codegen.rs. - Regenerate the checked-in files so they match:
cargo run -p cimgen
- Commit both the updated test hashes and the regenerated source files together.
cargo test -p cimgen --test codegen is the check to add to CI. It requires the
submodule to be checked out (schema files are needed to regenerate) and will fail if
the generator output has changed relative to the stored hash.