ffigen
23.0.0, released 6 weeks ago by tools.dart.dev
Generator for FFI bindings, using LibClang to parse C, Objective-C, and Swift files.
What it does
FFIgen parses C, Objective-C, and Swift header files using LibClang to generate Dart FFI binding boilerplate. It automates calling native code from Dart via a programmatic generator API.
AI-written summary of version 23.0.0, based on the package's README and metadata. Report an inaccuracy
Use it when
- You need to call C or Objective-C native libraries from Dart.
- You want to avoid manually writing Dart FFI bindings for large native headers.
Skip it when
- You are writing a pure Dart app with no native interop requirements.
- You only need simple bindings that are faster to write by hand.
Strengths
- Automates generating complex Dart FFI bindings from native headers.
- Supports C, Objective-C, and experimental C++ features.
Weaknesses
- Requires LLVM and LibClang installed on the host system to run.
- YAML configuration format is deprecated in favor of the programmatic Dart API.
Setup
- Kind
- FFI (native library)
- Effort
- High
- Code generation
- No
- Direct dependencies
- 18
Requires LLVM / libclang installed on your operating system (e.g., libclang-dev on Linux, LLVM on Windows via winget/installer, or Xcode command line tools on macOS).
import 'package:ffigen/ffigen.dart';
import 'dart:io';
Future<void> main() async {
final packageRoot = Platform.script.resolve('../');
final generator = FfiGenerator(
output: Output(dart: DartOutput(path: packageRoot.resolve('lib/add.g.dart'))),
input: Input(entryPoints: [packageRoot.resolve('src/add.h')]),
);
await generator.generate();
}Alternatives
Packages that do the same job and could replace ffigen.
- objective_c
Support library for accessing Objective C via ffigen in Flutter
90Compare - flutter_rust_bridge
Flutter/Dart and Rust binding generator
92Compare - pigeon
Type-safe code generator for communication between Flutter and host platforms.
90Compare - build
Package for authoring build_runner compatible code generators.
87Compare
Works with
Packages commonly used together with ffigen: ones it builds on, ones built on it, and its own family.
- yamlffigen depends on itA Dart library for parsing YAML documents into Dart data structures.
- pub_semverffigen depends on itVersions and version constraints implementing pub's versioning policy.
- globffigen depends on itA file and directory globbing library that supports Bash-style path matching and listing.
- package_configffigen depends on itRead and write Dart package configuration files.
- dart_styleffigen depends on itProvides an API and CLI to format Dart source code automatically.
- hooksffigen depends on itDart API for the JSON-based protocol for package build and link hooks.
- code_assetsffigen depends on itProvides the hook protocol specification for bundling native code with Dart packages.
- ffiffigen depends on itUtilities for working with Foreign Function Interface (FFI) code in Dart.