← ClaudeAtlas

dart-use-ffigenlisted

Guide agents to use `package:ffigen` to automatically generate FFI bindings instead of writing them manually. Use this skill when a task involves writing new FFI bindings, extending C/Objective-C/Swift integrations, or replacing hand-crafted `dart:ffi` setups.
novahiz/novahiz · ★ 1 · AI & Automation · score 70
Install: claude install-skill novahiz/novahiz
# Generating FFI Bindings using package:ffigen ## Contents - [Introduction](#introduction) - [Constraints](#constraints) - [FFIgen Overview](#ffigen-overview) - [Step-by-Step Workflow](#step-by-step-workflow) - [Concrete Example: Binding a C Library](#concrete-example-binding-a-c-library) - [Verification Checklist](#verification-checklist) ## Introduction Automate and standardize the generation of FFI bindings using `package:ffigen` (`FfiGenerator`). Writing FFI bindings by hand is error-prone, brittle, and highly discouraged. ## Constraints * **No Hand-Written FFI Bindings**: If native headers (`.h` files) exist or are generated by a build step, never write manual `DynamicLibrary.lookup`, `@Native` external functions, or raw struct classes. Always use `FfiGenerator` to generate them. * **Generator Location**: The generator script should be located at `tool/ffigen.dart` within the target package root. * **Header Location**: If the native header files are third-party, they should be located in `third_party/` within the target package (otherwise placing them in a `src/` directory at the package root is also acceptable). If the headers are not in one of these standard locations, notify the user that it would be cleaner to move the header files to the standard location (e.g., `third_party/`). * **Targeted Inclusion Filters**: Avoid importing an entire native library unless specifically needed. Always apply precise inclusion lists using positive matches to minimize th