diff --git a/bazel/bazel.bzl b/bazel/bazel.bzl index 2d7110ef969..00c9cdf9b7b 100644 --- a/bazel/bazel.bzl +++ b/bazel/bazel.bzl @@ -136,7 +136,6 @@ def _iml_module_jar_impl( deps = java_deps + kotlin_providers, javac_opts = java_common.default_javac_opts(java_toolchain = java_toolchain) + ctx.attr.javacopts, java_toolchain = java_toolchain, - host_javabase = find_java_runtime_toolchain(ctx, ctx.attr._host_javabase), sourcepath = sourcepath, # TODO(b/216385876) After updating to Bazel 5.0, use enable_compile_jar_action = use_ijar, ) @@ -371,7 +370,6 @@ _iml_module_ = rule( "data": attr.label_list(allow_files = True), "test_data": attr.label_list(allow_files = True), "_java_toolchain": attr.label(default = Label("@bazel_tools//tools/jdk:current_java_toolchain")), - "_host_javabase": attr.label(default = Label("@bazel_tools//tools/jdk:current_host_java_runtime")), "_zipper": attr.label( default = Label("@bazel_tools//tools/zip:zipper"), cfg = "host", diff --git a/bazel/common.bazelrc b/bazel/common.bazelrc index a3a1a3d09cc..15ee0ebe29e 100644 --- a/bazel/common.bazelrc +++ b/bazel/common.bazelrc @@ -47,7 +47,6 @@ build:datasize_aspect --output_groups=+data_size build --incompatible_strict_action_env # Ensures actions don't pick up env changes build --sandbox_tmpfs_path=/tmp -build --javacopt="-g:source,lines,vars" # Keep debug info # TODO (b/141269926): this generates a warning on windows when building for host, # but is required when building for android. build --copt=-fvisibility=hidden @@ -58,11 +57,10 @@ build --define=grpc_no_ares=true # finds make in the ndk-build script (see b/72179674). build --test_env=SHELL -# Use prebuilt JDK when doing local bazel build/test -build --host_javabase=//prebuilts/studio/jdk:jdk11_runtime -build --javabase=//prebuilts/studio/jdk:jdk11_runtime -build --host_java_toolchain=@bazel_tools//tools/jdk:legacy_toolchain -build --java_toolchain=@bazel_tools//tools/jdk:legacy_toolchain +# Bazel will find the matching java toolchain registered in WORKSPACE. +build --java_language_version=8 +build --java_runtime_version=jdk11 +build --tool_java_runtime_version=jdk11 # Use prebuilt native toolchain build --crosstool_top=@native_toolchain//:toolchain diff --git a/bazel/kotlin.bzl b/bazel/kotlin.bzl index b93030b0874..cf1d573b0e5 100644 --- a/bazel/kotlin.bzl +++ b/bazel/kotlin.bzl @@ -133,14 +133,13 @@ def kotlin_test( ) # Creates actions to generate the sources jar -def _sources(ctx, srcs, source_jars, jar, java_toolchain, host_javabase): +def _sources(ctx, srcs, source_jars, jar, java_toolchain): java_common.pack_sources( ctx.actions, output_source_jar = jar, sources = srcs, source_jars = source_jars, java_toolchain = java_toolchain, - host_javabase = host_javabase, ) # Creates actions to generate a resources_jar from the given resources. @@ -297,7 +296,6 @@ def _kotlin_library_impl(ctx): jars += [resources_jar] java_toolchain = find_java_toolchain(ctx, ctx.attr._java_toolchain) - host_javabase = find_java_runtime_toolchain(ctx, ctx.attr._host_javabase) # Java if java_srcs or source_jars: @@ -310,8 +308,7 @@ def _kotlin_library_impl(ctx): deps = deps + kotlin_providers, javac_opts = java_common.default_javac_opts(java_toolchain = java_toolchain) + ctx.attr.javacopts, java_toolchain = java_toolchain, - host_javabase = host_javabase, - plugins = [plugin[JavaInfo] for plugin in ctx.attr.plugins], + plugins = [plugin[JavaPluginInfo] for plugin in ctx.attr.plugins], # TODO(b/216385876) After updating to Bazel 5.0, use enable_compile_jar_action = use_ijar, ) @@ -337,7 +334,7 @@ def _kotlin_library_impl(ctx): allow_duplicates = True, ) - _sources(ctx, java_srcs + kotlin_srcs, source_jars, ctx.outputs.source_jar, java_toolchain, host_javabase) + _sources(ctx, java_srcs + kotlin_srcs, source_jars, ctx.outputs.source_jar, java_toolchain) java_info = JavaInfo( output_jar = ctx.outputs.jar, @@ -382,11 +379,10 @@ _kotlin_library = rule( "kotlin_use_ir": attr.bool(), "compress_resources": attr.bool(), "plugins": attr.label_list( - providers = [JavaInfo], + providers = [JavaPluginInfo], ), "stdlib": attr.label(), "_java_toolchain": attr.label(default = Label("@bazel_tools//tools/jdk:current_java_toolchain")), - "_host_javabase": attr.label(default = Label("@bazel_tools//tools/jdk:current_host_java_runtime")), "_bootclasspath": attr.label( # Use JDK 8 because AGP still needs to support it (b/166472930). default = Label("//prebuilts/studio/jdk:bootclasspath"), diff --git a/bazel/toplevel.WORKSPACE b/bazel/toplevel.WORKSPACE index c3755dc39e8..ece9b90aac5 100644 --- a/bazel/toplevel.WORKSPACE +++ b/bazel/toplevel.WORKSPACE @@ -11,6 +11,9 @@ register_toolchains( "@native_toolchain//:cc-toolchain-x64_windows-clang-cl", "//tools/base/bazel/toolchains/darwin:python_toolchain", "//tools/base/bazel/toolchains/darwin:python_toolchain_10.13", + "//prebuilts/studio/jdk:runtime_toolchain_definition", + "//prebuilts/studio/jdk:jdk11_toolchain_java8_definition", + "//prebuilts/studio/jdk:jdk11_toolchain_java11_definition", ) local_repository(