Skip to content

Commit 27fe30b

Browse files
tshaynikcopybara-github
authored andcommitted
Expose compatibility arguments on java toolchains
This change allows providing the `exec_compatibility_with` and `target_compatibility_with` arguments to native.toolchain from invocations of the local_java_runtime and default_java_toolchain. This is useful for setting constraints on javatoolchains. With the default arguments provided, this does not break the API of these functions. Closes #16497 Closes #16498. PiperOrigin-RevId: 489481041 Change-Id: I324decf299cd9fbb679afa48e0461a0f535ce1e3
1 parent 8349c95 commit 27fe30b

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

tools/jdk/default_java_toolchain.bzl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ NONPREBUILT_TOOLCHAIN_CONFIGURATION = dict(
139139
java_runtime = "@bazel_tools//tools/jdk:remote_jdk11",
140140
)
141141

142-
def default_java_toolchain(name, configuration = DEFAULT_TOOLCHAIN_CONFIGURATION, toolchain_definition = True, **kwargs):
142+
def default_java_toolchain(name, configuration = DEFAULT_TOOLCHAIN_CONFIGURATION, toolchain_definition = True, exec_compatible_with = [], target_compatible_with = [], **kwargs):
143143
"""Defines a remote java_toolchain with appropriate defaults for Bazel."""
144144

145145
toolchain_args = dict(_BASE_TOOLCHAIN_CONFIGURATION)
@@ -160,6 +160,8 @@ def default_java_toolchain(name, configuration = DEFAULT_TOOLCHAIN_CONFIGURATION
160160
toolchain_type = "@bazel_tools//tools/jdk:toolchain_type",
161161
target_settings = [name + "_version_setting"],
162162
toolchain = name,
163+
exec_compatible_with = exec_compatible_with,
164+
target_compatible_with = target_compatible_with,
163165
)
164166

165167
def java_runtime_files(name, srcs):

tools/jdk/local_java_repository.bzl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def _detect_java_version(repository_ctx, java_bin):
3838
return minor
3939
return major
4040

41-
def local_java_runtime(name, java_home, version, runtime_name = None, visibility = ["//visibility:public"]):
41+
def local_java_runtime(name, java_home, version, runtime_name = None, visibility = ["//visibility:public"], exec_compatible_with = [], target_compatible_with = []):
4242
"""Defines a java_runtime target together with Java runtime and compile toolchain definitions.
4343
4444
Java runtime toolchain is constrained by flag --java_runtime_version having
@@ -102,6 +102,8 @@ def local_java_runtime(name, java_home, version, runtime_name = None, visibility
102102
source_version = str(version),
103103
target_version = str(version),
104104
java_runtime = runtime_name,
105+
exec_compatible_with = exec_compatible_with,
106+
target_compatible_with = target_compatible_with,
105107
)
106108

107109
# else version is not recognized and no compilation toolchains are predefined

0 commit comments

Comments
 (0)