Skip to content

8: Dart build runner integration#9

Open
f1sh1918 wants to merge 17 commits into
jtmcdole:mainfrom
digitalfabrik:8-dart-build-runner-integration
Open

8: Dart build runner integration#9
f1sh1918 wants to merge 17 commits into
jtmcdole:mainfrom
digitalfabrik:8-dart-build-runner-integration

Conversation

@f1sh1918

@f1sh1918 f1sh1918 commented Apr 13, 2026

Copy link
Copy Markdown

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

@google-cla

google-cla Bot commented Apr 13, 2026

Copy link
Copy Markdown

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.

@f1sh1918 f1sh1918 force-pushed the 8-dart-build-runner-integration branch from 4b841df to 4d38fe7 Compare April 13, 2026 13:05
@f1sh1918

f1sh1918 commented Apr 13, 2026

Copy link
Copy Markdown
Author

i can remove all idea files if you want!

@jtmcdole jtmcdole left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets remove the .idea folders from the reppo and just put them in .gitignore

Comment thread lib/builder.dart
import 'package:build/build.dart';
import 'package:protofu/builder_impl.dart';

Builder getBuilder(BuilderOptions options) => ProtofuBuilder(options);

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add public dart doc for public members.

Comment thread lib/src/builder_impl.dart

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move to lib/src/ unless you want people importing _impl.dart files.

Comment thread lib/builder_impl.dart Outdated
import 'package:protofu/paths.dart';
import 'package:protofu/plugin_from_pubspec.dart';

class ProtofuBuilder implements Builder {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add public dart doc for all public classes, members, functions, etc.

Comment thread lib/builder_impl.dart Outdated
import 'package:protofu/paths.dart';
import 'package:protofu/plugin_from_pubspec.dart';

class ProtofuBuilder implements Builder {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make this a final class and we never have to worry about others extending or implementing it.

Comment thread pubspec.yaml Outdated
@@ -18,7 +18,7 @@ version: 1.2.1

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

API features are added; bump the minor version to 1.3.0
Also update the changelog.

Comment thread README.md Outdated
Comment on lines +1 to +4
# 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.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, but its not a fork anymore!

@jtmcdole jtmcdole left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--- gemini review summary (forgot to switch to agentfu :(

Comment thread lib/src/builder_impl.dart
Comment thread lib/plugin_from_pubspec.dart Outdated
// 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');

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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).

Comment thread lib/download_tools.dart
import 'package:protofu/spinner.dart';
import 'package:protofu/unzip.dart';

bool _isArm() {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 🙃

@jtmcdole jtmcdole left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📋 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

@f1sh1918

Copy link
Copy Markdown
Author

Thx for your review @jtmcdole
I will work on it next week!

@f1sh1918

f1sh1918 commented Apr 28, 2026

Copy link
Copy Markdown
Author

Okay i came to it way earlier than expected.
I hope i addressed all your concerns.

@f1sh1918 f1sh1918 requested a review from jtmcdole April 28, 2026 13:21
@jtmcdole

jtmcdole commented Jun 3, 2026

Copy link
Copy Markdown
Owner

Okay i came to it way earlier than expected. I hope i addressed all your concerns.

Did you push any changes?

@f1sh1918

f1sh1918 commented Jun 3, 2026

Copy link
Copy Markdown
Author

Okay i came to it way earlier than expected. I hope i addressed all your concerns.

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.
I cherry-picked the commits from there, but will recheck tommorow if everything is fine and resolved since i did this couple of time ago.

@f1sh1918

f1sh1918 commented Jun 4, 2026

Copy link
Copy Markdown
Author

Okay i came to it way earlier than expected. I hope i addressed all your concerns.

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. I cherry-picked the commits from there, but will recheck tommorow if everything is fine and resolved since i did this couple of time ago.

Okay should be fine now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature request: build_runner integration

2 participants