feat(compiler): add dart unary gRPC codegen#3723
Open
yash-agarwa-l wants to merge 11 commits into
Open
Conversation
Wire DartServiceGeneratorMixin into DartGenerator via MRO matching JavaGenerator and PythonGenerator. The mixin currently exposes only the streaming-rejection check, which raises ValueError listing every offending method when an FDL service contains stream RPCs. File emission and Client/ServiceBase generation land in follow-up commits.
Add generate_grpc_module to DartServiceGeneratorMixin: emits a <stem>_grpc.dart companion next to the messages file with Apache header, dart:async/dart:typed_data/package:grpc imports, a sibling import of the messages module as _models, and the two top-level codec helpers (_serialize<T> and _deserialize<T>) that route through the existing ForyRegistration.getFory() static. _deserialize includes the is-Uint8List guard for zero-copy on the common HTTP/2 path.
Emit per-service Client with ClientMethod constants and $createUnaryCall-backed unary methods. Constructor uses super-parameter syntax confirmed by grpc 4.3.1's in-tree TestClient(super.channel). Method names are normalized through safe_identifier(to_camel_case(method.name)).
Emit <Service>ServiceBase: registers each unary RPC via $addMethod in the constructor and exposes an abstract handler per method. Uses a _Pre shim that awaits the request Future before dispatching, since grpc-dart's ServiceMethod always hands the handler a Future<Q>
Add check_dart_grpc_service_collisions to the mixin. For each local service, compute its emitted Client and ServiceBase class names and check against the set of top-level names DartGenerator would already emit for messages/enums/unions/registration. Also detect service<->service collisions when two services in the same schema would emit the same Client/ServiceBase name. Raises ValueError naming the offending class; the CLI's existing ValueError wrap at cli.py:686-690 prints it and exits non-zero.
Add check_dart_grpc_method_collisions. For each service, normalize every method name through safe_identifier(to_camel_case(name)) and raise ValueError if two distinct RpcMethod names collapse to the same Dart identifier (e.g. SayHello and say_hello both produce sayHello).
Mirror Python's test_proto_and_fbs_grpc_service_codegen: one test exercises a .proto-sourced service through ProtoTranslator and a .fbs-sourced service through FbsTranslator, then asserts both end up in the Dart gRPC emitter with the right method paths and Client classes. Confirms no Dart-specific translator wiring was needed.
Register DartGenerator in GENERATOR_CLASSES and add it to the gRPC-supported skip in the unsupported-generators test.
Emit _grpc.dart under the same package directory as the messages file. Add opt-in dart analyze gate covering the emitted file.
dart format reflowed the ClientMethod constant and $addMethod call; align emitter strings with format output and add a dart format gate to the smoke test.
Collaborator
|
Could you add java-dart grpc integration tests? You can take #3692 as reference |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why?
Dart users need gRPC support from FDL/proto/fbs schemas
What does this PR do?
Adds DartServiceGeneratorMixin so foryc --grpc --dart_out=… emits a /_grpc.dart next to the messages file. Includes:
Related issues
Part of #3266
AI Contribution Checklist
yes/noyes, I included a completed AI Contribution Checklist in this PR description and the requiredAI Usage Disclosure.yes, my PR description includes the requiredai_reviewsummary and screenshot evidence of the final clean AI review results from both fresh reviewers on the current PR diff or current HEAD after the latest code changes.Does this PR introduce any user-facing change?
Benchmark