From da635b6bebb7ac660f19451469182f54adea884c Mon Sep 17 00:00:00 2001 From: David Ostrovsky Date: Sun, 16 Aug 2026 21:36:13 +0200 Subject: [PATCH] Add header_compiler_direct_opts to java_toolchain Expose an attribute to pass options to the direct header compiler, for example to allow JDK 24+ sun.misc.Unsafe access for TurbineDirect's bundled protobuf (protocolbuffers/protobuf#20760). Options pass through as-is. These are only meaningful for a JVM direct header compiler such as TurbineDirect's deploy jar; a native turbine_direct_graal parses them as Turbine command-line options, which the attribute docs warn against. Closes #374 --- java/common/rules/java_toolchain.bzl | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/java/common/rules/java_toolchain.bzl b/java/common/rules/java_toolchain.bzl index a24ae4f1..a635c5dd 100644 --- a/java/common/rules/java_toolchain.bzl +++ b/java/common/rules/java_toolchain.bzl @@ -91,6 +91,9 @@ def _java_toolchain_impl(ctx): else: header_compiler_direct_data = [] header_compiler_direct_jvm_opts = [] + + header_compiler_direct_jvm_opts = header_compiler_direct_jvm_opts + ctx.attr.header_compiler_direct_opts + if ctx.attr.oneversion_allowlist and ctx.attr.oneversion_whitelist: fail("oneversion_allowlist and oneversion_whitelist are mutually exclusive") oneversion_allowlist = ctx.file.oneversion_allowlist if ctx.file.oneversion_allowlist else ctx.file.oneversion_whitelist @@ -588,6 +591,18 @@ Labels of data available for label-expansion in turbine_jvm_opts. The list of arguments for the JVM when invoking turbine. """, ), + "header_compiler_direct_opts": attr.string_list( + doc = """ +Additional options passed to the direct header compiler, verbatim and without +location or make-variable expansion. + +Warning: these are only meaningful when the direct header compiler runs on a +JVM, such as TurbineDirect's deploy jar. A native direct header compiler such +as turbine_direct_graal parses them as Turbine command-line options, so do not +set JVM options (for example --sun-misc-unsafe-memory-access=allow) when a +native direct header compiler is in use. + """, + ), "xlint": attr.string_list( default = [], doc = """