Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

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.

Patternbuild-dependenciesdependenciesTypical use
Build only (samples default)ergo-sbenonegenerate(..)?.write_to("src/generated") writes src/generated/ (gitignored, unpublished), included with #[path = "generated/….rs"]
OUT_DIR onlyergo-sbenonegenerate(..)?.write_to_out_dir() + include!(concat!(env!("OUT_DIR"), …)); the product shape without macros
Build + runtime (product default)ergo-sbeergo-sbegenerate(..)?.write_to_out_dir() + sbe_mod! (expands to that include!); this is what cluster/build.rs and the introduction do
Runtime onlynoneergo-sbeCall 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
  1. cargo build --manifest-path samples/sbe-feature-tour/Cargo.toml
  2. Open samples/sbe-feature-tour/src/generated/feature_tour.rs
  3. 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;