Define the Java toolchain types in rules_java (#392) Defines `//toolchains:toolchain_type`, `:runtime_toolchain_type` and `:bootstrap_runtime_toolchain_type` as the actual toolchain types rather than aliases into `@bazel_tools`, conditional on a `bazel_features` feature that is always `False` for now. https://github.com/bazelbuild/bazel/pull/32196 will allow them to be flipped over. Until then and on all older versions they are aliases of the types in `@bazel_tools`, so both labels always refer to the same type. Work towards bazelbuild/bazel#32428 Closes #392 COPYBARA_INTEGRATE_REVIEW=https://github.com/bazelbuild/rules_java/pull/392 from fmeum:java-toolchain-types 41f05fc81aba83ee0b317c07ccc87b60d8295690 PiperOrigin-RevId: 1022628752 Change-Id: I8a330969a62951cec2db1484cee3a6a658b2e119
diff --git a/MODULE.bazel b/MODULE.bazel index 13d44ed..28bfa5b 100644 --- a/MODULE.bazel +++ b/MODULE.bazel
@@ -6,7 +6,7 @@ bazel_dep(name = "platforms", version = "0.0.11") bazel_dep(name = "rules_cc", version = "0.2.25") -bazel_dep(name = "bazel_features", version = "1.30.0") +bazel_dep(name = "bazel_features", version = "1.55.0") bazel_dep(name = "bazel_skylib", version = "1.6.1") bazel_dep(name = "protobuf", version = "32.1", repo_name = "com_google_protobuf") bazel_dep(name = "zlib", version = "1.3.1.bcr.5")
diff --git a/WORKSPACE b/WORKSPACE index 475e9ef..f0bc662 100644 --- a/WORKSPACE +++ b/WORKSPACE
@@ -39,9 +39,9 @@ http_archive( name = "bazel_features", - sha256 = "a660027f5a87f13224ab54b8dc6e191693c554f2692fcca46e8e29ee7dabc43b", - strip_prefix = "bazel_features-1.30.0", - url = "https://github.com/bazel-contrib/bazel_features/releases/download/v1.30.0/bazel_features-v1.30.0.tar.gz", + sha256 = "2ed1fdce7e51ba2149dfab73eab6e402217c8e27d17e1d4a48d4d86bdd9eaef6", + strip_prefix = "bazel_features-1.55.0", + url = "https://github.com/bazel-contrib/bazel_features/releases/download/v1.55.0/bazel_features-v1.55.0.tar.gz", ) load("@bazel_features//:deps.bzl", "bazel_features_deps")
diff --git a/distro/relnotes.bzl b/distro/relnotes.bzl index e47c3c9..7976204 100644 --- a/distro/relnotes.bzl +++ b/distro/relnotes.bzl
@@ -41,9 +41,9 @@ http_archive( name = "bazel_features", - sha256 = "a660027f5a87f13224ab54b8dc6e191693c554f2692fcca46e8e29ee7dabc43b", - strip_prefix = "bazel_features-1.30.0", - url = "https://github.com/bazel-contrib/bazel_features/releases/download/v1.30.0/bazel_features-v1.30.0.tar.gz", + sha256 = "2ed1fdce7e51ba2149dfab73eab6e402217c8e27d17e1d4a48d4d86bdd9eaef6", + strip_prefix = "bazel_features-1.55.0", + url = "https://github.com/bazel-contrib/bazel_features/releases/download/v1.55.0/bazel_features-v1.55.0.tar.gz", ) load("@bazel_features//:deps.bzl", "bazel_features_deps")
diff --git a/test/repo/WORKSPACE b/test/repo/WORKSPACE index a100961..3d18336 100644 --- a/test/repo/WORKSPACE +++ b/test/repo/WORKSPACE
@@ -9,9 +9,9 @@ http_archive( name = "bazel_features", - sha256 = "a660027f5a87f13224ab54b8dc6e191693c554f2692fcca46e8e29ee7dabc43b", - strip_prefix = "bazel_features-1.30.0", - url = "https://github.com/bazel-contrib/bazel_features/releases/download/v1.30.0/bazel_features-v1.30.0.tar.gz", + sha256 = "2ed1fdce7e51ba2149dfab73eab6e402217c8e27d17e1d4a48d4d86bdd9eaef6", + strip_prefix = "bazel_features-1.55.0", + url = "https://github.com/bazel-contrib/bazel_features/releases/download/v1.55.0/bazel_features-v1.55.0.tar.gz", ) load("@bazel_features//:deps.bzl", "bazel_features_deps")
diff --git a/toolchains/BUILD b/toolchains/BUILD index 9eca53d..0dda388 100644 --- a/toolchains/BUILD +++ b/toolchains/BUILD
@@ -1,3 +1,4 @@ +load("@bazel_features//:features.bzl", "bazel_features") load("@bazel_skylib//:bzl_library.bzl", "bzl_library") load("@bazel_skylib//rules:common_settings.bzl", "bool_flag", "string_setting") load("@rules_cc//cc:cc_library.bzl", "cc_library") @@ -60,8 +61,14 @@ # # Obtain the associated JavaToolchainInfo via: # ctx.toolchains["@bazel_tools//tools/jdk:toolchain_type"].java -# TODO: migrate away from using @bazel_tools//tools/jdk:toolchain_type ? -# toolchain_type(name = "toolchain_type") +# buildifier: disable=no-effect +toolchain_type( + name = "toolchain_type", +) if bazel_features.java._toolchain_type_in_rules_java else alias( + # buildifier: disable=duplicated-name + name = "toolchain_type", + actual = "@bazel_tools//tools/jdk:toolchain_type", +) # The Java runtime that executable Java compilation outputs (e.g., java_binary with # create_executable = True) will run on. @@ -72,8 +79,14 @@ # # Obtain the associated JavaRuntimeInfo via: # ctx.toolchains["@bazel_tools//tools/jdk:runtime_toolchain_type"].java_runtime -# TODO: migrate away from using @bazel_tools//tools/jdk:runtime_toolchain_type ? -# toolchain_type(name = "runtime_toolchain_type") +# buildifier: disable=no-effect +toolchain_type( + name = "runtime_toolchain_type", +) if bazel_features.java._toolchain_type_in_rules_java else alias( + # buildifier: disable=duplicated-name + name = "runtime_toolchain_type", + actual = "@bazel_tools//tools/jdk:runtime_toolchain_type", +) # The Java runtime to extract the bootclasspath from that is then used to compile Java sources. # @@ -84,8 +97,14 @@ # # 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") +# buildifier: disable=no-effect +toolchain_type( + name = "bootstrap_runtime_toolchain_type", +) if bazel_features.java._toolchain_type_in_rules_java else alias( + # buildifier: disable=duplicated-name + name = "bootstrap_runtime_toolchain_type", + actual = "@bazel_tools//tools/jdk:bootstrap_runtime_toolchain_type", +) # Points to toolchain[":runtime_toolchain_type"] (was :legacy_current_java_runtime) java_runtime_alias(name = "current_java_runtime")