Expand description
§rusteron-code-gen
rusteron-code-gen is an internal code generation tool used within the Rusteron project.
It automates the creation of Rust bindings from Aeron’s C APIs, reducing manual effort and ensuring consistent wrapper interfaces across the rusteron-* crates.
§Purpose
Aeron’s C APIs follow predictable structural patterns. This tool parses those C headers and uses templates to emit Rust wrappers around the raw FFI layer. It is primarily used to generate:
rusteron-clientrusteron-archiverusteron-media-driver
By automating this step, we reduce maintenance cost and improve reliability when tracking upstream changes in Aeron.
Note: This crate is not intended for standalone use outside the Rusteron project.
§Sponsored by GSR
Rusteron is proudly sponsored and maintained by GSR, a global leader in algorithmic trading and market making in digital assets.
It powers mission-critical infrastructure in GSR’s real-time trading stack and is now developed under the official GSR GitHub organization as part of our commitment to open-source excellence and community collaboration.
We welcome contributions, feedback, and discussions. If you’re interested in integrating or contributing, please open an issue or reach out directly.
§Features
- Automated Code Generation – Converts Aeron C headers into Rust-safe APIs.
- Pattern-Based Templating – Leverages Aeron’s consistent structure to minimize boilerplate.
- Integration-Friendly – Output is directly used in production modules of the Rusteron stack.
§Usage
This crate is used via internal tooling (e.g. in just scripts or CI pipelines) and is not meant to be added as a dependency in consumer projects.
§Safety Considerations
Generated code includes unsafe blocks where necessary to interface with Aeron’s low-level constructs.
While much of the generation is automated, occasional manual review and patching may be required to ensure correctness, especially when Aeron introduces API changes.
§License & Acknowledgments
Dual-licensed under MIT or Apache-2.0. See the root README.
Special thanks to:
- @mimran1980, a core low-latency developer at GSR and the original creator of Rusteron - your work made this possible!
- @bspeice for the original
libaeron-sys - The Aeron community for open protocol excellence
Modules§
- c_build
- Release compiler flags for the vendored Aeron C build.
- test_
logger
Macros§
- cformat
format!for C strings: builds the formattedStringand converts it to aCStringin one visibly-named step.
Structs§
- AeronC
Error - Aeron C API error: code + optional message.
- Arg
- Backoff
Idle Strategy - Adaptive backoff: spin a few times, then yield a few times, then sleep with an exponentially
growing park up to a max. A good general-purpose strategy. (Aeron
BackoffIdleStrategy.) - Busy
Spin Idle Strategy - Spin with a CPU pause hint. Lowest latency, pins a core. (Aeron
BusySpinIdleStrategy.) - CBinding
- CHandler
- CWrapper
- Channel
Uri - Represents the Aeron URI parser and handler.
- Classified
Arg - One argument, classified once, with every emission fragment precomputed.
- Classified
Method Args - Handler
- Heap-allocated, reference-counted holder for a callback the C client keeps and fires later, possibly many times, from the conductor thread.
- Handlers
- Utility method for setting empty handlers
- ManagedC
Resource - A custom struct for managing C resources with automatic cleanup.
- Method
- NoHandler
- Type-level “no callback” sentinel.
- NoOp
Idle Strategy - No-op — never yields the core. (Aeron
NoOpIdleStrategy.) - Return
Type - Sleeping
Idle Strategy - Sleep for a fixed duration when idle. (Aeron
SleepingIdleStrategy.) - Yielding
Idle Strategy - Yield the OS thread when idle. Lower CPU than busy-spin, slightly higher latency.
(Aeron
YieldingIdleStrategy.)
Enums§
- Aeron
Error Type - Aeron
Offer Error - Typed error for
offer/try_claimon a publication. - ArgProcessing
- ArgRole
- Role of a C argument in the generated Rust wrapper method.
- CResource
- Control
Mode - Enum for control modes.
- Media
- Enum for media types.
Constants§
- AERON_
DIR_ PROP_ NAME - AERON_
IPC_ MEDIA - AERON_
UDP_ MEDIA - ARCHIVE_
BINDINGS - CLIENT_
BINDINGS - COMMON_
CODE - CUSTOM_
AERON_ CODE - CUSTOM_
ARCHIVE_ CODE - DRIVER_
TIMEOUT_ MS_ DEFAULT - MEDIA_
DRIVER_ BINDINGS - SPY_
PREFIX - TAG_
PREFIX - UNWIND_
HANDLER_ TYPES - Handler types declared
extern "C-unwind": the handler typesUNWIND_POLL_FNStake. Needed before parsing, as bindgen sets the ABI; a test checks it matches the bindings - UNWIND_
POLL_ FNS - C functions a handler panic may pass through, checked by reading the Aeron C source: they save the position only after the handler returns, so the next poll redelivers from the last saved position. Not derivable from the headers. Any other C function gets trampolines that catch the panic, so a missing entry is safe, just not zero cost
Traits§
- Idle
Strategy - Back off a poll loop when the last cycle did no work. Mirrors Aeron’s
IdleStrategy:idle(work_count)returns immediately whenwork_count > 0, otherwise spins / yields / sleeps depending on the implementation. - IntoC
String
Functions§
- append_
to_ file - classify_
method_ args - Classify every argument of
methodonce.owned_retainedmirrors the owned-setter rule:&selfmethod, int return, exactly one retained handler, no&mutprimitives. - find_
unused_ udp_ port - format_
token_ stream - format_
with_ rustfmt - generate_
handlers - generate_
rust_ code - get_
possible_ wrappers - is_
sync_ handler_ type - is_
udp_ port_ available - parse_
bindings - parse_
bindings_ with_ custom - Like
parse_bindings, additionally scanning per-crate custom code (appended after the commonaeron_custom.rs) so its hand-written methods are skipped during generation. - parse_
custom_ methods - Parse
aeron_custom.rssource and return a map ofClassName -> {method_names}for everyimpl ClassName { fn method_name ... }block found. This lets the generator skip auto-generating methods that have hand-written overrides. - snake_
to_ pascal_ case
Type Aliases§
- Cleanup
Box - RcOrArc
- Reference-counting smart pointer:
Rcby default,Arcunder themulti-threadedfeature. Swap is transparent —RcOrArc::new,.clone(),strong_countall work on both. - RefCell
OrMutex