Skip to content

Commit

Permalink
chore: use ffi_gen for binding generation
Browse files Browse the repository at this point in the history
  • Loading branch information
luiscib3r committed May 14, 2023
1 parent 84b0c2c commit 0291c5c
Show file tree
Hide file tree
Showing 38 changed files with 6,368 additions and 1,115 deletions.
7 changes: 2 additions & 5 deletions example/text_classification/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ publish_to: 'none'
version: 1.0.0+1

environment:
sdk: ">=2.12.0 <3.0.0"
flutter: ">=1.26.0-17.6.pre"
sdk: '>=3.0.0 <4.0.0'

dependencies:
flutter:
Expand All @@ -25,15 +24,13 @@ dev_dependencies:
flutter_driver:
sdk: flutter
integration_test:
sdk: flutter

sdk: flutter

# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec

# The following section is specific to Flutter.
flutter:

# The following line ensures that the Material Icons font is
# included with your application, so that you can use the icons in
# the material Icons class.
Expand Down
31 changes: 31 additions & 0 deletions ffigen_tensorflow_lite.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Run with `flutter pub run ffigen --config ffigen.yaml`.
name: TensorFlowLiteBindings
description: |
Bindings for `src/tensorflow_lite/c_api.h`.
Regenerate bindings with `flutter pub run ffigen --config ffigen_tensorflow_lite.yaml`.
output: 'lib/src/bindings/tensorflow_lite_bindings_generated.dart'
headers:
entry-points:
- 'src/tensorflow_lite/c_api.h'
- 'src/tensorflow_lite/c_api_experimental.h'
- 'src/tensorflow_lite/coreml_delegate.h'
- 'src/tensorflow_lite/metal_delegate.h'
- 'src/tensorflow_lite/xnnpack_delegate.h'
- 'src/tensorflow_lite/delegate.h'
- 'src/tensorflow_lite/delegate_options.h'
include-directives:
- 'src/tensorflow_lite/c_api.h'
- 'src/tensorflow_lite/c_api_experimental.h'
- 'src/tensorflow_lite/coreml_delegate.h'
- 'src/tensorflow_lite/metal_delegate.h'
- 'src/tensorflow_lite/xnnpack_delegate.h'
- 'src/tensorflow_lite/delegate.h'
- 'src/tensorflow_lite/delegate_options.h'
preamble: |
// ignore_for_file: always_specify_types
// ignore_for_file: camel_case_types
// ignore_for_file: non_constant_identifier_names
comments:
style: any
length: full
33 changes: 26 additions & 7 deletions lib/src/bindings/bindings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,34 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import 'dart:ffi';
import 'dart:io';

import 'package:tflite_flutter/src/bindings/tensorflow_lite_bindings_generated.dart';

final DynamicLibrary _dylib = () {
if (Platform.isAndroid) {
return DynamicLibrary.open('libtensorflowlite_jni.so');
}

if (Platform.isIOS) {
return DynamicLibrary.process();
}

throw UnsupportedError('Unknown platform: ${Platform.operatingSystem}');
}();

import 'package:ffi/ffi.dart';
final DynamicLibrary _dylibGpu = () {
if (Platform.isAndroid) {
return DynamicLibrary.open('libtensorflowlite_gpu_jni.so');
}

import 'dlib.dart';
throw UnsupportedError('Unknown platform: ${Platform.operatingSystem}');
}();

/// Version information for the TensorFlowLite library.
final Pointer<Utf8> Function() tfLiteVersion = tflitelib
.lookup<NativeFunction<_TfLiteVersionNativeT>>('TfLiteVersion')
.asFunction();
/// TensorFlowLite Bindings
final tfliteBinding = TensorFlowLiteBindings(_dylib);

typedef _TfLiteVersionNativeT = Pointer<Utf8> Function();
/// TensorFlowLite Gpu Bindings
final tfliteBindingGpu = TensorFlowLiteBindings(_dylibGpu);
43 changes: 0 additions & 43 deletions lib/src/bindings/delegates/coreml_delegate.dart

This file was deleted.

62 changes: 0 additions & 62 deletions lib/src/bindings/delegates/gpu_delegate.dart

This file was deleted.

56 changes: 0 additions & 56 deletions lib/src/bindings/delegates/metal_delegate.dart

This file was deleted.

54 changes: 0 additions & 54 deletions lib/src/bindings/delegates/xnnpack_delegate.dart

This file was deleted.

54 changes: 0 additions & 54 deletions lib/src/bindings/dlib.dart

This file was deleted.

Loading

0 comments on commit 0291c5c

Please sign in to comment.