package:ffigen simplifies the process of generating dart:ffi bindings from C and Objective-C header files. It is simple to use, configured via a Dart script (FfiGenerator). It requires LLVM (18+) to work. This document tries to give a complete overview of every component without going into too many details about every single class/file.
package:ffigen binds to LibClang using dart:ffi for parsing C header files.
The script for generating bindings is tool/generate_clang_bindings.dart. The bindings are generated to lib/src/header_parser/clang_bindings/clang_bindings.dart. These are used by Header Parser for calling libclang functions.
FFIgen is typically run via a Dart script such as tool/ffigen.dart using dart run tool/ffigen.dart.
FfiGenerator object specifying Input, Output, and Visitors.FfiGenerator.generate() parses the headers, runs AST visitors, and generates the Dart bindings.The Config Provider holds all the configurations required by other modules.
The Header Parser parses C and Objective-C header files and converts them into AST nodes and a Library object.
Library object.The Code Generator generates the actual string bindings.
Binding.