Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a rule for encoding textprotos #122

Open
davidgiven opened this issue Jun 4, 2022 · 0 comments
Open

Add a rule for encoding textprotos #122

davidgiven opened this issue Jun 4, 2022 · 0 comments
Labels
P4 This is either out of scope or we don't have bandwidth to review a PR. (No assignee)

Comments

@davidgiven
Copy link

i.e. the equivalent of protoc --encode=$MESSAGETYPE. This is useful when embedding binary protos in applications. Something like:

proto_encode(
    name = "encoded",
    src = "something.textproto",
    message = "foo.bar.ThingProto",
    deps = [ ":library_proto" ]
)

This can already be implemented with something like this:

def proto_encode(name, src, message, proto, deps=[]):
    native.genrule(
        name = name,
        srcs = [ src ] + deps,
        outs = [ name + ".binpb" ],
        cmd = "protoc --encode={} --descriptor_set_in={} {} < $(location {}) > $@".format(
            message, ":".join(["$(location {})".format(n) for n in deps]), proto, src)
    )

However, this is very clunky: it requires a hard-coded dependency on the system proto compiler rather than using the same one by the rest of the Bazel stuff (I can't tell if this is exposed anywhere?), and it also requires the author to explicitly pass in the filename of the proto being encoded as well as the message name. This violates layering as the consumer of the proto library shouldn't need to know about the filenames of the source files inside the proto library. Having some bazel magic to make this convenient would be, well, very convenient.

@comius comius added the P4 This is either out of scope or we don't have bandwidth to review a PR. (No assignee) label Jun 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P4 This is either out of scope or we don't have bandwidth to review a PR. (No assignee)
Projects
None yet
Development

No branches or pull requests

2 participants