A binding declares foreign functions and data types so code in another language can use them. In Rust–C integration, bindgen generates Rust FFI declarations from C headers; cbindgen generates C headers from Rust code. section 8.5 section 8.5.1
For embedded Rust, bindgen options help control generated declarations:
- --use-core selects Rust’s core library and maps C types to core::ffi types. section 8.5.1
- Allowlist options restrict generation to selected names; blocklist options exclude names that should not be generated. section 8.5.1
- Arguments after -- are passed to libclang, including the target used to parse the C header. section 8.5.1
bindgen example.h \ --use-core \ --allowlist-type "ExampleStruct" \ --allowlist-function "process_example" \ --blocklist-function "strcpy" \ --blocklist-var "errno" \ -o example_bindings.rs \ -- -target thumbv7em-none-eabi
This command generates Rust bindings for selected declarations, excludes named items, writes an output file, and passes an embedded target to libclang. section 8.5.1
