From 97ab92ee353e2b8bc60834a2e0756cba69922c38 Mon Sep 17 00:00:00 2001 From: Hossein Yousefi Date: Thu, 15 Feb 2024 11:37:30 +0100 Subject: [PATCH] Modify `plugin_ffi` and `package_ffi` template (#143376) * Use `dart run` instead of `flutter pub run` in the documentation as it is now deprecated. * Use `int64_t` instead of `intptr_t` for `sum` examples. --- packages/flutter_tools/templates/package_ffi/README.md.tmpl | 2 +- .../flutter_tools/templates/package_ffi/ffigen.yaml.tmpl | 4 ++-- packages/flutter_tools/templates/plugin_ffi/README.md.tmpl | 2 +- .../flutter_tools/templates/plugin_ffi/ffigen.yaml.tmpl | 4 ++-- .../plugin_ffi/lib/projectName_bindings_generated.dart.tmpl | 6 +++--- .../templates/plugin_ffi/src.tmpl/projectName.c.tmpl | 4 ++-- .../templates/plugin_ffi/src.tmpl/projectName.h.tmpl | 4 ++-- 7 files changed, 13 insertions(+), 13 deletions(-) diff --git a/packages/flutter_tools/templates/package_ffi/README.md.tmpl b/packages/flutter_tools/templates/package_ffi/README.md.tmpl index 05b96b01d6..485a428ea4 100644 --- a/packages/flutter_tools/templates/package_ffi/README.md.tmpl +++ b/packages/flutter_tools/templates/package_ffi/README.md.tmpl @@ -31,7 +31,7 @@ Bundling is done by Flutter based on the output from `build.dart`. To use the native code, bindings in Dart are needed. To avoid writing these by hand, they are generated from the header file (`src/{{projectName}}.h`) by `package:ffigen`. -Regenerate the bindings by running `flutter pub run ffigen --config ffigen.yaml`. +Regenerate the bindings by running `dart run ffigen --config ffigen.yaml`. ## Invoking native code diff --git a/packages/flutter_tools/templates/package_ffi/ffigen.yaml.tmpl b/packages/flutter_tools/templates/package_ffi/ffigen.yaml.tmpl index c33bb9f92c..1686f0a9a4 100644 --- a/packages/flutter_tools/templates/package_ffi/ffigen.yaml.tmpl +++ b/packages/flutter_tools/templates/package_ffi/ffigen.yaml.tmpl @@ -1,9 +1,9 @@ -# Run with `flutter pub run ffigen --config ffigen.yaml`. +# Run with `dart run ffigen --config ffigen.yaml`. name: {{pluginDartClass}}Bindings description: | Bindings for `src/{{projectName}}.h`. - Regenerate bindings with `flutter pub run ffigen --config ffigen.yaml`. + Regenerate bindings with `dart run ffigen --config ffigen.yaml`. output: 'lib/{{projectName}}_bindings_generated.dart' headers: entry-points: diff --git a/packages/flutter_tools/templates/plugin_ffi/README.md.tmpl b/packages/flutter_tools/templates/plugin_ffi/README.md.tmpl index 43378e7a94..3d3efc0987 100644 --- a/packages/flutter_tools/templates/plugin_ffi/README.md.tmpl +++ b/packages/flutter_tools/templates/plugin_ffi/README.md.tmpl @@ -73,7 +73,7 @@ The native build systems that are invoked by FFI (and method channel) plugins ar To use the native code, bindings in Dart are needed. To avoid writing these by hand, they are generated from the header file (`src/{{projectName}}.h`) by `package:ffigen`. -Regenerate the bindings by running `flutter pub run ffigen --config ffigen.yaml`. +Regenerate the bindings by running `dart run ffigen --config ffigen.yaml`. ## Invoking native code diff --git a/packages/flutter_tools/templates/plugin_ffi/ffigen.yaml.tmpl b/packages/flutter_tools/templates/plugin_ffi/ffigen.yaml.tmpl index 65aa00e692..5762da10e4 100644 --- a/packages/flutter_tools/templates/plugin_ffi/ffigen.yaml.tmpl +++ b/packages/flutter_tools/templates/plugin_ffi/ffigen.yaml.tmpl @@ -1,9 +1,9 @@ -# Run with `flutter pub run ffigen --config ffigen.yaml`. +# Run with `dart run ffigen --config ffigen.yaml`. name: {{pluginDartClass}}Bindings description: | Bindings for `src/{{projectName}}.h`. - Regenerate bindings with `flutter pub run ffigen --config ffigen.yaml`. + Regenerate bindings with `dart run ffigen --config ffigen.yaml`. output: 'lib/{{projectName}}_bindings_generated.dart' headers: entry-points: diff --git a/packages/flutter_tools/templates/plugin_ffi/lib/projectName_bindings_generated.dart.tmpl b/packages/flutter_tools/templates/plugin_ffi/lib/projectName_bindings_generated.dart.tmpl index 11b9f06a22..34b0773ca6 100644 --- a/packages/flutter_tools/templates/plugin_ffi/lib/projectName_bindings_generated.dart.tmpl +++ b/packages/flutter_tools/templates/plugin_ffi/lib/projectName_bindings_generated.dart.tmpl @@ -10,7 +10,7 @@ import 'dart:ffi' as ffi; /// Bindings for `src/{{projectName}}.h`. /// -/// Regenerate bindings with `flutter pub run ffigen --config ffigen.yaml`. +/// Regenerate bindings with `dart run ffigen --config ffigen.yaml`. /// class {{pluginDartClass}}Bindings { /// Holds the symbol lookup function. @@ -43,7 +43,7 @@ class {{pluginDartClass}}Bindings { } late final _sumPtr = - _lookup>( + _lookup>( 'sum'); late final _sum = _sumPtr.asFunction(); @@ -63,7 +63,7 @@ class {{pluginDartClass}}Bindings { } late final _sum_long_runningPtr = - _lookup>( + _lookup>( 'sum_long_running'); late final _sum_long_running = _sum_long_runningPtr.asFunction(); diff --git a/packages/flutter_tools/templates/plugin_ffi/src.tmpl/projectName.c.tmpl b/packages/flutter_tools/templates/plugin_ffi/src.tmpl/projectName.c.tmpl index a4bb788df9..3e559d1d88 100644 --- a/packages/flutter_tools/templates/plugin_ffi/src.tmpl/projectName.c.tmpl +++ b/packages/flutter_tools/templates/plugin_ffi/src.tmpl/projectName.c.tmpl @@ -5,14 +5,14 @@ // For very short-lived functions, it is fine to call them on the main isolate. // They will block the Dart execution while running the native function, so // only do this for native functions which are guaranteed to be short-lived. -FFI_PLUGIN_EXPORT intptr_t sum(intptr_t a, intptr_t b) { return a + b; } +FFI_PLUGIN_EXPORT int sum(int a, int b) { return a + b; } // A longer-lived native function, which occupies the thread calling it. // // Do not call these kind of native functions in the main isolate. They will // block Dart execution. This will cause dropped frames in Flutter applications. // Instead, call these native functions on a separate isolate. -FFI_PLUGIN_EXPORT intptr_t sum_long_running(intptr_t a, intptr_t b) { +FFI_PLUGIN_EXPORT int sum_long_running(int a, int b) { // Simulate work. #if _WIN32 Sleep(5000); diff --git a/packages/flutter_tools/templates/plugin_ffi/src.tmpl/projectName.h.tmpl b/packages/flutter_tools/templates/plugin_ffi/src.tmpl/projectName.h.tmpl index 084c64228f..79444598be 100644 --- a/packages/flutter_tools/templates/plugin_ffi/src.tmpl/projectName.h.tmpl +++ b/packages/flutter_tools/templates/plugin_ffi/src.tmpl/projectName.h.tmpl @@ -20,11 +20,11 @@ // For very short-lived functions, it is fine to call them on the main isolate. // They will block the Dart execution while running the native function, so // only do this for native functions which are guaranteed to be short-lived. -FFI_PLUGIN_EXPORT intptr_t sum(intptr_t a, intptr_t b); +FFI_PLUGIN_EXPORT int sum(int a, int b); // A longer lived native function, which occupies the thread calling it. // // Do not call these kind of native functions in the main isolate. They will // block Dart execution. This will cause dropped frames in Flutter applications. // Instead, call these native functions on a separate isolate. -FFI_PLUGIN_EXPORT intptr_t sum_long_running(intptr_t a, intptr_t b); +FFI_PLUGIN_EXPORT int sum_long_running(int a, int b);