prebindgen-proc-macro 0.5.0

Procedural macros for prebindgen - export FFI definitions for binding generation
Documentation

prebindgen-proc-macro

Procedural macros for the prebindgen system.

This crate provides the procedural macros used by the prebindgen system:

  • #[prebindgen] or #[prebindgen("group")] - Attribute macro for marking FFI definitions
  • prebindgen_out_dir!() - Macro that returns the prebindgen output directory path
  • features!() - Macro that returns the list of features enabled for the crate

Crate features

  • inline (off by default) — inject #[inline] onto every function marked with #[prebindgen] (types/consts are unaffected).

    prebindgen wrappers are usually thin shims that forward to a native API. A non-generic pub fn in one crate is not inlined into a Rust caller in another crate unless the function is #[inline] or the final binary is built with link-time optimization. Without inlining, every wrapper call costs an extra cross-crate call (measurable on hot paths — e.g. a per-message publish loop).

    Two ways to make the wrappers zero-cost:

    1. Build the final artifact with LTO ([profile.release] lto = "fat", codegen-units = 1). Cross-crate inlining then happens automatically and this feature is redundant. This is the recommended setup for an FFI cdylib/staticlib and matches how upstream zenoh builds its release profile.
    2. Enable inline when you cannot rely on LTO — e.g. the wrapper crate is consumed as a normal Rust dependency by crates that build without LTO.

    It is opt-in because prebindgen can also wrap non-trivial functions where forcing #[inline] would only bloat the consumer; enable it only for genuine thin-wrapper libraries. The feature affects only the Rust function emitted into the wrapper crate — the recorded definition used for binding generation (and the resulting C ABI) is unchanged.

See also: prebindgen for the main processing library.