Covers the full FFI workflow from manual extern declarations through bindgen automation, cbindgen for exporting Rust to C, and the sys crate pattern for wrapping native libraries. Shows practical build.rs configurations for linking, allowlisting specific symbols in bindgen to avoid pulling in system headers, and writing safe Drop-based wrappers around unsafe handles. The examples are comprehensive, walking through CString conversions, null checks, and proper error handling at FFI boundaries. Honest take: this is exactly the reference you want when integrating C libraries, with enough real patterns that you won't just cargo cult Stack Overflow snippets. The split between raw bindings and safe wrappers follows established Rust conventions well.
- skills.sh installs
- 613
- GitHub stars
- 279
- last updated
- Aug 21, 2026
Install
$ npx -y skills add mohitmishra786/low-level-dev-skills --skill rust-ffi --agent claude-codeInstalls into .claude/skills of the current project.
Files
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)
// Declare external C functions manually
use std::ffi::{c_int, c_char, c_void, CStr, CString};
extern "C" {
fn strlen(s: *const c_char) -> usize;
fn malloc(size: usize) -> *mut c_void;
fn free(ptr: *mut c_void);
fn my_lib_init(config: *const c_char) -> c_int;
fn my_lib_process(handle: *mut c_void, data: *const u8, len: usize) -> c_int;
fn my_lib_cleanup(handle: *mut c_void);
}
Sponsors
Details
- Repository
- github.com/mohitmishra786/low-level-dev-skills
- Categories
- Documentation, Rust
- First seen
- Jun 3, 2026
More from mohitmishra786/low-level-dev-skills
All 54- Rust Unsafe611
- Pgo610
- Interpreters609
- Cargo Workflows608
- Rust Sanitizers Miri604
- Meson603
- Cpp Modules597
- Rust Debugging597
- Hardware Counters590
- Debug Optimized Builds579
- Cpp Templates574
- Rustc Basics567
- Rust Cross565
- Wasm Emscripten559
- Zig Debugging555
- Zig Build System552
- Zig Cross536
- Wasm Wasmtime532
- Zig Cinterop524
- Cmake1.8K
- Static Analysis1.2K
- Gdb1K
- Llvm948
- Sanitizers895
