Skip to content

Commit

Permalink
Use target_compatible_with for Java runtimes
Browse files Browse the repository at this point in the history
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
Change-Id: I97ab530c56047b780b1a2170937ddf162660840b
  • Loading branch information
cushon authored and copybara-github committed Feb 7, 2022
1 parent fcfe24e commit 338c418
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 28 deletions.
46 changes: 23 additions & 23 deletions java/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def remote_jdk8_repos(name = ""):
maybe(
remote_java_repository,
name = "remote_jdk8_linux_aarch64",
exec_compatible_with = [
target_compatible_with = [
"@platforms//os:linux",
"@platforms//cpu:aarch64",
],
Expand All @@ -100,7 +100,7 @@ def remote_jdk8_repos(name = ""):
maybe(
remote_java_repository,
name = "remote_jdk8_linux",
exec_compatible_with = [
target_compatible_with = [
"@platforms//os:linux",
"@platforms//cpu:x86_64",
],
Expand All @@ -115,7 +115,7 @@ def remote_jdk8_repos(name = ""):
maybe(
remote_java_repository,
name = "remote_jdk8_macos",
exec_compatible_with = [
target_compatible_with = [
"@platforms//os:macos",
"@platforms//cpu:x86_64",
],
Expand All @@ -130,7 +130,7 @@ def remote_jdk8_repos(name = ""):
maybe(
remote_java_repository,
name = "remote_jdk8_windows",
exec_compatible_with = [
target_compatible_with = [
"@platforms//os:windows",
"@platforms//cpu:x86_64",
],
Expand All @@ -156,7 +156,7 @@ def remote_jdk11_repos():
maybe(
remote_java_repository,
name = "remotejdk11_linux",
exec_compatible_with = [
target_compatible_with = [
"@platforms//os:linux",
"@platforms//cpu:x86_64",
],
Expand All @@ -171,7 +171,7 @@ def remote_jdk11_repos():
maybe(
remote_java_repository,
name = "remotejdk11_linux_aarch64",
exec_compatible_with = [
target_compatible_with = [
"@platforms//os:linux",
"@platforms//cpu:aarch64",
],
Expand All @@ -186,7 +186,7 @@ def remote_jdk11_repos():
maybe(
remote_java_repository,
name = "remotejdk11_linux_ppc64le",
exec_compatible_with = [
target_compatible_with = [
"@platforms//os:linux",
"@platforms//cpu:ppc",
],
Expand All @@ -202,7 +202,7 @@ def remote_jdk11_repos():
maybe(
remote_java_repository,
name = "remotejdk11_linux_s390x",
exec_compatible_with = [
target_compatible_with = [
"@platforms//os:linux",
"@platforms//cpu:s390x",
],
Expand All @@ -218,7 +218,7 @@ def remote_jdk11_repos():
maybe(
remote_java_repository,
name = "remotejdk11_macos",
exec_compatible_with = [
target_compatible_with = [
"@platforms//os:macos",
"@platforms//cpu:x86_64",
],
Expand All @@ -233,7 +233,7 @@ def remote_jdk11_repos():
maybe(
remote_java_repository,
name = "remotejdk11_macos_aarch64",
exec_compatible_with = [
target_compatible_with = [
"@platforms//os:macos",
"@platforms//cpu:aarch64",
],
Expand All @@ -249,7 +249,7 @@ def remote_jdk11_repos():
maybe(
remote_java_repository,
name = "remotejdk11_win",
exec_compatible_with = [
target_compatible_with = [
"@platforms//os:windows",
"@platforms//cpu:x86_64",
],
Expand All @@ -266,7 +266,7 @@ def remote_jdk15_repos():
maybe(
remote_java_repository,
name = "remotejdk15_linux",
exec_compatible_with = [
target_compatible_with = [
"@platforms//os:linux",
"@platforms//cpu:x86_64",
],
Expand All @@ -282,7 +282,7 @@ def remote_jdk15_repos():
maybe(
remote_java_repository,
name = "remotejdk15_macos",
exec_compatible_with = [
target_compatible_with = [
"@platforms//os:macos",
"@platforms//cpu:x86_64",
],
Expand All @@ -298,7 +298,7 @@ def remote_jdk15_repos():
maybe(
remote_java_repository,
name = "remotejdk15_macos_aarch64",
exec_compatible_with = [
target_compatible_with = [
"@platforms//os:macos",
"@platforms//cpu:aarch64",
],
Expand All @@ -314,7 +314,7 @@ def remote_jdk15_repos():
maybe(
remote_java_repository,
name = "remotejdk15_win",
exec_compatible_with = [
target_compatible_with = [
"@platforms//os:windows",
"@platforms//cpu:x86_64",
],
Expand All @@ -332,7 +332,7 @@ def remote_jdk16_repos():
maybe(
remote_java_repository,
name = "remotejdk16_linux",
exec_compatible_with = [
target_compatible_with = [
"@platforms//os:linux",
"@platforms//cpu:x86_64",
],
Expand All @@ -348,7 +348,7 @@ def remote_jdk16_repos():
maybe(
remote_java_repository,
name = "remotejdk16_macos",
exec_compatible_with = [
target_compatible_with = [
"@platforms//os:macos",
"@platforms//cpu:x86_64",
],
Expand All @@ -364,7 +364,7 @@ def remote_jdk16_repos():
maybe(
remote_java_repository,
name = "remotejdk16_macos_aarch64",
exec_compatible_with = [
target_compatible_with = [
"@platforms//os:macos",
"@platforms//cpu:aarch64",
],
Expand All @@ -380,7 +380,7 @@ def remote_jdk16_repos():
maybe(
remote_java_repository,
name = "remotejdk16_win",
exec_compatible_with = [
target_compatible_with = [
"@platforms//os:windows",
"@platforms//cpu:x86_64",
],
Expand All @@ -398,7 +398,7 @@ def remote_jdk17_repos():
maybe(
remote_java_repository,
name = "remotejdk17_linux",
exec_compatible_with = [
target_compatible_with = [
"@platforms//os:linux",
"@platforms//cpu:x86_64",
],
Expand All @@ -414,7 +414,7 @@ def remote_jdk17_repos():
maybe(
remote_java_repository,
name = "remotejdk17_macos",
exec_compatible_with = [
target_compatible_with = [
"@platforms//os:macos",
"@platforms//cpu:x86_64",
],
Expand All @@ -430,7 +430,7 @@ def remote_jdk17_repos():
maybe(
remote_java_repository,
name = "remotejdk17_macos_aarch64",
exec_compatible_with = [
target_compatible_with = [
"@platforms//os:macos",
"@platforms//cpu:aarch64",
],
Expand All @@ -446,7 +446,7 @@ def remote_jdk17_repos():
maybe(
remote_java_repository,
name = "remotejdk17_win",
exec_compatible_with = [
target_compatible_with = [
"@platforms//os:windows",
"@platforms//cpu:x86_64",
],
Expand Down
10 changes: 5 additions & 5 deletions toolchains/remote_java_repository.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@ _toolchain_config = repository_rule(
},
)

def remote_java_repository(name, version, exec_compatible_with, prefix = "remotejdk", **kwargs):
def remote_java_repository(name, version, target_compatible_with = None, prefix = "remotejdk", **kwargs):
"""Imports and registers a JDK from a http archive.
Toolchain resolution is determined with exec_compatible_with
Toolchain resolution is determined with target_compatible_with
parameter and constrained with --java_runtime_version flag either having value
of "version" or "{prefix}_{version}" parameters.
Args:
name: A unique name for this rule.
version: Version of the JDK imported.
exec_compatible_with: Platform constraints (CPU and OS) for this JDK.
target_compatible_with: Target platform constraints (CPU and OS) for this JDK.
prefix: Optional alternative prefix for configuration flag value used to determine this JDK.
**kwargs: Refer to http_archive documentation
"""
Expand Down Expand Up @@ -73,15 +73,15 @@ alias(
)
toolchain(
name = "toolchain",
exec_compatible_with = {exec_compatible_with},
target_compatible_with = {target_compatible_with},
target_settings = [":version_or_prefix_version_setting"],
toolchain_type = "@bazel_tools//tools/jdk:runtime_toolchain_type",
toolchain = "{toolchain}",
)
""".format(
prefix = prefix,
version = version,
exec_compatible_with = exec_compatible_with,
target_compatible_with = target_compatible_with,
toolchain = "@{repo}//:jdk".format(repo = name),
),
)

0 comments on commit 338c418

Please sign in to comment.