dart-use-ffigen
БесплатноБез исполняемых скриптовНе проверен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…
от flutter★ 3 224 звезды на GitHubОб этом скилле
Generating FFI Bindings using package:ffigen
Contents
- Introduction
- Constraints
- FFIgen Overview
- Step-by-Step Workflow
- Concrete Example: Binding a C Library
- 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 (
.hfiles) exist or are generated by a build step, never write manualDynamicLibrary.lookup,@Nativeexternal functions, or raw struct classes. Always useFfiGeneratorto generate them. - Generator Location: The generator script should be located at
tool/ffigen.dartwithin 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 asrc/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 the size and cognitive load of the generated code (e.g., using
Functions.includeSetor filtering matches inincludeclosures). - Output Setup: If the generated FFI bindings interface with a third-party library (or reference third-party headers), the generated files must always be placed under
lib/src/third_party/. The primary generated FFI bindings file must strictly use the.g.dartextension (e.g.sqlite3.g.dart). - Preamble & License Headers: Always supply a premium
preamblein theOutputclass to specify the license. This must match the native third-party library's license, explicitly include the copyright header of the target native header file, and contain an automatic generation warning (e.g.// Generated by package:ffigen. Do not edit manually.). - No Unnecessary Commits of Stale Bindings: Ensure you run the generator script and check if the generated files have changed before finishing your task. Always verify the package by running
dart analyze. - Record Usage and Tree Shaking: If the package is integrated into standard runtime execution or compiles native assets via native hooks:
- Enable recorded usage on all functions by setting
recordUse: (_) => trueunderFunctions. - Specify the
recordUseMappingtarget inOutput(which must strictly be a.g.dartfile underlib/src/third_party/, e.g.lib/src/third_party/sqlite3.record_use_mapping.g.dart) to register bindings for symbol tree shaking.
- Enable recorded usage on all functions by setting
FFIgen Overview
To construct the programmatic generator, use the core configuration objects imported from package:ffigen/ffigen.dart:
1. FfiGenerator
The parent class that orchestrates the configuration, parsing, and code generation.
FfiGenerator({
Headers headers = const Headers(),
Enums enums = Enums.excludeAll,
Functions functions = Functions.excludeAll,
Globals globals = Globals.excludeAll,
Integers integers = const Integers(),
Macros macros = Macros.excludeAll,
Structs structs = Structs.excludeAll,
Typedefs typedefs = Typedefs.excludeAll,
Unions unions = Unions.excludeAll,
UnnamedEnums unnamedEnums = UnnamedEnums.excludeAll,
ObjectiveC? objectiveC,
required Output output,
}).generate();
2. Headers
Configures Clang header parsing targets and compiler flags.
entryPoints: A list of target headerUriinputs.include: A filter functionbool Function(Uri header)that handles transitive header imports.compilerOptions: Custom preprocessor/include compiler flags to pass directly to libclang.ignoreSourceErrors: Set totrueto silence errors occurring inside third-party headers during parsing.
3. Functions
Specifies which native C/C++ functions to expose in Dart.
include: A matcher function (e.g.(decl) => {'my_func'}.contains(decl.originalName)orFunctions.includeSet({'my_func'})).isLeaf: Declares functions as leaf functions ((decl) => true) if they do not call back into Dart or block thread execution.recordUse: Enables metadata generation for native asset tree shaking (essential indart-lang/native). Set to(_) => true.
4. Output
Configures target generated files.
dartFile: TargetUriwhere the primary FFI bindings will be written.recordUseMapping: TargetUrifor recorded usage metadata maps (crucial for linking-time tree shaking).preamble: Text inserted at the top of the generated file (licensing, annotations).format:
Установить dart-use-ffigen в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл dart-use-ffigen?
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.
Как установить скилл dart-use-ffigen?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл dart-use-ffigen запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
doc-coauthoring
Guide users through a structured workflow for co-authoring documentation. Use when user wants to write documentation, proposals, technical specs, decision…
от Anthropicacademy-guide
Stop and check this skill before finishing any reply to a question about how to use Claude or a Claude product — it recommends matching courses, tutorials…
от Anthropicinternal-comms
A set of resources to help me write all kinds of internal communications, using the formats that my company likes to use. Claude should use this skill…
от Anthropicskill-development
This skill should be used when the user wants to "create a skill", "add a skill to plugin", "write a new skill", "improve skill description", "organize skill…
от Anthropic