Add a `java_toolchain` attribute to specify options to the `header_compiler_direct` tool (#375)

Primary motivation is to let users not using the Turbine graal native image silence protobuf sun.misc.Unsafe warnings from the direct header compiler

turbine_direct (header_compiler_direct) bundles protobuf, whose UnsafeUtil calls terminally-deprecated sun.misc.Unsafe methods. On JDK 24+ (JEP 498) the JVM prints a warning for each such call during header compilation:

  WARNING: A terminally deprecated method in sun.misc.Unsafe has been called
  WARNING: sun.misc.Unsafe::arrayBaseOffset has been called by
  com.google.protobuf.UnsafeUtil (.../java_tools/turbine_direct_binary_deploy.jar)

Unlike the Turbine worker, header_compiler_direct does not receive turbine_jvm_opts, and --jvmopt does not reach header-compilation actions, so a toolchain currently has no way to silence these warnings for the direct header compiler. Add --sun-misc-unsafe-memory-access=allow to header_compiler_direct_jvm_opts, gated on the runtime feature version since the flag is rejected on JDK <= 22.

See https://github.com/protocolbuffers/protobuf/issues/20760.

Fixes #374

Closes #375

COPYBARA_INTEGRATE_REVIEW=https://github.com/bazelbuild/rules_java/pull/375 from davido:turbine-direct-unsafe-memory-access da635b6bebb7ac660f19451469182f54adea884c
PiperOrigin-RevId: 968352943
Change-Id: I94d5bc5d564016ced3cc3b6e06330fad4d8451a7
1 file changed
tree: e31667df676c1dd6d509d62352e06ab03b8c14fe
  1. .bazel_checkout/
  2. .bazelci/
  3. .bcr/
  4. .github/
  5. distro/
  6. examples/
  7. java/
  8. test/
  9. third_party/
  10. toolchains/
  11. .bazelignore
  12. .bazelrc
  13. .gitignore
  14. AUTHORS
  15. BUILD
  16. CODEOWNERS
  17. CONTRIBUTING.md
  18. LICENSE
  19. MODULE.bazel
  20. README.md
  21. renovate.json
  22. WORKSPACE
  23. WORKSPACE.bzlmod
README.md

rules_java

Build status

Java Rules for Bazel https://bazel.build.

Documentation

For a quickstart tutorial, see https://bazel.build/start/java

The fastest way to try this in an empty project is to click the green “Use this template” button on https://github.com/bazel-starters/java.

For slightly more advanced usage, like setting up toolchains or writing your own java-like rules, see https://bazel.build/docs/bazel-and-java

Core Java rules

Add a load like:

load("@rules_java//java:java_library.bzl", "java_library")

to your BUILD / BUILD.bazel / *.bzl files

For detailed docs on the core rules, see https://bazel.build/reference/be/java