Skip to content

Bazel: support @generated=omit #11226

Closed
Closed

Description

@ah-quant

Is your feature request related to a problem?

There is currently no simple way to use the (wonderful) new 1.64.0 feature @generated=omit from Bazel. Which leaves Bazel users with a superfluous dependency for a single annotation.

It might be possible to do so with a new toolchain, but that's a lot of effort for a minor feature. If that doesn't work either, it's probably impossible. This might also be related to #11097

Describe the solution you'd like

Either set it to omit by default or add an option to change it.

https://github.com/grpc/grpc-java/blob/v1.64.0/java_grpc_library.bzl#L95 looks like the right place; args.add("--rpc-plugin_opt=@generated={0}".format(<???>)) behind a conditional (only if non-default) should do the trick - with a new attribute in the rules below.

The ..._opt flag to set the CodeGeneratorRequest.parameter for a plugin is not well documented, but is referenced e.g. here: protocolbuffers/protobuf#4759 (comment) (EDIT: a better reference would be https://github.com/protocolbuffers/protobuf/blob/v26.1/src/google/protobuf/compiler/command_line_interface.h#L107-L175)

It can occur more than once. It might even be worth it to also use this instead of the lite/non-lite toolchains.

Describe alternatives you've considered

I tried a .bazelrc entry with build --protocopt=--rpc-plugin_opt=@generated=omit - but that failed. The descriptors are created before the plugin is called, the option is unknown at that point and the command fails.

Additional context

Activity

  1. ejona86 commented on May 21, 2024

    @ejona86
    Member

    I think this is mostly infeasible/not worth the effort. Even without the @Generated annotation, your dependencies wouldn't change and you'd still depend on the old j2ee stuff.

    Yes, with specific toolchain plumbing that could maybe be managed, but that's a lot of effort for this neverlink=1 dependency. It'd be much easier for someone to just pick up #9179.

  2. Hc747 commented on May 22, 2024

    @Hc747

    Picked up #9179 for you here #11215 :)

  3. ejona86 commented on May 22, 2024

    @ejona86
    Member

    @Hc747, please actually read the beginning of #9179. Its title is "Replace javax.annotation.Generated with custom gRPC annotation," which is quite different than that PR.

  4. locked as resolved and limited conversation to collaborators on Aug 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions