8: Dart build runner integration#9
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
4b841df to
4d38fe7
Compare
|
i can remove all |
jtmcdole
left a comment
There was a problem hiding this comment.
Lets remove the .idea folders from the reppo and just put them in .gitignore
| import 'package:build/build.dart'; | ||
| import 'package:protofu/builder_impl.dart'; | ||
|
|
||
| Builder getBuilder(BuilderOptions options) => ProtofuBuilder(options); |
There was a problem hiding this comment.
add public dart doc for public members.
There was a problem hiding this comment.
Move to lib/src/ unless you want people importing _impl.dart files.
| import 'package:protofu/paths.dart'; | ||
| import 'package:protofu/plugin_from_pubspec.dart'; | ||
|
|
||
| class ProtofuBuilder implements Builder { |
There was a problem hiding this comment.
Add public dart doc for all public classes, members, functions, etc.
| import 'package:protofu/paths.dart'; | ||
| import 'package:protofu/plugin_from_pubspec.dart'; | ||
|
|
||
| class ProtofuBuilder implements Builder { |
There was a problem hiding this comment.
Make this a final class and we never have to worry about others extending or implementing it.
| @@ -18,7 +18,7 @@ version: 1.2.1 | |||
There was a problem hiding this comment.
API features are added; bump the minor version to 1.3.0
Also update the changelog.
| # ProtoFu-Builder | ||
| This is a fork of https://github.com/jtmcdole/protofu | ||
| The ProtoFu builder can be used within a flutter/dart build runner of your project. | ||
|
|
There was a problem hiding this comment.
Ah, but its not a fork anymore!
| // protoc --plugin expects an executable; `dart run <script>` works on all | ||
| // platforms when passed as the plugin path if Dart is on PATH. | ||
| // Return the script path directly — callers should prefer precompile: true. | ||
| return p.join(pluginRoot, 'bin', 'protoc_plugin.dart'); |
There was a problem hiding this comment.
[HIGH] Returning a '.dart' file path directly will likely fail as 'protoc' expects an executable to run the plugin. While the comment mentions 'dart run', the code returns just the script path. If precompilation is not used, you should probably return a wrapper script or ensure the caller handles this correctly (though 'protoc' doesn't easily support arguments in the plugin path).
| import 'package:protofu/spinner.dart'; | ||
| import 'package:protofu/unzip.dart'; | ||
|
|
||
| bool _isArm() { |
There was a problem hiding this comment.
[LOW] Using 'PROCESSOR_ARCHITECTURE' for ARM detection on Windows can be unreliable if the Dart process is running under emulation (e.g. x86_64 emulation on ARM64). Consider using 'Platform.version' or checking 'PROCESSOR_ARCHITEW6432' as well.
There was a problem hiding this comment.
Windows ARM detection now also checks PROCESSOR_ARCHITEW6432, which holds the native architecture when a 32-bit process runs under WOW64 emulation.
Actually i would recommended never working with protobuf on windows in general 🙃
There was a problem hiding this comment.
📋 Review Summary
This PR successfully integrates 'protofu' with the Dart 'build_runner', enabling automated protobuf compilation. It also adds support for ARM architectures and allows resolving the 'protoc_plugin' from the project's dependencies, which is a great improvement for developer experience.
🔍 General Feedback
- The use of a static future for setup in the builder is a good performance optimization to avoid redundant tool downloads.
- Consider adding unit tests for the new builder implementation and the ARM detection logic to ensure long-term stability across platforms.
- The 'build_extensions' in 'build.yaml' are currently hardcoded, which might lead to confusion if users override 'root_dir' or 'out_dir' in the builder options
|
Thx for your review @jtmcdole |
|
Okay i came to it way earlier than expected. |
Did you push any changes? |
Oh dear I pushed it to the wrong branch, since i had another one for our internal fork, we currently use. |
…) or .bat file (Windows) instead of returning a raw .dart path that protoc can't execute.
Okay should be fine now |
Fixes #8
Proposed Changes
build_runner integration (lib/builder.dart, lib/builder_impl.dart, build.yaml) — Implements the Builder interface. When build_runner detects .proto files under proto/, it invokes ProtofuBuilder to run protoc and write the generated .pb.dart files into lib/proto/. Setup (downloading protoc, resolving/compiling the plugin) is shared across all builder instances via a static future to avoid redundant work.
Plugin resolution from pubspec (lib/plugin_from_pubspec.dart) — Can locate protoc_plugin from the project's package_config and optionally AOT-compile it to a native executable (cached under .dart_tool/build/protofu/plugin/pubspec/), which is faster than using dart run each time.
ARM architecture support (lib/download_tools.dart) — downloadProtoc now detects ARM vs x86-64 on macOS, Linux, and Windows and downloads the correct binary (e.g., osx-aarch_64 for Apple Silicon).
Updated pubspec.yaml — Adds build: ^4.0.0 and package_config: ^2.1.0 dependencies; bumps min SDK to >=3.7.0.
Tests pass
Appropriate changes to README are included in PR