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 (product / samples default)ergo-sbegenerate_to_dirsrc/generated/ (gitignored) + #[path = "generated/….rs"]
OUT_DIR onlyergo-sbegenerate_to_out_dir + include!(concat!(env!("OUT_DIR"), …)) — fine for apps; poor IDE go-to-def
Build + runtimeergo-sbeergo-sbeMacros such as sbe_mod! plus build-time generation
Runtime onlyergo-sbeCall 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 — hard to find and rust-analyzer usually cannot jump into them.

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 (Binance alone is multi‑MB). Rebuild after a clean clone.

  // build.rs
  let out = Path::new(env!("CARGO_MANIFEST_DIR")).join("src/generated");
  ergo_sbe::generate_to_dir("schemas/messages.xml", config, &out)?;

  // src/lib.rs — real path → 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;