rust-ffi

Generate Rust-C FFI bindings with bindgen and cbindgen.

Updated Aug 23, 2026
One-click install
npx skills add https://github.com/awfixers-stuff/opencode-config --skill rust-ffi-awfixers-stuff
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: rust-ffi
Source: https://github.com/awfixers-stuff/opencode-config/tree/main/skills/rust-ffi
Command: npx skills add https://github.com/awfixers-stuff/opencode-config --skill rust-ffi-awfixers-stuff

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Rust and C interop can be error-prone and verbose. This Skill provides patterns and examples to bridge Rust with C libraries, generate bindings, export Rust APIs to C, and structure safe wrappers around unsafe FFI, enabling reliable cross-language integration.

Core Features & Use Cases

  • Manual extern blocks for calling C without bindings when needed
  • bindgen-based automatic binding generation to wrap C APIs in Rust
  • cbindgen-driven exporting of Rust APIs to C for use by C clients
  • Safe wrapper patterns around unsafe FFI to protect invariants
  • System/ffi crate layouts (sys crate) with build.rs integration for linking
  • Clear guidance on linking system and vendor libraries in Rust projects

Quick Start

Create a minimal Rust wrapper around a C library, generate bindings with bindgen, and wire a build script to link the library.

Frequently Asked Questions about rust-ffi

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I call C libraries from Rust using FFI?

You can call C libraries from Rust by writing manual extern blocks or using bindgen to generate bindings, then wiring a build.rs script to handle library linking.

What is the best way to export Rust APIs to C?

Export Rust APIs to C by using cbindgen to automatically generate C headers, allowing C clients to seamlessly interface with your Rust code.

How do I create a safe wrapper around unsafe Rust FFI?

Create a safe wrapper around unsafe Rust FFI by applying safe wrapper patterns to protect invariants, ensuring reliable cross-language integration by hiding unsafe calls behind a safe API.

How do I set up a sys crate for Rust-C interop?

Set up a sys crate for Rust-C interop by structuring your ffi crate layout and integrating a build.rs script to manage standard linking workflows for system and vendor libraries.

When should I use bindgen instead of manual extern blocks in Rust?

Use bindgen for automatic binding generation when wrapping large C APIs in Rust, whereas manual extern blocks are better for calling C without bindings when needed.

How do I link system and vendor libraries in a Rust project?

Link system and vendor libraries in a Rust project by configuring a standard build.rs script to handle linking workflows, ensuring proper integration during the sys crate build process.