rules_proto_grpc icon indicating copy to clipboard operation
rules_proto_grpc copied to clipboard

Control output path not to include label.package name?

Open dnkoutso opened this issue 3 years ago • 2 comments

Description

We have our own folder structure that we have protos into which is causing an issue with the generated import paths.

e.g. given the following .proto folder structure:

protos/google/protobuf/descriptor.proto
protos/company/common/common.proto (which imports descriptor.proto).

When invoking the rules, they append the package as the output folder from here https://github.com/rules-proto-grpc/rules_proto_grpc/blob/master/internal/common.bzl#L352-L353

e.g

bazel build protos//company/common:common_proto

This causes a failure in the generated #import statements from protoc.

The final output as it is right now is:

out/google/protobuf/_rpg_premerge_descriptor_proto_objc_pb
out/google/protobuf/google/protobuf/.h,.m
out/company/common/_rpg_premerge_common_proto_objc_pb
out/company/common/company/common/.h.m

However the imports protoc outputs are all relative to the structure we use so it the case above it outputs #import "../../google/protobuf" which fails compilation for common proto given the output folder structure the rules_proto_grpc use.

What we want is:

out/google/protobuf/_rpg_premerge_descriptor_proto_objc_pb/...
out/google/protobuf/.h,.m # <----- 
out/company/common/_rpg_premerge_common_proto_objc_pb/...
out/company/common/.h.m # <-----

Is there a workaround or something we are missing in achieving this?

dnkoutso avatar Feb 09 '22 18:02 dnkoutso

How are you using the generated Obj-C library? If you are using objc_proto_library, the target should have the correct includes attr to ensure the generated imports are valid when used from a downstream objc_library.

aaliddell avatar Feb 13 '22 21:02 aaliddell

@aaliddell we use objc_proto_compile and feed that into an apple_framework from https://github.com/bazel-ios/rules_ios.

Not sure if its happening because of that or not, I should try to get you a sample scenario perhaps to demonstrate it...

dnkoutso avatar Aug 24 '22 05:08 dnkoutso

This issue has been automatically closed because there has been no response to our request for more information from the original author. With only the information that is currently in the issue, we don't have enough information to take action. Please reach out if you have or find the answers we need so that we can investigate further.

github-actions[bot] avatar Oct 29 '22 20:10 github-actions[bot]

So the way this works internally is that the objc_proto_library is setting the includes attr correctly to hide the label name:

https://github.com/rules-proto-grpc/rules_proto_grpc/blob/58f568397f3707e072c3e94493c380edea04337c/objc/objc_grpc_library.bzl#L38

Looking into rules_ios it appears you might be able to propagate that attr through the kwargs, so you could try:

apple_framework(
    name = "something",
    includes = ["something_pb"],
    ...
)

Otherwise, you could try using objc_proto_library from these rules and pass the library to the deps attr of apple_framework, but that might complain about having no srcs.

aaliddell avatar Dec 01 '22 13:12 aaliddell