idlc in build.rs
The runnable companion to the
zerodds-idlchandbook's build-script section: abuild.rsthat shells out to the CLI and alib.rsthat includes the generated module.
- Example:
idlc-buildrs - Repository: zero-dds-snippets
What it shows
idl/Robot.idldefines an@appendable,@key-edRobot::Pose;build.rsruns the CLI andsrc/lib.rsinclude!s the result from$OUT_DIR.- It documents a real doc gap it found: the generated file carries file-level
#![allow(...)]inner attributes because it is designed to stand alone, andinclude!splices those into the including file where an inner attribute is only legal at the very top. Both the doc and this companion now strip those lines and re-apply the allows as outer attributes on the wrapper module. cargo testproves the roundtrip on the library target; the demo binary encodes and decodes aRobot::Pose.
Build and run
cargo test # roundtrip unit test on the lib target
cargo run --bin idlc-buildrs-demo
Output
idlc-buildrs-demo: 40 bytes on the wire, roundtripped Pose { robot_id: "R2D2", x: 1.0, y: 2.0, theta: 0.5 }
Taken verbatim from the example's own README.
See also
idlc in build.rs
Der lauffähige Begleiter zum Build-Script-Abschnitt des
zerodds-idlc-Handbuchs: einbuild.rs, das die CLI aufruft, und einlib.rs, das das generierte Modul einbindet.
- Beispiel:
idlc-buildrs - Repository: zero-dds-snippets
Was es zeigt
idl/Robot.idldefiniert ein@appendable-StructRobot::Posemit@key;build.rsruft die CLI auf undsrc/lib.rsbindet das Ergebnis aus$OUT_DIRperinclude!ein.- Es hält eine echte Lücke der Dokumentation fest: Die generierte Datei trägt Datei-Attribute
#![allow(...)], weil sie allein stehen soll, undinclude!schiebt diese in die einbindende Datei, wo ein inneres Attribut nur ganz oben zulässig ist. Dokument und Begleiter entfernen diese Zeilen jetzt und setzen dieselben Allows als äußere Attribute an das Wrapper-Modul. cargo testweist den Roundtrip auf dem Library-Target nach; das Demo-Binary codiert und decodiert eineRobot::Pose.
Bauen und ausführen
cargo test # Roundtrip-Unit-Test auf dem Lib-Target
cargo run --bin idlc-buildrs-demo
Ausgabe
idlc-buildrs-demo: 40 bytes on the wire, roundtripped Pose { robot_id: "R2D2", x: 1.0, y: 2.0, theta: 0.5 }
Wörtlich aus dem README des Beispiels übernommen.