Rust FFI
Purpose
Guide agents through Rust's Foreign Function Interface: calling C from Rust with bindgen, exporting Rust to C with cbindgen, writing safe wrappers, linking libraries via build.rs, and structuring sys crates.
Triggers
- "How do I call a C library from Rust?"
- "How do I use bindgen to generate Rust bindings?"
- "How do I export Rust functions to be called from C?"
- "How do I write a safe wrapper around an unsafe C API?"
- "How do I link a system library in Rust?"
- "What is a sys crate and how do I structure one?"
Workflow
1. Calling C without bindgen (manual declarations)
2. bindgen for automatic binding generation
3. sys crate pattern
Structure:
4. Writing safe wrappers
5. Exporting Rust to C with cbindgen
6. Linking libraries in build.rs
For bindgen and cbindgen configuration details, see references/bindgen-cbindgen.md [blocked].
Related skills
- Use
skills/rust/rustc-basicsfor RUSTFLAGS affecting FFI builds - Use
skills/rust/cargo-workflowsfor build.rs integration and sys crate layout - Use
skills/zig/zig-cinteropfor Zig's equivalent C interop approach - Use
skills/binaries/dynamic-linkingfor dynamic library linking details


