Skip to content

Commit

Permalink
Update package:objective_c to be compatible with ffigen (#1618)
Browse files Browse the repository at this point in the history
* Update `package:objective_c` to be compatible with `ffigen` returning Structs

* Update objective_c.yaml

* Update pubspec.yaml

* Remove preable
  • Loading branch information
brianquinlan authored Sep 30, 2024
1 parent f664a30 commit 8490510
Show file tree
Hide file tree
Showing 8 changed files with 135 additions and 73 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/objective_c.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ jobs:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332
- uses: subosito/flutter-action@44ac965b96f18d999802d4b807e3256d5a3f9fa1
with:
flutter-version: 3.19.0
channel: 'stable'
- id: install
name: Install dependencies
Expand All @@ -53,7 +52,6 @@ jobs:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332
- uses: subosito/flutter-action@44ac965b96f18d999802d4b807e3256d5a3f9fa1
with:
flutter-version: 3.19.0
channel: 'stable'
- name: Install dependencies
run: flutter pub get
Expand Down Expand Up @@ -90,7 +88,6 @@ jobs:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332
- uses: subosito/flutter-action@44ac965b96f18d999802d4b807e3256d5a3f9fa1
with:
flutter-version: 3.19.0
channel: 'stable'
- name: Install dependencies
run: flutter pub get
Expand Down
17 changes: 11 additions & 6 deletions pkgs/ffigen/lib/src/code_generator/objc_built_in_functions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// 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.

import 'package:meta/meta.dart';

import '../code_generator.dart';
import '../config_provider/config_types.dart';

Expand Down Expand Up @@ -43,7 +45,8 @@ class ObjCBuiltInFunctions {
ObjCImport('UnimplementedOptionalMethodException');

// Keep in sync with pkgs/objective_c/ffigen_objc.yaml.
static const _builtInInterfaces = {
@visibleForTesting
static const builtInInterfaces = {
'DartProxy',
'DartProxyBuilder',
'NSArray',
Expand Down Expand Up @@ -78,11 +81,13 @@ class ObjCBuiltInFunctions {
'NSValue',
'Protocol',
};
static const _builtInCompounds = {
@visibleForTesting
static const builtInCompounds = {
'NSFastEnumerationState': 'NSFastEnumerationState',
'_NSRange': 'NSRange',
};
static const _builtInEnums = {
@visibleForTesting
static const builtInEnums = {
'NSBinarySearchingOptions',
'NSComparisonResult',
'NSDataBase64DecodingOptions',
Expand Down Expand Up @@ -110,11 +115,11 @@ class ObjCBuiltInFunctions {
// TODO(https://github.com/dart-lang/native/issues/1173): Ideally this check
// would be based on more than just the name.
bool isBuiltInInterface(String name) =>
!generateForPackageObjectiveC && _builtInInterfaces.contains(name);
!generateForPackageObjectiveC && builtInInterfaces.contains(name);
String? getBuiltInCompoundName(String name) =>
generateForPackageObjectiveC ? null : _builtInCompounds[name];
generateForPackageObjectiveC ? null : builtInCompounds[name];
bool isBuiltInEnum(String name) =>
!generateForPackageObjectiveC && _builtInEnums.contains(name);
!generateForPackageObjectiveC && builtInEnums.contains(name);
bool isNSObject(String name) => name == 'NSObject';

// We need to load a separate instance of objc_msgSend for each signature. If
Expand Down
2 changes: 1 addition & 1 deletion pkgs/ffigen/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ dependencies:
file: ^7.0.0
glob: ^2.0.0
logging: ^1.0.0
meta: ^1.11.0
package_config: ^2.1.0
path: ^1.8.0
pub_semver: ^2.1.4
Expand All @@ -37,7 +38,6 @@ dev_dependencies:
dart_flutter_team_lints: ^2.0.0
json_schema: ^5.1.1
leak_tracker: ^10.0.7
meta: ^1.11.0
objective_c: ^2.1.0
test: ^1.16.2

Expand Down
4 changes: 4 additions & 0 deletions pkgs/objective_c/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
bindings if an optional method is invoked, and the instance doesn't implement
the method.
- Dispatch all object/block releases to the main thread.
- Require Dart 3.4 or later (due to the use of `dart:ffi`
`Struct.create` by `package:ffigen`).
- __Breaking change__: Return structs from ObjC methods by value instead of
taking a struct return pointer.

## 2.0.0

Expand Down
2 changes: 0 additions & 2 deletions pkgs/objective_c/ffigen_objc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -100,5 +100,3 @@ preamble: |
// ignore_for_file: unused_element
// ignore_for_file: unused_field
// coverage:ignore-file
import 'package:ffi/ffi.dart' as pkg_ffi;
Loading

0 comments on commit 8490510

Please sign in to comment.