ffi-code-review
БесплатноБез исполняемых скриптовНе проверенReviews Rust FFI code for type safety, memory layout compatibility, string handling, callback patterns, and unsafe boundary correctness. Use when reviewing…
от existential-birds★ 92 звезды на GitHubОб этом скилле
FFI Code Review
Review Workflow
- Check Cargo.toml -- Note Rust edition (2024 has breaking changes to extern blocks and unsafe attributes),
build-dependencies(bindgen, cc, pkg-config),crate-type(cdylib,staticlib), andlinkskey - Check build.rs -- Verify link directives (
cargo:rustc-link-lib,cargo:rustc-link-search), bindgen configuration, and C source compilation - Check extern blocks -- Verify calling conventions, symbol declarations, and safety annotations
- Check type layout -- Every type crossing FFI must be
#[repr(C)]or a primitive FFI type - Check string and pointer handling -- CStr/CString usage, null checks, ownership transfers
- Check callbacks --
extern "C" fnpointers, panic safety across FFI boundary - Gates -- Complete Gates below before reporting; do not skip ahead on “internal verification”
Gates
Complete in order. Do not emit findings until Gate 4 passes for each issue.
Gate 1 — Crate context (on disk)
PASS when: You opened the reviewed crate’s Cargo.toml (workspace member path if applicable) and recorded edition =, plus any of links, crate-type, or build-dependencies that matter for this FFI.
Blocks rationalization: Edition-specific findings (unsafe extern "C" {}, #[unsafe(no_mangle)], etc.) require this — if edition is not 2024, do not flag 2024-only requirements.
Gate 2 — Linkage and binding sources
PASS when: If the crate links native code or uses bindgen/pkg-config, you opened build.rs (or the checked-in bindings entry point). If there is no build.rs, you stated that bindings are hand-written and reviewed those extern / include! sites.
Artifact: At least one path you opened (e.g. build.rs, src/ffi.rs, or OUT_DIR bindings via include!).
Gate 3 — Code evidence
PASS when: Every planned finding has a target [FILE:LINE] from a full function/block you read, not only diff hunks or partial snippets.
Gate 4 — Pre-report protocol
PASS when: You applied the FFI-Specific Verification checks below (for repr(C), safety comments, ownership/callbacks, or bindgen-heavy code) and the general verification workflow in the review-verification-protocol skill.
FFI-Specific Verification
"Missing repr(C)"
Before flagging, you MUST:
- Confirm the type actually crosses the FFI boundary (passed to/from C code)
- Check if the type is only used on the Rust side of the FFI wrapper
- Verify there isn't a
#[repr(transparent)]wrapper instead
Common false positives:
- Internal Rust types that are converted before FFI call — only the FFI-facing type needs
repr(C) - Types used with
repr(transparent)newtype wrappers — the wrapper handles layout - Opaque pointer types (
*mut c_voidor zero-sized opaque structs) — no internal layout guarantee needed
"FFI Safety"
Before flagging, you MUST:
- Check if the unsafe FFI call has a
// SAFETY:comment documenting invariants - Verify ownership transfer is actually ambiguous (check for
Box::into_raw/Box::from_rawpairs) - Confirm
CStringlifetime issues are real (theCStringmust outlive the pointer passed to C) - Check if callback unwinding is actually possible (pure data functions can't panic across FFI)
Common false positives:
extern "C" fncallbacks that never panic —catch_unwindnot needed*const c_charfromCStr::as_ptr()held within the same scope — lifetime is fine- Bindgen-generated code with
unsafe— bindgen output is inherently unsafe-heavy by design
Output Format
Report findings as:
[FILE:LINE] ISSUE_TITLE
Severity: Critical | Major | Minor | Informational
Description of the issue and why it matters.
Quick Reference
| Issue Type | Reference |
|---|---|
| C-to-Rust type mapping, repr(C) layout, enums, opaque types | references/type-mapping.md |
| Safe wrappers, ownership transfer, callbacks, build.rs, testing | references/safety-patterns.md |
Review Checklist
extern Blocks and Calling Conventions
- Foreign function declarations use
extern "C"(explicit, not bareextern) - Edition 2024:
extern "C" {}blocks written asunsafe extern "C" {} - Functions exposed to C use
extern "C" fn(not default Rust calling convention) - Calling convention matches the foreign library (
"C","system"for Win32 API) -
#[link(name = "...")]specifies the correct library name -
#[link(name = "...", kind = "static")]used when statically linking
Symbol Management
- Exported functions use
#[no_mangle]to preserve symbol names - Edition 2024:
#[no_mangle]written as#[unsafe(no_mangle)] - Edition 2024:
#[export_name = "..."]written as#[unsafe(export_name = "...")] -
#[link_name = "..."]used when Rust name dif
Установить ffi-code-review в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл ffi-code-review?
Reviews Rust FFI code for type safety, memory layout compatibility, string handling, callback patterns, and unsafe boundary correctness. Use when reviewing extern blocks, #[repr(C)] types, bindgen output, or code calling C/C++ libraries.
Как установить скилл ffi-code-review?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл ffi-code-review запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
mcp-builder
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
от Anthropicclaude-api
Reference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
от Anthropicalgorithmic-art
Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
от Anthropicmcp-integration
This skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…
от Anthropic