Skip to content

[pigeon] Swift FFI (swift_use_ffi) generates code that doesn't compile for files with event channels or ProxyApis #193881

Closed
flutter/packages
#13153

Description

@tarrinneal

Found while investigating #193195.

Summary

Pigeon accepts Swift FFI mode for pigeon files that contain event channels or ProxyApis, but the Swift it generates doesn't compile. Users get a wall of Swift errors instead of a clear message at generation time.

Steps to reproduce

  1. Write a pigeon file with a @HostApi() and an @EventChannelApi(), or use pigeon's own pigeons/event_channel_tests.dart or pigeons/proxy_api_tests.dart.
  2. Generate Swift with FFI enabled (--swift_use_ffi, or SwiftOptions(useFfi: true)).
  3. Type-check the generated file against the SDK, the way swiftgen compiles it:
    xcrun swiftc -typecheck -sdk "$(xcrun --show-sdk-path --sdk macosx)" Generated.swift

Expected results

Either pigeon rejects the input with a clear error, or the generated Swift compiles.

Actual results

Pigeon writes the file without complaint, and it fails to type-check:

Input Result
Host API only Compiles
pigeons/native_interop_tests.dart Compiles
Host API + 1 event channel 56 errors; 34 are missing Flutter types (FlutterEventSink, FlutterStandardReader/Writer, FlutterError)
pigeons/event_channel_tests.dart 208 errors
pigeons/proxy_api_tests.dart 1,118 errors

Cause

  • In FFI mode the Swift generator skips import Flutter/import FlutterMacOS (swift_generator.dart L318).
  • It uses the FFI codec only when the file has no event channels and no ProxyApis. Otherwise it falls back to the channel codec, which is built on FlutterStandardReader/Writer (L530). The event channel and ProxyApi code also uses Flutter types directly.
  • Swift FFI validation checks only @TaskQueue and package dependencies (pigeon_lib_internal.dart L603–620), so nothing stops the combination.
  • Adding the Flutter import wouldn't fix it. swiftgen compiles the file with swiftc against the bare SDK, without a Flutter framework search path.

The Kotlin JNI side doesn't have this compile problem: in JNI mode the Kotlin generator imports the Flutter embedding for files with event channels or ProxyApis.

Proposed fix

  1. Now: in Swift FFI validation, reject files that contain event channels or ProxyApis, with a message such as: "Event channels and ProxyApis are not supported with Swift FFI yet. Move them to a separate pigeon file that doesn't use swift_use_ffi."
  2. Later, as separate designs:
    • event channels over native interop, for example as FlutterApi-style calls from native to Dart;
    • ProxyApis over FFI.

Environment

pigeon 29.0.6, swiftgen 0.2.0, ffigen 22.0.0, Xcode 16.4 (Swift 6.1.2), macOS SDK.

Activity

  1. added
    p: pigeonrelated to pigeon messaging codegen tool
    packageflutter/packages repository. See also p: labels.
    P2Important issues not at the top of the work list
    on Oct 6, 2026
  2. self-assigned this
    on Oct 6, 2026
  3. github-actions commented on Oct 23, 2026

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  4. locked as resolved and limited conversation to collaborators on Oct 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work listp: pigeonrelated to pigeon messaging codegen toolpackageflutter/packages repository. See also p: labels.team-ecosystemOwned by Ecosystem teamtriaged-ecosystemTriaged by Ecosystem team

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions