@@ -134,3 +134,56 @@ When this name is chosen, part 3 is not needed and should be omitted.
134134Consult source files in the
135135[ examples/helloworld/go] ( ../examples/helloworld/go ) directory
136136for additional information.
137+
138+ ---
139+
140+ ## Well-Known Protobuf Import Mappings
141+
142+ This demonstrates one way to incorporate the so-called * well-known*
143+ protos in your proto definitions. Protoc will look to find the proto
144+ file in the ` google/protobuf/src ` directory in the external workspace.
145+ The ` protoc-gen-go ` plugin then performs the importmapping according
146+ to the ` importmap ` attribute. Pregenerated protobuf dependencies are
147+ provided by the ` @com_github_golang_protobuf ` workspace. A minimally
148+ functional example is provided in
149+ [ examples/wkt/go] ( https://github.com/pubref/rules_protobuf/tree/master/examples/wkt/go ) .
150+
151+ ``` c
152+ // foo.proto
153+ syntax = " proto3" ;
154+ import " {A}" ;
155+ ...
156+ ```
157+
158+ ``` python
159+ # BUILD
160+ go_proto_library(
161+ name = " protolib" ,
162+ protos = [" foo.proto" ],
163+ importmap = {
164+ " {A} " : " github.com/golang/protobuf/{B} " ,
165+ },
166+ imports = [" external/com_github_google_protobuf/src" ],
167+ deps = [
168+ " @com_github_golang_protobuf//:{B} " ,
169+ ],
170+ )
171+ ```
172+
173+ ``` go
174+ // foo.go
175+ import (
176+ " github.com/golang/protobuf/{B}"
177+ )
178+ ```
179+
180+ | Proto Filename (A) | Import Name Suffix and Target Name (B) |
181+ | --- | --- | ----- |
182+ | ` google/protobuf/any.proto ` | ` ptypes/any ` |
183+ | ` google/protobuf/duration.proto ` | ` ptypes/duration ` |
184+ | ` google/protobuf/timestamp.proto ` | ` ptypes/timestamp ` |
185+ | ` google/protobuf/empty.proto ` | ` ptypes/empty ` |
186+ | ` google/protobuf/struct.proto ` | ` ptypes/struct ` |
187+ | ` google/protobuf/wrappers.proto ` | ` ptypes/wrappers ` |
188+ | ` google/protobuf/descriptor.proto ` | ` protoc-gen-go/descriptor ` |
189+ | ` google/protobuf/compiler/plugin.proto ` | ` protoc-gen-go/plugin ` |
0 commit comments