dart-setup-ffi-assets

Compiles and packages C/C++ source code into Dart Code Assets using Native Assets build and link hooks.

1|Updated Aug 14, 2026
One-click install
npx skills add https://github.com/sohampawar1866/zeromile-go --skill dart-setup-ffi-assets-sohampawar1866
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: dart-setup-ffi-assets
Source: https://github.com/sohampawar1866/zeromile-go/tree/main/.agents/skills/dart-setup-ffi-assets
Command: npx skills add https://github.com/sohampawar1866/zeromile-go --skill dart-setup-ffi-assets-sohampawar1866

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires code_assets, hooks, native_toolchain_c, record_use, ffigen, crypto.

What problem does it solve? Integrating native C/C++ libraries into Dart or Flutter packages normally requires manual toolchain orchestration, platform-specific build scripts, and fragile binary distribution. This Skill guides agents through Dart's Native Assets hook system so native code is compiled, linked, and bundled automatically during standard commands like dart run and dart test. ## Core Features & Use Cases - Local Compilation with Tree-Shaking: Implements hook/build.dart and hook/link.dart using package:hooks and package:native_toolchain_c to compile C sources with host toolchains (GCC, Clang, MSVC) and strip unused symbols via LinkerOptions.treeshake with FFIgen record-use mappings. - Precompiled Binary Downloads: Configures build hooks that download platform-specific dynamic libraries with MD5/SHA-256 hash verification and an offline local_build fallback flag. - Verification Workflow: Provides checklists for validating output binaries (.so, .dylib, .dll), confirming symbol stripping with nm or dumpbin, and testing offline compliance. - Use Case: A developer wrapping SQLite in a Dart package uses this Skill to generate the build hook that compiles sqlite3.c per target platform and the link hook that tree-shakes unused symbols, shrinking the shipped binary. ## Quick Start Set up Dart Native Assets hooks to compile my C source files in third_party/ into a bundled dynamic library with tree-shaking enabled.

Frequently Asked Questions about dart-setup-ffi-assets

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

FAQPage Schema
How do I compile C code in a Dart package with Native Assets?

Create a hook/build.dart script that calls build() from package:hooks and runs a CLibrary or CBuilder from package:native_toolchain_c against your C sources. The hook executes automatically during dart run, dart test, or flutter run, producing a platform-specific dynamic library.

How to tree-shake unused native symbols in Dart FFI libraries?

Implement hook/link.dart with LinkerOptions.treeshake, mapping recorded Dart method calls back to C symbol names via an FFIgen-generated record_use_mapping.g.dart file. The linker then strips unreferenced symbols, and you can verify exports with nm or dumpbin.

Should I compile C code locally or download precompiled binaries in Dart?

Local compilation gives maximum size optimization through tree-shaking but requires host toolchains like Xcode, GCC, or MSVC. Precompiled downloads need no compiler setup and run faster, but require network access and hash verification, with a local_build flag as offline fallback.

What C compilers are required for Dart Native Assets builds?

package:native_toolchain_c delegates to the host toolchain: Xcode Command Line Tools on macOS, GCC or Clang on Linux, and MSVC with the Desktop development with C++ workload on Windows. If no toolchain is found, the build hook throws a compilation exception.

How do I verify downloaded native libraries are safe in Dart hooks?

Store expected MD5 or SHA-256 hashes per platform file in a lookup table, then hash the downloaded binary with package:crypto and compare before registering it as a CodeAsset. A mismatch should throw an exception to prevent tampered binaries from being bundled.