cargo (Rust)¶
dsdlc writes a complete crate -- Cargo.toml, feature flags, and the runtime inside it -- so consuming it is a one-line path dependency.
| Language | Rust |
| Build system | cargo |
| Idiom | A -- the generated tree is the package |
| Regeneration | None -- regeneration is an explicit step |
Notes¶
The generated crate has no external dependencies, so this builds offline. Generation is a separate step here rather than a build.rs; for automatic regeneration, a build.rs calling dsdlc with cargo:rerun-if-changed on the namespace directory works.
Build values from Default, not from a struct literal. A variable-length field is a DsdlVec carrying the memory contract declared for that field, and Default is what installs it; DsdlVec::new() installs a default contract instead. VarArray derives PartialEq over that metadata as well as over the payload, so a value built with DsdlVec::new() compares unequal to the same value after a round trip even though every visible field matches. Start from Default and fill fields in.
Prerequisites¶
| Tool | Why |
|---|---|
cargo |
builds the crate and the round-trip binary |
Commands¶
Run these from the recipe directory, with dsdl/ and src/ copied alongside it. This is the exact sequence CI runs.
# generate
dsdlc --target-language rust dsdl/lanyard --rust-profile std --rust-crate-name lanyard --outdir generated
# build
cargo build --quiet --offline
# round-trip
cargo run --quiet --offline
The types this builds¶
The whole lanyard namespace -- twenty-four definitions, browsable from the showroom overview, where each one is paired with its wire-layout facts and a declaration excerpt in every language.
The build files¶
Cargo.toml¶
[package]
name = "lanyard-roundtrip"
version = "0.1.0"
edition = "2021"
# Idiom A in one line: the generated tree is a crate, so it is a path dependency and nothing else is
# needed. dsdlc wrote generated/Cargo.toml -- including the `std` / `no-std-alloc` feature flags that
# match the profile it was asked for -- and the runtime is inside the crate, so there is no companion
# package to add here and no version to keep in step with the compiler.
[dependencies]
lanyard = { path = "generated" }
[[bin]]
name = "roundtrip"
path = "src/rust/roundtrip.rs"