Build patterns
Generated codecs ship their own embedded sbe_rt module. Linking the app
does not require ergo-sbe unless you use its macros or call the generator
library at runtime.
| Pattern | build-dependencies | dependencies | Typical use |
|---|---|---|---|
| Build only (samples default) | ergo-sbe | none | generate(..)?.write_to("src/generated") writes src/generated/ (gitignored, unpublished), included with #[path = "generated/….rs"] |
| OUT_DIR only | ergo-sbe | none | generate(..)?.write_to_out_dir() + include!(concat!(env!("OUT_DIR"), …)); the product shape without macros |
| Build + runtime (product default) | ergo-sbe | ergo-sbe | generate(..)?.write_to_out_dir() + sbe_mod! (expands to that include!); this is what cluster/build.rs and the introduction do |
| Runtime only | none | ergo-sbe | Call generate, or parse + Generator, as a library (no build.rs) |
Seeing generated code (without committing it)
include!(concat!(env!("OUT_DIR"), …)) and sbe_mod! put files under a
hashed path like target/debug/build/<crate>-<hash>/out/….rs, which is
awkward to open by hand.
Samples instead write to a stable, local path:
samples/<name>/src/generated/*.rs # created on cargo build, gitignored
cargo build --manifest-path samples/sbe-feature-tour/Cargo.toml- Open
samples/sbe-feature-tour/src/generated/feature_tour.rs - From app code, Go to definition on
CarEncoder/ etc. should land there
Root .gitignore has **/src/generated/. Do not commit those trees
(a large exchange schema generates several MB). Rebuild after a clean clone.
// build.rs
let out = Path::new(env!("CARGO_MANIFEST_DIR")).join("src/generated");
ergo_sbe::generate(ergo_sbe::SchemaSource::file("schemas/messages.xml"), config)?
.write_to(&out)?;
// src/lib.rs: real path, so IDE go-to-definition works
#[allow(dead_code, unused_imports, non_camel_case_types, non_snake_case, clippy::all, warnings)]
#[path = "generated/messages.rs"]
mod messages;