[ffigen] Gemini's friction log

Open
#3,837 0 comments 0 reactions 1 assignee View on GitHub

Maintainers usually reply within 2 days

@liamappelbe is already working on this.

Since Dec 2, 2026.

Assessment

This issue has not been assessed yet.

Description

needs-triage package:ffigen

This is an AI generated summary of all the issues Gemini has run into while using FFIgen. I haven't fully reviewed the contents. I need to go through these in detail and triage them/file separate issues. I'm pasting it into an issue to make review easier for myself.

FFIgen Usage & Tooling Improvements

Executive Summary

A review of package:ffigen across consumer, migration, and maintenance workflows surfaced five dominant themes driving developer and coding-agent friction:

  1. Silent misconfigurations as the primary failure mode: FFIgen frequently exits with code 0 on broken configurations, including bare asset-id values that disagree with CBuilder.library, unknown YAML keys logged at [SEVERE], structs.exclude overridden by transitive dependencies, pre-rename vs post-rename filter mismatches, uncompilable Dart from mismatched structs/unions opacity, silent no-ops in Input(compilerOptions: null, appendCompilerOptions: true), and silent ABI corruption when appendCompilerOptions: false pairs with ignoreSourceErrors: true.
  2. Opaque Clang / libclang discovery and OS platform traps: Missing diagnostic logs for resolved libclang paths, versions, and -resource-dir values make silent Homebrew-vs-Xcode shadowing, outdated Linux/macOS search paths, cross-toolchain header mismatches, Clang 22/23 ElaboratedType AST changes, Linux xcrun/Objective-C crashes, and host <pthread.h> header leakage costly to diagnose.
  3. Build-hook coupling and packaging hazards: Test-only pkgs/ffigen/hook/build.dart leaked into published ffigen 23.0.0, couples native compilation into pure-Dart CLI and unit-test runs (breaking entirely when swiftly hijacks clang and adding 1.3s to 2.6s overhead), emits an invalid buildSwift iOS Simulator triple, produces opaque rebuild errors, and triggers chicken-and-egg .m crashes under dart run tool/ffigen.dart in greenfield consumer apps.
  4. Missing check mode and extreme log noise: FfiGenerator lacks a first-class dry-run / --set-exit-if-changed check mode, while internal header-path, hash, and CWD-formatting couplings break temp-dir diffing. Routine runs emit 110 to 898 lines of [WARNING]/[SEVERE] noise (including warnings on excluded Foundation declarations) that truncate real failures and push consumers to mute logs.
  5. API, generated-code, regeneration, and documentation drift: Remaining Visitor ergonomics gaps, symbol collisions (Declaration, Symbol, #2850 struct-field scoping), pure-ObjC @ffi.DefaultAsset lazy loading traps, dart analyze --fatal-infos failures on freshly generated bindings, fragmented monorepo regeneration entrypoints, workspace-excluded example/* drift, and stale docs (pkgs/ffigen/test/README.md, checkOsVersion, Func.exposeSymbolAddress, legacy YAML bias) repeatedly trip both humans and agents.

Suggested Improvements

P0: High-Blast-Radius Silent Failures, Toolchain Discovery & Build-Hook Isolation
  1. Validate asset-id / defaultAsset format against CBuilder.library conventions: Validate in config.dart and writer.dart that assetId / defaultAsset conforms to Dart's package: asset ID URI convention. Emit a prominent warning or error on bare paths (such as sample_c.dart), explicitly noting that CBuilder.library automatically prepends package:<package_name>/.
  2. Fail fast on unknown YAML keys and enforce filter, opacity, and compiler-option invariants: Exit non-zero on unknown YAML keys, warn when include/exclude rules match zero declarations (noting pre-rename matching) or when excluded structs are emitted via dependency-only: full, and fail or auto-opaque ffi.Union fields whose struct member is ffi.Opaque. Assert or warn on Input(compilerOptions: null, appendCompilerOptions: true) and on ignoreSourceErrors: true paired with missing system headers or appendCompilerOptions: false to prevent silent ABI corruption.
  3. Make libclang discovery transparent, modern, self-paired, and unified across pipelines: Log the resolved libclang path, clang_getClangVersion(), -resource-dir, and unsupported version warnings (> 22), while fixing macOsDylibLocations, enforcing same-toolchain -resource-dir pairing, and dynamically probing /usr/lib/llvm-*/lib/libclang.so* on Linux. Unify compiler-option resolution across YamlConfig, FfiGenerator, and macro_parser.dart, embed Clang diagnostics in HeaderParserException.message, and add Clang 22/23 ElaboratedType regression tests.
  4. Decouple test-only hook/build.dart from pkgs/ffigen CLI/tests/pub.dev and harden compiler/Swift hooks: Exclude hook/ in pkgs/ffigen/.pubignore and move native_test/cpp_test assets into a dedicated test helper package so pure-Dart CLI and unit tests never trigger native compilation. Verify compiler identity via --version (avoiding swiftly symlink hijacks) with full command/stdout/stderr on failure, fix buildSwift's iOS Simulator triple and tracked-header overwrites, and print offending file paths in rebuild errors.
P1: Check Mode, Log Hygiene, Platform Guards & Generated-Code Correctness
  1. Add first-class dry-run / up-to-date verification to FfiGenerator and honor --set-exit-if-changed: Add a built-in in-memory or check mode (FfiGenerator.check() or generate(dryRun: true)) and update all example tool/ffigen.dart entrypoints (including code_assets/example/host_name/tool/ffigen.dart) to honor --set-exit-if-changed. Decouple _libraryIdFromConfigHash from temporary filenames, expose headerPath on public Output, and format in memory using the logical target directory's pubspec.yaml and analysis_options.yaml context.
  2. Eliminate log noise and align diagnostics with severity, includeSet, and active API surface: Restrict cursor, inline-function, and enum warnings strictly to includeSet-matched or transitively referenced declarations, deduplicate identical cursor warnings, and downgrade non-fatal enum notices from SEVERE to WARNING/INFO. Emit Dart FfiGenerator property hints instead of YAML keys (such as silence-enum-warning: true) when invoked via the Dart API.
  3. Fail fast on non-macOS Objective-C invocation and guard against host system-header leakage: Fail fast with an actionable platform error when language: objc / ObjectiveC(...) runs on non-macOS hosts without macOS SDK headers instead of crashing in xcrun or exiting 79 silently. Add diagnostics or filtering when bindings pull in host-specific system-header types (such as <pthread.h>) that diverge between Linux and macOS.
  4. Fix generated-code correctness, analysis cleanliness, and pure-Objective-C dylib loading: Stop emitting unused _class_<Type> fields on instance-only Objective-C categories (or include unused_element in ignore_for_file), fix the unused $keepIsolateAlive parameter bug and naming inconsistency in generated addToBuilder* methods, and emit auto-generated header banners with FFIgen version metadata in .m files. Ensure pure-Objective-C @ffi.DefaultAsset libraries trigger dylib loading automatically before class lookups (or surface a clear diagnostic for FailedToLoadClassException).
P2: Public API Ergonomics, Monorepo Regeneration, Test Isolation & Verified Docs
  1. Eliminate symbol collisions and close remaining Visitor and Scope ergonomics gaps: Complete #2770 to retire legacy config_types.Declaration with zero dart:core (Symbol) or internal AST collisions, and land #2850 so struct fields do not collide with top-level symbols. Add Param.isUnnamed, synchronize property setter symbols on ObjCMethod.name = ... with updated tests, and document or align node.isIncluded = false child-traversal semantics with JNIgen.
  2. Unify monorepo binding regeneration, consolidate ObjC version constants, and rewrite pkgs/ffigen/test/README.md: Provide a single documented regeneration entrypoint or manifest covering all 8 monorepo scripts (eliminating or documenting the cross-package write to objc_built_in_types.dart) and unify objcMajorVersion/objcMinorVersion into one source of truth. Rewrite pkgs/ffigen/test/README.md to remove deleted regen.dart/setup.dart references and document unit tests, UPDATE=true golden runs, two-step C++/ObjC glue rebuilds, and @TestOn('mac-os') expectations.
  3. Fix pkgs/ffigen test isolation, CWD independence, and cross-platform example builds: Redirect all test-generated bindings (including format: false tests) into Directory.systemTemp with addTearDown cleanup and remove concurrent dart pub get calls from expectNoAnalysisErrors. Resolve script paths via Platform.script / Isolate.resolvePackageUri instead of Directory.current, and add Windows __declspec(dllexport) exports in pkgs/ffigen/example/add.
  4. Improve Dart Config / Objective-C documentation, generated API discoverability, and CI doc/example verification: Make FfiGenerator (with CBuilder.library + package:<pkg>/... defaultAsset) the primary README quick-start, consolidate v20-to-v23 and ObjC docs (including .blocking void-only semantics, dart tool/ffigen.dart build-hook ordering, and Func.exposeSymbolAddress examples plus @Native runtime tests), and emit a compact summary of renamed ObjC selectors. Gate ffigen.yml CI on dart doc --validate-links, doc snippet analysis, and dart pub get + dart analyze across pkgs/ffigen/example/*.
Dominant language
Dart
Stars
280
Forks
166
Avg merge
3d 4h
Merged PRs (30d)
33

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from dart-lang/native

All issues in dart-lang/native

Similar issues

More Dart issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.