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

Support for passing extra compiler options #12790

Open
bsravanin opened this issue Apr 15, 2020 · 5 comments
Open

Support for passing extra compiler options #12790

bsravanin opened this issue Apr 15, 2020 · 5 comments
Labels
P4 This is either out of scope or we don't have bandwidth to review a PR. (No assignee) team-Rules-Java Issues for Java rules type: feature request

Comments

@bsravanin
Copy link

Would it be possible to support passing additional compiler options to java_proto_library like in https://docs.bazel.build/versions/master/be/java.html#java_library_args

We find it useful to pass Error-Prone's -XepDisableAllChecks while generating Java code for protos, but haven't figured out how since switching to rules_java.

@dwtj
Copy link

dwtj commented Apr 15, 2020

Is the javacopts attribute what you're looking for? Looks like it is present on the java_library, java_binary and java_test rules.

E.g.

java_library(
    name = "foo",
    srcs = [...],
    javacopts = ["-XepDisableAllChecks"],
)

@jfancher
Copy link

jfancher commented Apr 15, 2020

The question is specifically about java_proto_library, which unfortunately does not have a javacopts attr (perhaps the title should be clarified). Supporting javacopts on that rule would provide a solution -- although perhaps not an ideal one, as you'd have to wrap it in a macro to apply to all libs.

We have a few large proto files that are expensive (>10s) to build, and running errorprone increases the compilation time by about 50%. We expect errorprone to be pointless for such generated code, as well, so this extra time is entirely wasted.

I did find a workaround by digging through Bazel internals: java_toolchain has a hidden attr compatible_javacopts you can use like this:

java_toolchain(
  name = "toolchain_java8",
  compatible_javacopts = {
    "proto": ["-XepDisableAllChecks"],
  },
  ...
}

This seems to do exactly what we want, so it'll do for now.

However, it'd obviously be preferable to have an officially-supported way to do this rather than relying on an internal flag.

@comius comius transferred this issue from bazelbuild/rules_java Jan 8, 2021
@comius comius added P4 This is either out of scope or we don't have bandwidth to review a PR. (No assignee) team-Rules-Java Issues for Java rules labels Jan 8, 2021
@comius
Copy link
Contributor

comius commented Jan 8, 2021

I believe the response in #3427 (comment) should be the preferred way to do this and that it supports your usecase.

@jfancher
Copy link

Unless I am misunderstanding, I don't believe that option would work for us without substantial reorganization unfortunately. We do not put protobuf libraries in separate Bazel packages; they exist side-by-side with code, so package-level configuration wouldn't be sufficient.

@guw
Copy link
Contributor

guw commented Aug 23, 2023

Echoing the need for a way to allow customization of javac options on java_proto_library. Specifically because the generated code causes compile errors/warnings, which we would like to ignore.

We use java_package_configuration to set workspace wide defaults which are more strict. Adding excludes to the package_group used by java_package_configuration is not possible because it doesn't allow to exclude specific targets. It operates at the package level. Thus, it's required to do this at the java_proto_library level where it's needed.

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) team-Rules-Java Issues for Java rules type: feature request
Projects
None yet
Development

No branches or pull requests

6 participants