### Implement C Source Source: https://pub.dev/packages/ffigen The source file provides the implementation for the functions declared in the header. ```c // in src/add.c: int add(int a, int b) { return a + b; } ``` -------------------------------- ### Enable FFigen Native Support Source: https://pub.dev/packages/ffigen Use the `ffi-native` option to generate `@Native` bindings. This is an experimental feature and the API may change. ```yaml ffi-native: asset-id: 'package:some_pkg/asset' # Optional, was assetId in previous versions ``` -------------------------------- ### Set file preamble Source: https://pub.dev/packages/ffigen Defines a raw header to be prepended to the generated file. ```yaml preamble: | // ignore_for_file: camel_case_types, non_constant_identifier_names ``` -------------------------------- ### Define Header Entry Points and Include Directives Source: https://pub.dev/packages/ffigen Specifies the header files that FFIgen should process. 'entry-points' are the primary headers, and 'include-directives' are additional headers to be included. Glob syntax is supported. ```yaml headers: entry-points: - 'folder/**.h' - 'folder/specific_header.h' include-directives: - '**index.h' - '**/clang-c/**' - '/full/path/to/a/header.h' ``` -------------------------------- ### Output Configuration Source: https://pub.dev/packages/ffigen Configure the output paths for generated bindings, including Objective-C bindings and symbol files. ```APIDOC ## Output Configuration Configure where generated code and symbol files are placed. ### Objective-C Bindings: Choose where the generated ObjC code (if any) is placed. The default path is `'${output.bindings}.m'`. ```yaml output: objc-bindings: 'generated_bindings.m' ``` This ObjC file will only be generated if it's needed. If it is generated, it must be compiled into your package. ### Symbol File: Generates a symbol file yaml containing all types defined in the generated output. ```yaml output: symbol-file: output: 'package:some_pkg/symbols.yaml' import-path: 'package:some_pkg/base.dart' ``` **Note:** Although file paths are supported for `output`, prefer Package URIs for `output` and `import-path` so that other packages can use them. ``` -------------------------------- ### FFI Native Bindings Source: https://pub.dev/packages/ffigen Configure the generation of native bindings using `@Native`. This is an experimental feature and the API may change. ```APIDOC ## FFI Native Bindings Generate `@Native` bindings instead of using `DynamicLibrary` or `lookup`. ### Configuration: ```yaml ffi-native: asset-id: 'package:some_pkg/asset' # Optional, was assetId in previous versions ``` **Note:** Native support is EXPERIMENTAL. The API may change in a breaking way without notice. ``` -------------------------------- ### Configure LLVM Path for Clang Source: https://pub.dev/packages/ffigen Specifies the paths to the LLVM folder, which is necessary for FFIgen to locate the Clang library. FFIgen searches sequentially in the provided paths. This is required if Clang cannot be found in default locations. ```yaml llvm-path: - '/usr/local/opt/llvm' - 'C:\\Program Files\\llvm` - '/usr/lib/llvm-11' # Specify exact path to dylib - '/usr/lib64/libclang.so' ``` -------------------------------- ### Generate Symbol File in FFigen Source: https://pub.dev/packages/ffigen Configure FFigen to generate a symbol file containing all defined types. Prefer Package URIs for the output path to allow other packages to use it. An `import-path` can also be specified. ```yaml output: ... symbol-file: # Although file paths are supported here, prefer Package Uri's here # so that other pacakges can use them. output: 'package:some_pkg/symbols.yaml' import-path: 'package:some_pkg/base.dart' ``` -------------------------------- ### Configure Objective-C Bindings Output Source: https://pub.dev/packages/ffigen Specify the output path for generated Objective-C code. The default path is `${output.bindings}.m`. This file is only generated if needed and must be compiled into your package. ```yaml output: ... objc-bindings: 'generated_bindings.m' ``` -------------------------------- ### Specify Input Language for FFigen Source: https://pub.dev/packages/ffigen Choose the input language for FFigen. Supported options are 'c' (default) and 'objc'. This is an experimental feature and the API may change. ```yaml language: 'objc' ``` -------------------------------- ### Add module prefixes for Swift-wrapped Objective-C libraries Source: https://pub.dev/packages/ffigen Use module prefixes when loading interfaces or protocols from dylibs that are generated wrappers for Swift libraries. ```yaml headers: entry-points: # Generated by swiftc to wrap foo_lib.swift. - 'foo_lib-Swift.h' objc-interfaces: include: # Eg, foo_lib contains a set of classes prefixed with FL. - 'FL.*' module: # Use 'foo_lib' as the module name for all the FL.* classes. # We don't match .* here because other classes like NSString # shouldn't be given a module prefix. 'FL.*': 'foo_lib' ``` -------------------------------- ### Configure Automatic C Standard Library Inclusion on macOS Source: https://pub.dev/packages/ffigen Controls whether FFIgen should attempt to automatically find and include the C standard library path in compiler options on macOS. Defaults to true. ```yaml compiler-opts-automatic: macos: include-c-standard-library: false ``` -------------------------------- ### Provide Dart Doc Description for Generated Class Source: https://pub.dev/packages/ffigen Adds a Dart documentation comment to the generated binding class, explaining its purpose. This is a preferred option for documentation. ```yaml description: 'Bindings to SQLite' ``` -------------------------------- ### Configure variadic arguments Source: https://pub.dev/packages/ffigen Defines function signatures for variadic arguments, supporting native C types, common typedefs, and custom structs. ```yaml functions: variadic-arguments: myfunc: // Native C types are supported - [int, unsigned char, long*, float**] // Common C typedefs (stddef.h) are supported too - [uint8_t, intptr_t, size_t, wchar_t*] // Structs/Unions/Typedefs from generated code or a library import can be referred too. - [MyStruct*, my_custom_lib.CustomUnion] ``` -------------------------------- ### Specify Output Path for Generated Bindings Source: https://pub.dev/packages/ffigen Defines the location where the generated Dart bindings file will be saved. This is a required configuration option. ```yaml output: 'generated_bindings.dart' ``` ```yaml output: bindings: 'generated_bindings.dart' ... ``` -------------------------------- ### Import Symbol Files Source: https://pub.dev/packages/ffigen Import symbols from a symbol file, which is useful for sharing type definitions between packages. ```APIDOC ## Import Symbol Files Import symbols from a symbol file. Used for sharing type definitions from other packages. ### Configuration: ```yaml import: symbol-files: - 'package:some_pkg/symbols.yaml' - 'path/to/some/symbol_file.yaml' ``` Both package URIs and file paths are supported here. ``` -------------------------------- ### Call Generated FFI Bindings Source: https://pub.dev/packages/ffigen Import the generated Dart file to invoke the native C functions. ```dart import 'add.g.dart'; // ... void answerToLife() { print('The answer to the Ultimate Question is ${add(40, 2)}!'); } ``` -------------------------------- ### Enable full code generation for transitive dependencies Source: https://pub.dev/packages/ffigen Set these flags to true to fully generate bindings for interfaces and protocols that are transitively depended upon, rather than generating stubs or omitting them. ```yaml include-transitive-objc-interfaces: true include-transitive-objc-protocols: true ``` -------------------------------- ### Configure FfiGenerator Source: https://pub.dev/packages/ffigen A Dart script used to configure and run the FfiGenerator to produce bindings. ```dart import 'dart:io'; import 'package:ffigen/ffigen.dart'; void main() { final packageRoot = Platform.script.resolve('../'); FfiGenerator( // Required. Output path for the generated bindings. output: Output(dartFile: packageRoot.resolve('lib/add.g.dart')), // Optional. Where to look for header files. headers: Headers(entryPoints: [packageRoot.resolve('src/add.h')]), // Optional. What functions to generate bindings for. functions: Functions.includeSet({'add'}), ).generate(); } ``` -------------------------------- ### Configure Objective-C interface, protocol, and category filters Source: https://pub.dev/packages/ffigen Use these filters to include, exclude, or rename specific Objective-C declarations in the generated bindings. ```yaml objc-interfaces: include: # Includes a specific interface. - 'MyInterface' # Includes all interfaces starting with "NS". - 'NS.*' exclude: # Override the above NS.* inclusion, to exclude NSURL. - 'NSURL' rename: # Removes '_' prefix from interface names. '_(.*)': '$1' objc-protocols: include: # Generates bindings for a specific protocol. - MyProtocol objc-categories: include: # Generates bindings for a specific category. - MyCategory ``` -------------------------------- ### Import Symbols from Symbol Files Source: https://pub.dev/packages/ffigen Import type definitions from symbol files of other packages. Both package URIs and file paths are supported for specifying the symbol files. ```yaml import: symbol-files: # Both package Uri and file paths are supported here. - 'package:some_pkg/symbols.yaml' - 'path/to/some/symbol_file.yaml' ``` -------------------------------- ### Pass Compiler Options to Clang Source: https://pub.dev/packages/ffigen Allows specifying compiler flags to be passed to Clang during the binding generation process. These options can also be provided via the command line. ```yaml compiler-opts: - '-I/usr/lib/llvm-9/include/' ``` ```bash dart run ffigen --compiler-opts "-I/headers -L 'path/to/folder name/file'" ``` -------------------------------- ### Sort bindings Source: https://pub.dev/packages/ffigen Enables sorting of generated bindings by name. ```yaml sort: true ``` -------------------------------- ### Use Dart handle Source: https://pub.dev/packages/ffigen Enables mapping of Dart_Handle to the Handle type. ```yaml use-dart-handle: true ``` -------------------------------- ### Use supported typedefs Source: https://pub.dev/packages/ffigen Enables automatic mapping of standard C typedefs to Dart FFI types. ```yaml use-supported-typedefs: true ``` -------------------------------- ### Language Selection Source: https://pub.dev/packages/ffigen Specify the input language for code generation. Supported languages are 'c' and 'objc'. ```APIDOC ## Language Selection Choose the input language. Must be one of 'c', or 'objc'. Defaults to 'c'. ### Configuration: ```yaml language: 'objc' ``` **Note:** Other language support is EXPERIMENTAL. The API may change in a breaking way without notice. ``` -------------------------------- ### Expose function typedefs Source: https://pub.dev/packages/ffigen Configures which functions should have their Native and Dart type typedefs generated. ```yaml functions: expose-typedefs: include: # Match function name. - 'myFunc' # Do this to expose types for all function. - '.*' exclude: # If you only use exclude, then everything # not excluded is generated. - 'dispose' ``` -------------------------------- ### Ignore source errors Source: https://pub.dev/packages/ffigen Configures whether to ignore compiler warnings or errors found in source header files. ```yaml ignore-source-errors: true ``` ```bash dart run ffigen --ignore-source-errors ``` -------------------------------- ### External Versions Source: https://pub.dev/packages/ffigen Filter generated bindings based on platform version. APIs deprecated before the minimum specified version for a platform will be omitted. ```APIDOC ## External Versions Filter generated bindings based on platform version. APIs deprecated before the minimum specified version for a platform will be omitted. ### Configuration: ```yaml external-versions: ios: min: 12.0.0 macos: min: 10.14.0 ``` Current supported OS keys are `ios` and `macos`. If you have a use case for version checking on other OSs, please file an issue. The API's inclusion will be based on the platforms that have a specified minimum version. ``` -------------------------------- ### Define Build Hook Source: https://pub.dev/packages/ffigen A build hook script to compile C sources into native assets for the Dart application. ```dart import 'package:code_assets/code_assets.dart'; import 'package:hooks/hooks.dart'; import 'package:native_toolchain_c/native_toolchain_c.dart'; void main(List args) async { await build(args, (input, output) async { if (input.config.buildCodeAssets) { final builder = CBuilder.library( name: 'add', assetName: 'add.g.dart', sources: ['src/add.c'], ); await builder.run(input: input, output: output); } }); } ``` -------------------------------- ### Define C Header Source: https://pub.dev/packages/ffigen The header file defines the C API interface to be exposed to Dart. ```c // in src/add.h: int add(int a, int b); ``` -------------------------------- ### Configure External Versioning for Deprecated APIs Source: https://pub.dev/packages/ffigen Omit APIs deprecated as of the minimum specified platform version from generated bindings. APIs are generated if available on any targeted platform version. Currently supports 'ios' and 'macos'. ```yaml external-versions: # See https://docs.flutter.dev/reference/supported-platforms. ios: min: 12.0.0 macos: min: 10.14.0 ``` -------------------------------- ### Define library imports Source: https://pub.dev/packages/ffigen Specifies external library imports for use within type mappings. ```yaml library-imports: custom_lib: 'package:some_pkg/some_file.dart' ``` -------------------------------- ### Set leaf functions Source: https://pub.dev/packages/ffigen Configures functions to be marked as leaf, which can improve performance for short-running native calls. ```yaml functions: leaf: include: # Match function name. - 'myFunc' # Do this to set isLeaf:true for all functions. - '.*' exclude: # If you only use exclude, then everything # not excluded is generated. - 'dispose' ``` -------------------------------- ### Configure dependency-only generation Source: https://pub.dev/packages/ffigen Sets generation behavior for structs and unions that are only dependencies and not explicitly included. ```yaml structs: dependency-only: opaque unions: dependency-only: opaque ``` -------------------------------- ### Filter members of Objective-C interfaces, protocols, and categories Source: https://pub.dev/packages/ffigen Define specific inclusion or exclusion rules for methods and properties within interfaces, protocols, or categories using regex patterns. ```yaml objc-interfaces: member-filter: MyInterface: include: - "someMethod:withArg:" # Since MyInterface has an include rule, all other methods # are excluded by default. objc-protocols: member-filter: NS.*: # Matches all protocols starting with NS. exclude: - copy.* # Remove all copy methods from these protocols. objc-categories: member-filter: MyCategory: include: - init.* # Include all init methods. ``` -------------------------------- ### Exclude all by default Source: https://pub.dev/packages/ffigen Changes the default behavior to exclude all declarations unless explicitly included. ```yaml exclude-all-by-default: true ``` -------------------------------- ### Filter and Rename C Declarations (Functions, Structs, Enums, Globals) Source: https://pub.dev/packages/ffigen Provides options to include, exclude, and rename C functions, structs, unions, enums, and globals. It also allows renaming members of structs and enums, and exposing symbol addresses for functions and globals. ```yaml functions: include: # 'exclude' is also available. # Matches using regexp. - '[a-z][a-zA-Z0-9]*' # '.' matches any character. - 'prefix.*' # Matches with exact name - 'someFuncName' # Full names have higher priority. - 'anotherName' rename: # Regexp groups based replacement. 'clang_(.*)': '$1' 'clang_dispose': 'dispose' # Removes '_' from beginning. '_(.*)': '$1' symbol-address: # Used to expose symbol address. include: - 'myFunc' structs: rename: # Removes prefix underscores # from all structures. '_(.*)': '$1' member-rename: '.*': # Matches any struct. # Removes prefix underscores # from members. '_(.*)': '$1' enums: rename: # Regexp groups based replacement. 'CXType_(.*)': '$1' member-rename: '(.*)': # Matches any enum. # Removes '_' from beginning # enum member name. '_(.*)': '$1' # Full names have higher priority. 'CXTypeKind': # $1 keeps only the 1st # group i.e only '(.*)'. 'CXType(.*)': '$1' as-int: # These enums will be generated as Dart integers instead of Dart enums include: - 'MyIntegerEnum' globals: exclude: - 'aGlobal' rename: # Removes '_' from # beginning of a name. '_(.*)': '$1' ``` -------------------------------- ### Configure comment extraction Source: https://pub.dev/packages/ffigen Specifies the style and length of documentation comments to extract from source declarations. ```yaml comments: style: any length: full ``` -------------------------------- ### Map types Source: https://pub.dev/packages/ffigen Maps specific native types, typedefs, structs, or unions to custom types. ```yaml type-map: 'native-types': # Targets native types. 'char': 'lib': 'pkg_ffi' # predefined import. 'c-type': 'Char' ``` -------------------------------- ### Configure Native Types in FFigen Source: https://pub.dev/packages/ffigen Specify native types for Dart bindings. Use 'int', 'double', or 'float' for standard types, or define custom 'dart-type' mappings for specific C types. ```yaml 'dart-type': 'int' 'int': 'lib': 'custom_lib' 'c-type': 'CustomType4' 'dart-type': 'int' 'typedefs': # Targets typedefs. 'my_type1': 'lib': 'custom_lib' 'c-type': 'CustomType' 'dart-type': 'CustomType' 'structs': # Targets structs. 'my_type2': 'lib': 'custom_lib' 'c-type': 'CustomType2' 'dart-type': 'CustomType2' 'unions': # Targets unions. 'my_type3': 'lib': 'custom_lib' 'c-type': 'CustomType3' 'dart-type': 'CustomType3' ``` -------------------------------- ### Native Type Mappings Source: https://pub.dev/packages/ffigen Configure mappings between Dart types and C/Objective-C types for native bindings. This section shows how to define custom types for integers, typedefs, structs, and unions. ```APIDOC ## Native Type Mappings FFigen allows for custom type mappings to handle specific C types. ### Example Mappings: - **Integer Type**: Map a Dart integer type to a specific C type. ```yaml native-types: dart-type: 'int' int: lib: 'custom_lib' c-type: 'CustomType4' dart-type: 'int' ``` - **Typedefs**: Define custom Dart types for C typedefs. ```yaml typedefs: my_type1: lib: 'custom_lib' c-type: 'CustomType' dart-type: 'CustomType' ``` - **Structs**: Define custom Dart types for C structs. ```yaml structs: my_type2: lib: 'custom_lib' c-type: 'CustomType2' dart-type: 'CustomType2' ``` - **Unions**: Define custom Dart types for C unions. ```yaml unions: my_type3: lib: 'custom_lib' c-type: 'CustomType3' dart-type: 'CustomType3' ``` ``` -------------------------------- ### Set Name for Generated Binding Class Source: https://pub.dev/packages/ffigen Assigns a name to the generated Dart class that will encapsulate the FFI bindings. This is a preferred option for naming. ```yaml name: 'SQLite' ``` -------------------------------- ### Include Unused Typedefs Source: https://pub.dev/packages/ffigen A boolean flag to control whether typedefs that are not referred to anywhere in the C code should also be generated. Defaults to false. ```yaml include-unused-typedefs: true ``` -------------------------------- ### Silence enum warnings Source: https://pub.dev/packages/ffigen Silences warnings related to integer type mimicking for enums. ```yaml silence-enum-warning: true ``` -------------------------------- ### Filter and Rename Typedefs Source: https://pub.dev/packages/ffigen Allows filtering (including or excluding) and renaming of referred typedefs. By default, typedefs not referenced anywhere are not generated. ```yaml typedefs: exclude: # Typedefs starting with `p` are not generated. - 'p.*' rename: # Removes '_' from beginning of a typedef. '_(.*)': '$1' ``` -------------------------------- ### Disable automatic transitive category generation Source: https://pub.dev/packages/ffigen Set to false to prevent automatic inclusion of categories that extend included interfaces, allowing for manual filtering. ```yaml include-transitive-objc-categories: false ``` -------------------------------- ### Override struct packing Source: https://pub.dev/packages/ffigen Overrides the @Packed(X) annotation for generated structs using regex matching on generated names. ```yaml structs: pack: # Matches with the generated name. 'NoPackStruct': none # No packing '.*': 1 # Pack all structs with value 1 ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.