Skip to content
Closed

ignore #10232

Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
eb7cac6
methods, basic types, sync, nullable-sync, async, and classes
tarrinneal Apr 15, 2025
9fa695d
broken nullable async methods
tarrinneal Apr 15, 2025
0aff0fd
refactor type logic, add codec
tarrinneal Apr 17, 2025
1ed8a8b
objects and enums
tarrinneal Apr 22, 2025
ee50607
full codec
tarrinneal May 9, 2025
4c6eb1a
error handling and more tests
tarrinneal May 29, 2025
f87efd4
fix codec
tarrinneal May 29, 2025
3e9d9f0
flutter api and plumbing through legacy apis and tests
tarrinneal Jun 27, 2025
6ad2e37
jnigen.yaml
tarrinneal Jun 27, 2025
9b55d44
ffi just getting started
tarrinneal Jul 7, 2025
25e8c30
gen fluff
tarrinneal Jul 11, 2025
df40332
not working
tarrinneal Jul 16, 2025
d90ecca
missing files
tarrinneal Jul 17, 2025
92933f8
gitignore
tarrinneal Jul 17, 2025
cb1c0fe
ios ffigen settings
tarrinneal Jul 17, 2025
a7cc7ce
remove macos min version from ffigen config
tarrinneal Jul 17, 2025
8fb8dca
no dylibs
tarrinneal Jul 17, 2025
ab64302
more basic, still can't see class
tarrinneal Jul 17, 2025
c7d00c6
upload macos
tarrinneal Jul 17, 2025
33f8fa1
fix ffigen files
tarrinneal Jul 17, 2025
4977cc2
test
tarrinneal Jul 29, 2025
586edf2
wip
tarrinneal Jul 29, 2025
74b1cb1
Merge branch 'Frillback' of github.com:tarrinneal/packages into Frill…
tarrinneal Jul 29, 2025
3736528
ns
tarrinneal Jul 29, 2025
31d182f
dunno
tarrinneal Jul 30, 2025
c63e598
something
tarrinneal Jul 30, 2025
6dc23e7
working again
tarrinneal Jul 30, 2025
982dfe6
Merge branch 'Frillback' of https://github.com/tarrinneal/packages in…
tarrinneal Jul 30, 2025
ecc088a
enums
tarrinneal Aug 12, 2025
927fd8d
and this one
tarrinneal Aug 12, 2025
877d60d
ffi support for classes, enums, and objects (partial testing)
tarrinneal Aug 26, 2025
910ac95
tests
tarrinneal Aug 26, 2025
b522d6c
fix enums, still need to resolve Any?
tarrinneal Sep 4, 2025
bd47b34
actually fix enums
tarrinneal Sep 5, 2025
4192a89
starting nullables, gonna be a mess
tarrinneal Sep 5, 2025
86e6907
nullable base types in classes
tarrinneal Sep 17, 2025
87f4f8a
add nullable enums (no tests for null things though.....)
tarrinneal Sep 18, 2025
ed3eb93
update to latest version
tarrinneal Sep 19, 2025
457edef
Not even I understand
tarrinneal Sep 24, 2025
9214479
fix null object?
tarrinneal Sep 25, 2025
aadd859
multi-arity and nullable enums in classes
tarrinneal Sep 26, 2025
8cb24b6
nested classes
tarrinneal Sep 27, 2025
d29e86a
typed lists and maps except int keys
tarrinneal Oct 14, 2025
b32d506
Merge branch 'main' of https://github.com/flutter/packages into Frill…
tarrinneal Oct 15, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
ffi just getting started
  • Loading branch information
tarrinneal committed Jul 7, 2025
commit 9b55d4475e98ad1b2f288a71b29e86add9a5692a
6 changes: 6 additions & 0 deletions packages/pigeon/lib/src/dart/dart_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class DartOptions {
this.sourceOutPath,
this.testOutPath,
this.useJni = false,
this.useFfi = false,
this.dartOut,
});

