dart-setup-ffi-assets
БесплатноБез исполняемых скриптовНе проверенGuides agents in compiling and packaging C/C++ source code into dynamic or static libraries (Code Assets) using Dart's Native Assets hook system (via…
от flutter★ 3 224 звезды на GitHubОб этом скилле
Compiling C Code into Code Assets with Native Assets Hooks
Integrate and automate the compilation and packaging of native C/C++ source code into Code Assets under Dart's overarching Native Assets feature using build and link hooks.
Contents
- Introduction
- Constraints
- Native Interop Packages
- Step-by-Step Workflow
- Choosing an Integration Approach
- Method 1: Local Compilation with Linker Tree-Shaking (Recommended)
- Method 2: Downloading Precompiled Dynamic Libraries
- Verification Checklist
Introduction
Under Dart's Native Assets feature, packages can package native code (like C/C++ libraries) as Code Assets and bundle them automatically during standard development cycles (e.g., dart run, dart test, dart build, and flutter run). The packaging of Code Assets is driven by two programmatic hook scripts placed inside a package's hook/ folder:
hook/build.dart: Compiles local C sources to machine code or bundles prebuilt native binaries as code assets for a specific host/target architecture.hook/link.dart: Links built code assets, applying advanced tree-shaking optimizations to strip unused native symbols and compress the runtime binary size.
Constraints
[!IMPORTANT] Keep all file resolving platform-independent. Never hardcode absolute target paths, shell scripts, or system command variables. Always use
Platform.script.resolve()orUri-based resolution to ensure scripts are fully portable.
- Hook Locations: Compiling and packaging hooks must reside strictly inside the
hook/directory at the package's root:hook/build.dart(Build execution phase)hook/link.dart(Optional packaging/linking/tree-shaking phase)
- Compile Toolchain Standard: Use the programmatic APIs from
package:native_toolchain_c(e.g.CBuilderandCLibrary) to run compile toolchains. Never invoke rawgcc,clang, ormsvcvia shell commands. - Preamble & License Headers: Every handcrafted and generated source file (including bindings, helpers, and hooks) must strictly contain the target package's copyright and licensing header.
- Tree Shaking Mapping: If utilizing compiler tree-shaking, you must map the target Dart method names (e.g.
Method.name) back to their raw native C symbol names using a record use mapping generated by FFIgen. The mapping file must reside underlib/src/third_party/and strictly use the.g.dartextension (e.g.,sqlite3.record_use_mapping.g.dart). - Integrity Safeguards for Precompiled Libraries: If adopting the dynamic download pattern:
- Cryptographic Verification: Downloaded prebuilt binaries must be checked against preconfigured lookup tables containing MD5 or SHA-256 hashes to guarantee binary integrity and prevent tampering.
- Graceful Recovery: Support offline developers by providing fallbacks (such as local compiler execution via flags like
local_build).
Native Interop Packages
Programmatic build and link hooks for Code Assets leverage three specialized native interop packages:
| Dependency | Purpose | Key API Abstractions |
|---|---|---|
package:hooks |
Main orchestrator defining execution bounds. | build(args, callback), link(args, callback) |
package:native_toolchain_c |
Detects local compilers (MSVC, Xcode/Clang, GCC) and executes build toolchains. | CLibrary, CBuilder, LinkerOptions.treeshake |
package:code_assets |
Models code metadata records passed to dynamic loaders. | CodeAsset, DynamicLoadingBundled |
Step-by-Step Workflow
Step 1: Add Dependencies
Add Code Assets hook and toolchain dependencies to your package. You must fetch these dependencies directly from pub.dev.
You can add it automatically using the CLI:
dart pub add code_assets hooks native_toolchain_c record_use dev:ffigen
Or
Установить dart-setup-ffi-assets в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл dart-setup-ffi-assets?
Guides agents in compiling and packaging C/C++ source code into dynamic or static libraries (Code Assets) using Dart's Native Assets hook system (via hook/build.dart and hook/link.dart utilizing package:hooks and package:native_toolchain_c). Use when a user asks to: 'setup native assets', 'compile C/C++ source code', 'bundle dynamic libraries', 'build native C code', 'link native assets', 'implement build.dart or link.dart hooks', or 'integrate C/C++ interop in Dart/Flutter'. Helps agents avoid manual toolchain orchestration and configures secure hash-validated binary downloads or advanced linker tree-shaking with package:record_use mapping.
Как установить скилл dart-setup-ffi-assets?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл dart-setup-ffi-assets запускает скрипты?
Нет, скилл состоит только из инструкций (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