Getting protoc to work with only direct dependencies is an interesting idea
because it has the potential to meaningfully speed up builds, but as Josh
said, protoc is not currently set up to be able to do that.

I think the way to do this would be to start by calling
AllowUnknownDependencies
<https://github.com/protocolbuffers/protobuf/blob/e5679c01e8f47e8a5e7172444676bda1c2ada875/src/google/protobuf/descriptor.h#L2036>
on the DescriptorPool in protoc. In principle that would allow protoc to
work with only direct dependencies. I tried this once and it didn't
immediately succeed, though, so I suspect it would take a fair bit of work
and experimentation to get something working, and then even more work to
set up Bazel to take advantage of it.

On Wed, Apr 19, 2023 at 8:09 AM 'habe...@google.com' via Protocol Buffers <
protobuf@googlegroups.com> wrote:

> Hi Brandon,
>
> The proto compiler doesn't generally allow what you are asking for. It
> always wants to see the full closure of .proto files.
>
> But if you are writing for Bazel, you shouldn't have to worry about any of
> that. As long as you are on Bazel >=5.3, you can use proto_common to handle
> most of the hard work for you when writing proto rules with aspects.
> proto_common makes it easy to write rules that work like the built-in rules
> cc_proto_library(), java_proto_library(), etc.
>
> There don't seem to be a lot of good documentation or examples for this
> right now. You could take a look at my in-progress CL that migrates to
> using proto_common:
> https://github.com/protocolbuffers/upb/pull/1254/files#diff-6816023f8495e20887edd8410f0348dbf79b27761cd5cf44cbfa6f72389274af
>
> Josh
> On Tuesday, April 18, 2023 at 5:10:15 PM UTC-7 bra...@buildbuddy.io wrote:
>
>> I'm writing a protoc plugin protoc-gen-protobufjs
>> <https://github.com/bduffany/protoc-gen-protobufjs> that is intended as
>> a faster version of protobufjs-cli and which is a better fit for Bazel.
>>
>> I have gotten it working, and am now trying to optimize the build rules a
>> little bit. My understanding is that when compiling a proto file, protoc
>> needs to locate all of the file's transitive dependencies, and gives an
>> error if it can't find one of them.
>>
>> Please correct me if I'm wrong (I'm not a proto expert), but my
>> understanding is that I just need to know about the directly imported
>> protos so that I can tell whether a particular type reference is a message
>> or an enum. So I am wondering if there is a way to tell protoc to not fail
>> if it can't find an indirect import, and instead continue code generation
>> anyway.
>>
>> Thanks!
>>
>> Brandon
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Protocol Buffers" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to protobuf+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/protobuf/5db3ba6d-dec6-4391-af00-2e83ef4445ben%40googlegroups.com
> <https://groups.google.com/d/msgid/protobuf/5db3ba6d-dec6-4391-af00-2e83ef4445ben%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to protobuf+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/protobuf/CADqAXr6%3D913FVWS83Ws%3Df7mTDN4tx1NUCdi9vM_OdORzQ-cURw%40mail.gmail.com.

Reply via email to