Expand All @@ -62,6 +63,9 @@ class DartOptions {
/// Whether to use Jni for generating kotlin interop code.
final bool useJni;

/// Whether to use Ffi for generating swift interop code.
final bool useFfi;

/// Path to output generated Dart file.
final String? dartOut;

Expand All @@ -75,6 +79,7 @@ class DartOptions {
sourceOutPath: map['sourceOutPath'] as String?,
testOutPath: map['testOutPath'] as String?,
useJni: map['useJni'] as bool? ?? false,
useFfi: map['useFfi'] as bool? ?? false,
dartOut: map['dartOut'] as String?,
);
}
Expand All @@ -87,6 +92,7 @@ class DartOptions {
if (sourceOutPath != null) 'sourceOutPath': sourceOutPath!,
if (testOutPath != null) 'testOutPath': testOutPath!,
if (useJni) 'useJni': useJni,
if (useFfi) 'useFfi': useFfi,
if (dartOut != null) 'dartOut': dartOut!,
};
return result;
Expand Down
21 changes: 10 additions & 11 deletions packages/pigeon/lib/src/kotlin/kotlin_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class KotlinOptions {
this.package,
this.copyrightHeader,
this.useJni = false,
this.exampleAppDirectory,
this.appDirectory,
this.errorClassName,
this.includeErrorClass = true,
this.fileSpecificClassNameComponent,
Expand All @@ -57,8 +57,8 @@ class KotlinOptions {
/// Whether to use Jni when possible.
final bool useJni;

/// The directory that the example app exists in, this is required for Jni APIs.
final String? exampleAppDirectory;
/// The directory that the app exists in, this is required for Jni APIs.
final String? appDirectory;

/// The name of the error class used for passing custom error parameters.
final String? errorClassName;
Expand All @@ -78,7 +78,7 @@ class KotlinOptions {
return KotlinOptions(
package: map['package'] as String?,
useJni: map['useJni'] as bool? ?? false,
exampleAppDirectory: map['exampleAppDirectory'] as String?,
appDirectory: map['appDirectory'] as String?,
copyrightHeader: map['copyrightHeader'] as Iterable<String>?,
errorClassName: map['errorClassName'] as String?,
includeErrorClass: map['includeErrorClass'] as bool? ?? true,
Expand All @@ -93,8 +93,7 @@ class KotlinOptions {
final Map<String, Object> result = <String, Object>{
if (package != null) 'package': package!,
if (useJni) 'useJni': useJni,
if (exampleAppDirectory != null)
'exampleAppDirectory': exampleAppDirectory!,
if (appDirectory != null) 'appDirectory': appDirectory!,
if (copyrightHeader != null) 'copyrightHeader': copyrightHeader!,
if (errorClassName != null) 'errorClassName': errorClassName!,
'includeErrorClass': includeErrorClass,
Expand All @@ -111,7 +110,7 @@ class KotlinOptions {
}
}

///
/// Options that control how Kotlin code will be generated.
class InternalKotlinOptions extends InternalOptions {
/// Creates a [InternalKotlinOptions] object
const InternalKotlinOptions({
Expand All @@ -121,7 +120,7 @@ class InternalKotlinOptions extends InternalOptions {
this.errorClassName,
this.includeErrorClass = true,
this.useJni = false,
this.exampleAppDirectory,
this.appDirectory,
this.fileSpecificClassNameComponent,
});

Expand All @@ -135,7 +134,7 @@ class InternalKotlinOptions extends InternalOptions {
errorClassName = options.errorClassName,
includeErrorClass = options.includeErrorClass,
useJni = options.useJni,
exampleAppDirectory = options.exampleAppDirectory,
appDirectory = options.appDirectory,
fileSpecificClassNameComponent =
options.fileSpecificClassNameComponent ??
kotlinOut.split('/').lastOrNull?.split('.').first;
Expand All @@ -161,8 +160,8 @@ class InternalKotlinOptions extends InternalOptions {
/// Whether to use Jni for generating kotlin interop code.
final bool useJni;

/// The directory that the example app exists in, this is required for Jni APIs.
final String? exampleAppDirectory;
/// The directory that the app exists in, this is required for Jni APIs.
final String? appDirectory;

/// A String to augment class names to avoid cross file collisions.
final String? fileSpecificClassNameComponent;
Expand Down
1 change: 1 addition & 0 deletions packages/pigeon/lib/src/pigeon_lib.dart
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,7 @@ ${_argParser.usage}''';
DartGeneratorAdapter(),
JavaGeneratorAdapter(),
SwiftGeneratorAdapter(),
FfigenConfigGeneratorAdapter(),
KotlinGeneratorAdapter(),
JnigenYamlGeneratorAdapter(),
CppGeneratorAdapter(),
Expand Down
53 changes: 50 additions & 3 deletions packages/pigeon/lib/src/pigeon_lib_internal.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import 'kotlin/jnigen_yaml_generator.dart';
import 'kotlin/kotlin_generator.dart';
import 'objc/objc_generator.dart';
import 'pigeon_lib.dart';
import 'swift/ffigen_config_generator.dart';
import 'swift/swift_generator.dart';

/// Options used when running the code generator.
Expand Down Expand Up @@ -476,6 +477,52 @@ class SwiftGeneratorAdapter implements GeneratorAdapter {
List<Error> validate(InternalPigeonOptions options, Root root) => <Error>[];
}

/// A [GeneratorAdapter] that generates FfigenConfig source code.
class FfigenConfigGeneratorAdapter implements GeneratorAdapter {
/// Constructor for [FfigenConfigGeneratorAdapter].
FfigenConfigGeneratorAdapter(
{this.fileTypeList = const <FileType>[FileType.na]});

@override
List<FileType> fileTypeList;

@override
void generate(StringSink sink, InternalPigeonOptions options, Root root,
FileType fileType) {
if (options.swiftOptions == null || options.dartOptions == null) {
return;
}
final FfigenConfigGenerator generator = FfigenConfigGenerator();

final InternalFfigenConfigOptions ffigenYamlOptions =
InternalFfigenConfigOptions(
options.dartOptions!,
options.swiftOptions!,
options.basePath,
options.dartOptions?.dartOut,
options.swiftOptions!.swiftOut,
);

generator.generate(
ffigenYamlOptions,
root,
sink,
dartPackageName: options.dartPackageName,
);
}

@override
IOSink? shouldGenerate(InternalPigeonOptions options, FileType _) =>
options.swiftOptions?.appDirectory != null &&
(options.swiftOptions?.useFfi ?? false)
? _openSink('ffigen_config.dart',
basePath: options.swiftOptions?.appDirectory ?? '')
: null;

@override
List<Error> validate(InternalPigeonOptions options, Root root) => <Error>[];
}

/// A [GeneratorAdapter] that generates C++ source code.
class CppGeneratorAdapter implements GeneratorAdapter {
/// Constructor for [CppGeneratorAdapter].
Expand Down Expand Up @@ -630,7 +677,7 @@ class JnigenYamlGeneratorAdapter implements GeneratorAdapter {
@override
void generate(StringSink sink, InternalPigeonOptions options, Root root,
FileType fileType) {
if (options.kotlinOptions == null) {
if (options.kotlinOptions == null || options.dartOptions == null) {
return;
}
final JnigenYamlGenerator generator = JnigenYamlGenerator();
Expand All @@ -640,7 +687,7 @@ class JnigenYamlGeneratorAdapter implements GeneratorAdapter {
options.kotlinOptions!,
options.basePath,
options.dartOptions?.dartOut,
options.kotlinOptions!.exampleAppDirectory,
options.kotlinOptions!.appDirectory,
);

generator.generate(
Expand All @@ -656,7 +703,7 @@ class JnigenYamlGeneratorAdapter implements GeneratorAdapter {
options.kotlinOptions?.kotlinOut != null &&
(options.kotlinOptions?.useJni ?? false)
? _openSink('jnigen.yaml',
basePath: options.kotlinOptions?.exampleAppDirectory ?? '')
basePath: options.kotlinOptions?.appDirectory ?? '')
: null;

@override
Expand Down
161 changes: 161 additions & 0 deletions packages/pigeon/lib/src/swift/ffigen_config_generator.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:path/path.dart' as path;

import '../ast.dart';
import '../dart/dart_generator.dart' show InternalDartOptions;
import '../generator.dart';
import '../generator_tools.dart';
import 'swift_generator.dart' show InternalSwiftOptions;

/// Options for [FfigenConfigGenerator].
class InternalFfigenConfigOptions extends InternalOptions {
/// Creates a [InternalFfigenConfigOptions].
InternalFfigenConfigOptions(
this.dartOptions,
this.swiftOptions,
this.basePath,
this.dartOut,
this.exampleAppDirectory,
);

/// Dart options.
final InternalDartOptions dartOptions;

/// Swift options.
final InternalSwiftOptions swiftOptions;

/// A base path to be prepended to all provided output paths.
final String? basePath;

/// Dart output path.
final String? dartOut;

/// Android example app directory.
final String? exampleAppDirectory;
}

/// Generator for jnigen yaml configuration file.
class FfigenConfigGenerator extends Generator<InternalFfigenConfigOptions> {
@override
void generate(
InternalFfigenConfigOptions generatorOptions, Root root, StringSink sink,
{required String dartPackageName}) {
final Indent indent = Indent(sink);

indent.format('''
import 'dart:io';

import 'package:ffigen/ffigen.dart' as fg;
import 'package:logging/logging.dart';
import 'package:pub_semver/pub_semver.dart';
import 'package:swiftgen/swiftgen.dart';

Future<void> main() async {
// TODO(https://github.com/dart-lang/native/issues/2371): Remove this.
Logger.root.onRecord.listen((record) {
stderr.writeln('\${record.level.name}: \${record.message}');
});

await SwiftGen(
target: Target(
triple: 'x86_64-apple-macosx14.0',
sdk: Uri.directory(
'/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk',
),
),
input: ObjCCompatibleSwiftFileInput(
module: 'AVFAudio',
files: [Uri.file('avf_audio_wrapper.swift')],
),
tempDirectory: Uri.directory('temp'),
outputModule: 'AVFAudioWrapper',
ffigen: FfiGenConfig(
output: Uri.file('avf_audio_bindings.dart'),
outputObjC: Uri.file('avf_audio_wrapper.m'),
externalVersions: fg.ExternalVersions(
ios: fg.Versions(min: Version(12, 0, 0)),
macos: fg.Versions(min: Version(10, 14, 0)),
),
objcInterfaces: fg.DeclarationFilters(
shouldInclude: (decl) => decl.originalName == 'AVAudioPlayerWrapper',
),
preamble: \'''
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// ignore_for_file: always_specify_types
// ignore_for_file: camel_case_types
// ignore_for_file: non_constant_identifier_names
// ignore_for_file: unnecessary_non_null_assertion
// ignore_for_file: unused_element
// ignore_for_file: unused_field
// coverage:ignore-file
\''',
),
).generate();

final result = Process.runSync('swiftc', [
'-emit-library',
'-o',
'avf_audio_wrapper.dylib',
'-module-name',
'AVFAudioWrapper',
'avf_audio_wrapper.swift',
'-framework',
'AVFAudio',
'-framework',
'Foundation',
]);
if (result.exitCode != 0) {
print('Failed to build the swift wrapper library');
print(result.stdout);
print(result.stderr);
}
}
// name: SwiftLibrary
// language: swift
// output: '${path.posix.join(generatorOptions.basePath ?? '', path.withoutExtension(generatorOptions.dartOut ?? ''))}.ffi.dart'
// exclude-all-by-default: true
// headers:
// entry-points:
// - '${generatorOptions.swiftOptions.swiftOut}'
// preamble: |
// # Header input

// // ignore_for_file: camel_case_types, non_constant_identifier_names
// // ignore_for_file: unused_element, unused_field, return_of_invalid_type
// // ignore_for_file: void_checks, annotate_overrides
// // ignore_for_file: no_leading_underscores_for_local_identifiers
// // ignore_for_file: library_private_types_in_public_api

''');
indent.writeScoped('// objc-interfaces:', '', () {
indent.writeScoped('// include:', '', () {
for (final Api api in root.apis) {
if (api is AstHostApi || api is AstFlutterApi) {
indent.writeln("// - '${api.name}'");
indent.writeln("// - '${api.name}Registrar'");
}
}
for (final Class dataClass in root.classes) {
indent.writeln("// - '${dataClass.name}'");
}
for (final Enum enumType in root.enums) {
indent.writeln("// - '${enumType.name}'");
}
});
indent.writeScoped('// include:', '', () {
for (final Class dataClass in root.classes) {
indent.writeln("// '${dataClass.name}': '${dataClass.name}'");
}
for (final Enum enumType in root.enums) {
indent.writeln("// '${enumType.name}': '${enumType.name}'");
}
});
});
}
}
Loading