google / google/protobuf.dart

Add support for file option: pub_package

Open
#496 0 comments 11 reactions 0 assignees View on GitHub
feature request
Dominant language
Dart
Stars
572
Forks
196
Avg merge
1h 59m
Merged PRs (30d)
2

Description

Other protobuf languages (Go, C++, Java) support custom file scoped generation options. One relevant example is the protobuf file option that Go uses
```protobuf
option go_package = "google.golang.org/protobuf/types/known/emptypb";
```
When users' proto files referencing this proto (in this case google/protobuf/empty.proto) are compiled, they will import the messages (Empty) from this package instead of relative/absolute path.

We can have something similar in Dart. This can help us solve the Well-Known types issue. This will allow us to maintain the generated code for well-known types separately in a pub package which provides additional functionality like the [Go packages provide](https://pkg.go.dev/google.golang.org/protobuf/types/known).

I propose the following file option
```protobuf
option pub_package = "package:proto_known/empty";
```
This needs to be unique for each file even if they belong to the same proto package. The generated code for this file is expected to be found there.

This way we can put all the code required for these types (Eg: Datetime <-> Timestamp) in the a single package and update it as needed. The compiler itself does not need any special information about these types.

#170
#216
#243
#252
#260
#328
#448
https://github.com/protocolbuffers/protobuf/issues/5678

Contributor guide

Open the contributing guide

Research direction

Start by locating the compiler handling for protobuf file-scoped options and the generated Dart import-path logic. Create a proto using option pub_package and verify that generated references resolve to the declared package path, including the proposed well-known-type use case.

Written by the indexing model from the issue text.

Assessment

Tech stack
dart
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.