feat: add build hooks support to plugin template#411
feat: add build hooks support to plugin template#411realmeylisdev wants to merge 13 commits intoVeryGoodOpenSource:mainfrom
Conversation
|
Thanks for the contribution @meylis1998, we will proceed with the review of this shortly! |
marcossevilla
left a comment
There was a problem hiding this comment.
thanks for opening this PR! I'll take a closer look later today, in the meantime, can we leave upgrades to VGA for another PR?
Add optional build hooks support for compiling native code in the very_good_flutter_plugin template. This enables developers to quickly ramp up when their plugin includes native assets. Features: - New use_build_hooks variable in brick.yaml (defaults to false) - Build hooks dependencies (hooks, code_assets, native_toolchain_c) - Example hook/build.dart for all native platforms (Linux, macOS, Windows, iOS, Android) - Example C source file (src/native_example.c) with an add() function - Documentation in README explaining build hooks usage Build hooks are automatically invoked during dart/flutter build, allowing seamless compilation of native code alongside Dart code. Closes VeryGoodOpenSource#392
c98a939 to
41743bd
Compare
|
Done! Removed the VGA upgrade from this PR and created a separate PR for it: #417 |
|
will wait for @ryzizub to give his review by EOW in order to approve 👍 |
ryzizub
left a comment
There was a problem hiding this comment.
Overally looks great! Good job, im just getting some dependency issues
...r_plugin/__brick__/{{#android}}{{project_name.snakeCase()}}_android{{/android}}/pubspec.yaml
Outdated
Show resolved
Hide resolved
|
@ryzizub feel free to review my other PRs. @marcossevilla reported that all others 'LGTM' too. Appreciate it! |
ryzizub
left a comment
There was a problem hiding this comment.
Can we also use that hook assets in dart? I believe it would be awesome for example, since this way its now it can be easily left out
...flutter_plugin/__brick__/{{#linux}}{{project_name.snakeCase()}}_linux{{/linux}}/pubspec.yaml
Outdated
Show resolved
Hide resolved
|
@marcossevilla please review! |
|
@meylis1998 I was probably unclear on my comment.. sorry 💙, what i meant with |
Done! Added |
4afc8da to
e49ff06
Compare
e49ff06 to
8379f51
Compare
|
Finally was able to get the CI checks right) We can review it now. |
...)}}_android{{/android}}/{{#use_build_hooks}}lib/src{{/use_build_hooks}}/native_bindings.dart
Outdated
Show resolved
Hide resolved
|
@meylis1998 Great work on native bindings!! I would include add method to platform interface and use that binding on each platform side. That way on dart side we wont care about each platform but we will use the plugin itself. We will use something like _platform. add in my_plugin :) Hope that makes sense |
|
New Usage Pattern // Before (platform-specific import) // After (main plugin import) |
...project_name.snakeCase()}}_android{{/android}}/lib/{{project_name.snakeCase()}}_android.dart
Show resolved
Hide resolved
c18e689 to
c668598
Compare
c668598 to
e77cb12
Compare
|
Can't wait to see them merge. |
ryzizub
left a comment
There was a problem hiding this comment.
Im getting also on generated plugin some format issues mainly Missing a newline at the end of the file.
I would recommend generating this template via mason and verify the code
| // Configure the C library builder | ||
| final cbuilder = CBuilder.library( | ||
| name: packageName, | ||
| assetName: '$packageName.dart', |
There was a problem hiding this comment.
I was testing this on package and i found issues one of them is that assetName should match the library URI where @Native is declared.
Can you verify that its properly running when the plugin is connected and add method is used?
|
@meylis1998 let me know if you need assistance to resolve issues |
|
@meylis1998 were you able to take a look at this? |
|
@ryzizub @realmeylisdev let me know if we can close this one for now or if we want to fix the issues |
Description
Adds optional build hooks support for compiling native code in the
very_good_flutter_plugintemplate, enabling developers to quickly ramp up when their plugin includes native assets.Closes #392
Changes
Core Changes
use_build_hooksboolean variable tobrick.yaml(defaults tofalsefor backward compatibility)hooks,code_assets,native_toolchain_c) to platform packages when enabledPlatform Support
Added build hooks to all native platforms:
Implementation
Each platform includes:
hook/build.dart- Build hook script that compiles C code usingCBuildersrc/native_example.c- Example C function (add()) demonstrating FFI usagepubspec.yamlwith conditional dependenciesDocumentation
Benefits
✅ Quick Ramp Up: Developers can immediately start using native code with pre-configured build hooks
✅ Modern Best Practices: Uses the new stable build hooks system from Dart 3.10 / Flutter 3.38
✅ Complete Example: Working C code example shows the full FFI workflow
✅ Backward Compatible: Optional feature (off by default) doesn't affect existing workflows
✅ Multi-Platform: Consistent implementation across all native platforms
Testing
To test this feature:
Generate a plugin with build hooks enabled:
very_good create flutter_plugin my_plugin --use_build_hooks trueThe generated plugin will include build hooks infrastructure for compiling native code
Build the plugin to verify hooks execute correctly:
cd my_plugin_linux dart runRequirements
References