Skip to content

Commit

Permalink
Make rules_java backwards compatible with Bazel 6.3.0
Browse files Browse the repository at this point in the history
Copybara Import from #210

BEGIN_PUBLIC
Make rules_java backwards compatible with Bazel 6.3.0 (#210)

Move bootstrap_toolchain_type into rules_java. There are no uses outside
of rules_java. This fixes compatiblity with Bazel 6.3.0, which doesn't
have the definition.

Add back `_allowlist_function_transition`. Older versions of Bazel require it.

Add Bazel 6.3.0 to the CI.

Remove a couple of broken targets from toolchains/BUILD. Those were
broken becuase old JDKs were removed.

Closes #210
END_PUBLIC

COPYBARA_INTEGRATE_REVIEW=#210 from comius:backward-compatible-rules_java 393f270
PiperOrigin-RevId: 670415171
Change-Id: I7f42cc92bb7285cb51a2a1185695451a644d5b30
  • Loading branch information
comius authored and copybara-github committed Sep 3, 2024
1 parent 2392b24 commit 30ecf3f
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 22 deletions.
17 changes: 16 additions & 1 deletion .bazelci/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,19 @@ tasks:
platform: windows
build_flags:
- "--config=bzlmod"
build_targets: *build_targets_bzlmod
build_targets: *build_targets_bzlmod
ubuntu2004_bazel630:
name: "Bazel 6.3.0"
bazel: 6.3.0
platform: ubuntu2004
build_targets: *build_targets
macos_bazel630:
name: "Bazel 6.3.0"
bazel: 6.3.0
platform: macos
build_targets: *build_targets
windows_bazel630:
name: "Bazel 6.3.0"
bazel: 6.3.0
platform: windows
build_targets: *build_targets
1 change: 0 additions & 1 deletion .bazelversion

This file was deleted.

3 changes: 1 addition & 2 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
module(
name = "rules_java",
version = "7.9.1",
# Requires @bazel_tools//tools/jdk:bootstrap_runtime_toolchain_type.
bazel_compatibility = [">=7.0.0"],
bazel_compatibility = [">=6.2.0"],
compatibility_level = 1,
)

Expand Down
16 changes: 2 additions & 14 deletions toolchains/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ filegroup(
#
# Toolchains of this type are only consumed internally by the bootclasspath rule and should not be
# accessed from Starlark.
# TODO: migrate away from using @bazel_tools//tools/jdk:bootstrap_runtime_toolchain_type ?
# toolchain_type(name = "bootstrap_runtime_toolchain_type")

toolchain_type(name = "bootstrap_runtime_toolchain_type")

# Points to toolchain[":runtime_toolchain_type"] (was :legacy_current_java_runtime)
java_runtime_alias(name = "current_java_runtime")
Expand Down Expand Up @@ -293,18 +293,6 @@ java_runtime_version_alias(
visibility = ["//visibility:public"],
)

java_runtime_version_alias(
name = "remotejdk_15",
runtime_version = "remotejdk_15",
visibility = ["//visibility:public"],
)

java_runtime_version_alias(
name = "remotejdk_16",
runtime_version = "remotejdk_16",
visibility = ["//visibility:public"],
)

java_runtime_version_alias(
name = "remotejdk_17",
runtime_version = "remotejdk_17",
Expand Down
2 changes: 1 addition & 1 deletion toolchains/default_java_toolchain.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def java_runtime_files(name, srcs):
tags = ["manual"],
)

_JAVA_BOOTSTRAP_RUNTIME_TOOLCHAIN_TYPE = Label("@bazel_tools//tools/jdk:bootstrap_runtime_toolchain_type")
_JAVA_BOOTSTRAP_RUNTIME_TOOLCHAIN_TYPE = Label("//toolchains:bootstrap_runtime_toolchain_type")

# Opt the Java bootstrap actions into path mapping:
# https://github.com/bazelbuild/bazel/commit/a239ea84832f18ee8706682145e9595e71b39680
Expand Down
3 changes: 3 additions & 0 deletions toolchains/java_toolchain_alias.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ java_runtime_version_alias = rule(
toolchains = ["@bazel_tools//tools/jdk:runtime_toolchain_type"],
attrs = {
"runtime_version": attr.string(mandatory = True),
"_allowlist_function_transition": attr.label(
default = "@bazel_tools//tools/allowlists/function_transition_allowlist",
),
},
cfg = _java_runtime_transition,
)
Expand Down
4 changes: 2 additions & 2 deletions toolchains/local_java_repository.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def local_java_runtime(name, java_home, version, runtime_name = None, visibility
native.toolchain(
name = "bootstrap_runtime_toolchain_definition",
target_settings = [":%s_settings_alias" % name],
toolchain_type = Label("@bazel_tools//tools/jdk:bootstrap_runtime_toolchain_type"),
toolchain_type = Label("//toolchains:bootstrap_runtime_toolchain_type"),
toolchain = runtime_name,
)

Expand Down Expand Up @@ -268,7 +268,7 @@ toolchain(
toolchain(
name = "bootstrap_runtime_toolchain_definition",
target_settings = [":localjdk_setting"],
toolchain_type = "@bazel_tools//tools/jdk:bootstrap_runtime_toolchain_type",
toolchain_type = "@rules_java//tools/jdk:bootstrap_runtime_toolchain_type",
toolchain = ":jdk",
)
'''
Expand Down
2 changes: 1 addition & 1 deletion toolchains/remote_java_repository.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ toolchain(
# the same configuration, this constraint will not result in toolchain resolution failures.
exec_compatible_with = {target_compatible_with},
target_settings = [":version_or_prefix_version_setting"],
toolchain_type = "@bazel_tools//tools/jdk:bootstrap_runtime_toolchain_type",
toolchain_type = "@rules_java//toolchains:bootstrap_runtime_toolchain_type",
toolchain = "{toolchain}",
)
""".format(
Expand Down

0 comments on commit 30ecf3f

Please sign in to comment.