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 definitionsprebindgen_out_dir!()- Macro that returns the prebindgen output directory pathfeatures!()- 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 fnin 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:
- 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 FFIcdylib/staticliband matches how upstream zenoh builds its release profile. - Enable
inlinewhen 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. - Build the final artifact with LTO (
See also: prebindgen for the main processing library.