Skip to content

Commit d5559c1

Browse files
cushoncopybara-github
authored andcommitted
Use target_compatible_with for Java runtimes
The JDK is a runtime. Actions like `java_binary` output an executable that contains a JDK in its runfiles, and that JDK needs to be compatible with the target platform. (Actions like `genrule` that execute the JDK can depend on the JDK as a `tool`, which does an explicit transition to the `exec` platform.) PiperOrigin-RevId: 426995073
1 parent 2eabd8d commit d5559c1

3 files changed

Lines changed: 17 additions & 17 deletions

File tree

site/docs/bazel-and-java.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ remote_java_repository(
181181
name = "openjdk_canary_linux_arm",
182182
prefix = "openjdk_canary", # Can be used with --java_runtime_version=openjdk_canary_11
183183
version = "11", # or --java_runtime_version=11
184-
exec_compatible_with = [ # Specifies constraints this JVM is compatible with "@platforms//cpu:arm",
184+
target_compatible_with = [ # Specifies constraints this JVM is compatible with "@platforms//cpu:arm",
185185
"@platforms//os:linux",
186186
],
187187
urls = ..., # Other parameters are from http_repository rule.

src/main/java/com/google/devtools/build/lib/bazel/rules/java/jdk.WORKSPACE.tmpl

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ maybe(
2121
maybe(
2222
remote_java_repository,
2323
{remotejdk11_linux}
24-
exec_compatible_with = [
24+
target_compatible_with = [
2525
"@platforms//os:linux",
2626
"@platforms//cpu:x86_64",
2727
],
@@ -32,7 +32,7 @@ maybe(
3232
maybe(
3333
remote_java_repository,
3434
{remotejdk11_linux_aarch64}
35-
exec_compatible_with = [
35+
target_compatible_with = [
3636
"@platforms//os:linux",
3737
"@platforms//cpu:aarch64",
3838
],
@@ -43,7 +43,7 @@ maybe(
4343
maybe(
4444
remote_java_repository,
4545
{remotejdk11_linux_ppc64le}
46-
exec_compatible_with = [
46+
target_compatible_with = [
4747
"@platforms//os:linux",
4848
"@platforms//cpu:ppc",
4949
],
@@ -54,7 +54,7 @@ maybe(
5454
maybe(
5555
remote_java_repository,
5656
{remotejdk11_linux_s390x}
57-
exec_compatible_with = [
57+
target_compatible_with = [
5858
"@platforms//os:linux",
5959
"@platforms//cpu:s390x",
6060
],
@@ -65,7 +65,7 @@ maybe(
6565
maybe(
6666
remote_java_repository,
6767
{remotejdk11_macos}
68-
exec_compatible_with = [
68+
target_compatible_with = [
6969
"@platforms//os:macos",
7070
"@platforms//cpu:x86_64",
7171
],
@@ -76,7 +76,7 @@ maybe(
7676
maybe(
7777
remote_java_repository,
7878
{remotejdk11_macos_aarch64}
79-
exec_compatible_with = [
79+
target_compatible_with = [
8080
"@platforms//os:macos",
8181
"@platforms//cpu:aarch64",
8282
],
@@ -87,7 +87,7 @@ maybe(
8787
maybe(
8888
remote_java_repository,
8989
{remotejdk11_win}
90-
exec_compatible_with = [
90+
target_compatible_with = [
9191
"@platforms//os:windows",
9292
"@platforms//cpu:x86_64",
9393
],
@@ -98,7 +98,7 @@ maybe(
9898
maybe(
9999
remote_java_repository,
100100
{remotejdk17_linux}
101-
exec_compatible_with = [
101+
target_compatible_with = [
102102
"@platforms//os:linux",
103103
"@platforms//cpu:x86_64",
104104
],
@@ -109,7 +109,7 @@ maybe(
109109
maybe(
110110
remote_java_repository,
111111
{remotejdk17_macos}
112-
exec_compatible_with = [
112+
target_compatible_with = [
113113
"@platforms//os:macos",
114114
"@platforms//cpu:x86_64",
115115
],
@@ -120,7 +120,7 @@ maybe(
120120
maybe(
121121
remote_java_repository,
122122
{remotejdk17_macos_aarch64}
123-
exec_compatible_with = [
123+
target_compatible_with = [
124124
"@platforms//os:macos",
125125
"@platforms//cpu:aarch64",
126126
],
@@ -131,7 +131,7 @@ maybe(
131131
maybe(
132132
remote_java_repository,
133133
{remotejdk17_win}
134-
exec_compatible_with = [
134+
target_compatible_with = [
135135
"@platforms//os:windows",
136136
"@platforms//cpu:x86_64",
137137
],

tools/jdk/remote_java_repository.bzl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,17 @@ _toolchain_config = repository_rule(
3131
},
3232
)
3333

34-
def remote_java_repository(name, version, exec_compatible_with, prefix = "remotejdk", **kwargs):
34+
def remote_java_repository(name, version, target_compatible_with = None, prefix = "remotejdk", **kwargs):
3535
"""Imports and registers a JDK from a http archive.
3636
37-
Toolchain resolution is determined with exec_compatible_with
37+
Toolchain resolution is determined with target_compatible_with
3838
parameter and constrained with --java_runtime_version flag either having value
3939
of "version" or "{prefix}_{version}" parameters.
4040
4141
Args:
4242
name: A unique name for this rule.
4343
version: Version of the JDK imported.
44-
exec_compatible_with: Platform constraints (CPU and OS) for this JDK.
44+
target_compatible_with: Target platform constraints (CPU and OS) for this JDK.
4545
prefix: Optional alternative prefix for configuration flag value used to determine this JDK.
4646
**kwargs: Refer to http_archive documentation
4747
"""
@@ -73,15 +73,15 @@ alias(
7373
)
7474
toolchain(
7575
name = "toolchain",
76-
exec_compatible_with = {exec_compatible_with},
76+
target_compatible_with = {target_compatible_with},
7777
target_settings = [":version_or_prefix_version_setting"],
7878
toolchain_type = "@bazel_tools//tools/jdk:runtime_toolchain_type",
7979
toolchain = "{toolchain}",
8080
)
8181
""".format(
8282
prefix = prefix,
8383
version = version,
84-
exec_compatible_with = exec_compatible_with,
84+
target_compatible_with = target_compatible_with,
8585
toolchain = "@{repo}//:jdk".format(repo = name),
8686
),
8787
)

0 commit comments

Comments
 (0)