Rust FFI Crate Creation

Creates a two-crate Rust workspace for binding C libraries.

Updated Mar 10, 2026
One-click install
npx skills add https://github.com/qbradley/sqlite-objs --skill rust-ffi-crate-creation
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: Rust FFI Crate Creation
Source: https://github.com/qbradley/sqlite-objs/tree/main/.squad/skills/rust-ffi-crate
Command: npx skills add https://github.com/qbradley/sqlite-objs --skill rust-ffi-crate-creation

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires cc, libc, thiserror, tempfile, and includes references (resource) components.

What problem does it solve?

This Skill streamlines the process of creating safe and idiomatic Rust bindings for existing C libraries, especially those requiring compilation of C source code or linking against system dependencies.

Core Features & Use Cases

  • Two-Crate Structure: Separates raw FFI (-sys crate) from safe Rust wrappers (library crate).
  • Automated C Compilation: Uses build.rs and the cc crate to compile C sources directly.
  • System Library Discovery: Integrates with pkg-config and Homebrew for flexible dependency management.
  • Use Case: Integrating a complex C library like libcurl or OpenSSL into a Rust project, providing a clean and safe API for Rust developers.

Quick Start

Use the rust-ffi-crate skill to create a two-crate Rust workspace for binding to a C library named 'my_c_lib'.

Frequently Asked Questions about Rust FFI Crate Creation

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

FAQPage Schema
How do I create Rust bindings for a C library with system dependencies?

You create Rust bindings for a C library by setting up a two-crate workspace structure that separates raw FFI declarations in a `-sys` crate from safe Rust APIs in a wrapper crate, managing system library linking via build scripts.

What is the best way to structure a Rust FFI project for C code compilation?

The best way to structure Rust FFI projects is using a two-crate workspace that isolates unsafe FFI declarations in a `-sys` crate while providing safe, idiomatic Rust wrapper APIs in the main library crate.

How do I compile C source code automatically when building a Rust crate?

You compile C source code automatically during Rust crate builds by using a `build.rs` script integrated with the `cc` crate to handle C code compilation and system library linking directly.

Can I use pkg-config and Homebrew for system library discovery in Rust FFI?

Yes, you can use pkg-config and Homebrew for system library discovery in Rust FFI, allowing flexible dependency management when linking external C functionalities into your Rust project.

Why separate unsafe FFI declarations from safe Rust APIs when binding C libraries?

Separating unsafe FFI declarations from safe Rust APIs provides clear boundaries in your codebase, ensuring that the raw `-sys` crate handles C bindings while the wrapper crate exposes idiomatic and safe Rust functionality.

Does this Rust FFI approach work with complex C libraries like OpenSSL?

Yes, this Rust FFI approach works with complex C libraries like OpenSSL or libcurl, streamlining the integration of external C functionalities into Rust projects with robust build and dependency handling.