Question: How to find a JDK runtime with `master`?
jpsim opened this issue · 8 comments
I've been using rules_java 5.0.0 successfully, but I'll soon need to update to include recent changes in master
to support the latest bazel 6.x rolling releases.
Prior to 338c418 the JDK runtime toolchain was being found correctly, but after that commit I get the following error:
ERROR: /.../BUILD:21:19: While resolving toolchains for target //{my-target}: no matching toolchains found for types @bazel_tools//tools/jdk:runtime_toolchain_type
Here's the complete error
INFO: Repository remotejdk11_macos_aarch64 instantiated at:
/Users/jsimard/src/envoy-mobile/WORKSPACE:58:26: in <toplevel>
/private/var/tmp/_bazel_jsimard/7140f038a5c13b01a171c93151a000da/external/envoy_mobile/bazel/envoy_mobile_dependencies.bzl:53:24: in envoy_mobile_dependencies
/private/var/tmp/_bazel_jsimard/7140f038a5c13b01a171c93151a000da/external/envoy_mobile/bazel/envoy_mobile_dependencies.bzl:62:28: in kotlin_dependencies
/private/var/tmp/_bazel_jsimard/7140f038a5c13b01a171c93151a000da/external/rules_java/java/repositories.bzl:469:23: in rules_java_dependencies
/private/var/tmp/_bazel_jsimard/7140f038a5c13b01a171c93151a000da/external/rules_java/java/repositories.bzl:233:10: in remote_jdk11_repos
/private/var/tmp/_bazel_jsimard/7140f038a5c13b01a171c93151a000da/external/bazel_tools/tools/build_defs/repo/utils.bzl:233:18: in maybe
/private/var/tmp/_bazel_jsimard/7140f038a5c13b01a171c93151a000da/external/rules_java/toolchains/remote_java_repository.bzl:48:17: in remote_java_repository
Repository rule http_archive defined at:
/private/var/tmp/_bazel_jsimard/7140f038a5c13b01a171c93151a000da/external/bazel_tools/tools/build_defs/repo/http.bzl:353:31: in <toplevel>
ERROR: /Users/jsimard/src/envoy-mobile/library/kotlin/io/envoyproxy/envoymobile/BUILD:21:19: While resolving toolchains for target //library/kotlin/io/envoyproxy/envoymobile:envoy_lib_kt: no matching toolchains found for types @bazel_tools//tools/jdk:runtime_toolchain_type
I'm probably not specifying something I should be, or perhaps this is considered a bug? I'm not sure, so I'm phrasing this as a question.
To reproduce you can clone Envoy Mobile and run the following command:
./bazelw build android_dist --config=android --override_repository=rules_java=/path/to/rules_java
I'll work to reduce and simplify the repro case but I wanted to share now in case the solution was obvious to more experienced users or maintainers of rules_java.
Thanks!
I can work with a large reproducer.
Reverting would cause other problems. There's a usecase where JDK gets packaged for deployment, so it needs to be matched by the target.
Is this only problem for android?
You can get extra debug by adding flag:
--toolchain_resolution_debug='@bazel_tools//tools/jdk:runtime_toolchain_type'
Is this only problem for android?
Yes, but only in the sense that we don't compile Java for any other platform, we compile C/C++/Python/ObjC/Swift for other platforms that aren't affected by this, but maybe that's obvious.
Actually it looks like this envoyproxy/envoy#22356 fixes the issue, but now bazel can't find the C++ toolchain:
ERROR: /private/var/tmp/_bazel_jsimard/7140f038a5c13b01a171c93151a000da/external/bazel_tools/tools/cpp/BUILD:60:19: While resolving toolchains for target @bazel_tools//tools/cpp:current_cc_toolchain: No matching toolchains found for types @bazel_tools//tools/cpp:toolchain_type. Maybe --incompatible_use_cc_configure_from_rules_cc has been flipped and there is no default C++ toolchain added in the WORKSPACE file? See https://github.com/bazelbuild/bazel/issues/10134 for details and migration instructions.
Maybe rules_java needs to use use_cpp_toolchain()
somewhere?
Update:
Full error
$ ./bazelw build android_dist --config=android --override_repository=rules_java=/Users/jsimard/src/rules_java
INFO: Build option --toolchain_resolution_debug has changed, discarding analysis cache.
INFO: Repository remotejdk11_macos_aarch64 instantiated at:
/Users/jsimard/src/envoy-mobile/WORKSPACE:58:26: in <toplevel>
/private/var/tmp/_bazel_jsimard/7140f038a5c13b01a171c93151a000da/external/envoy_mobile/bazel/envoy_mobile_dependencies.bzl:52:24: in envoy_mobile_dependencies
/private/var/tmp/_bazel_jsimard/7140f038a5c13b01a171c93151a000da/external/envoy_mobile/bazel/envoy_mobile_dependencies.bzl:61:28: in kotlin_dependencies
/private/var/tmp/_bazel_jsimard/7140f038a5c13b01a171c93151a000da/external/rules_java/java/repositories.bzl:517:23: in rules_java_dependencies
/private/var/tmp/_bazel_jsimard/7140f038a5c13b01a171c93151a000da/external/rules_java/java/repositories.bzl:251:10: in remote_jdk11_repos
/private/var/tmp/_bazel_jsimard/7140f038a5c13b01a171c93151a000da/external/bazel_tools/tools/build_defs/repo/utils.bzl:233:18: in maybe
/private/var/tmp/_bazel_jsimard/7140f038a5c13b01a171c93151a000da/external/rules_java/toolchains/remote_java_repository.bzl:48:17: in remote_java_repository
Repository rule http_archive defined at:
/private/var/tmp/_bazel_jsimard/7140f038a5c13b01a171c93151a000da/external/bazel_tools/tools/build_defs/repo/http.bzl:353:31: in <toplevel>
INFO: Repository maven instantiated at:
/Users/jsimard/src/envoy-mobile/WORKSPACE:58:26: in <toplevel>
/private/var/tmp/_bazel_jsimard/7140f038a5c13b01a171c93151a000da/external/envoy_mobile/bazel/envoy_mobile_dependencies.bzl:52:24: in envoy_mobile_dependencies
/private/var/tmp/_bazel_jsimard/7140f038a5c13b01a171c93151a000da/external/envoy_mobile/bazel/envoy_mobile_dependencies.bzl:62:18: in kotlin_dependencies
/private/var/tmp/_bazel_jsimard/7140f038a5c13b01a171c93151a000da/external/rules_jvm_external/defs.bzl:121:19: in maven_install
Repository rule coursier_fetch defined at:
/private/var/tmp/_bazel_jsimard/7140f038a5c13b01a171c93151a000da/external/rules_jvm_external/coursier.bzl:1173:33: in <toplevel>
INFO: Repository android_tools instantiated at:
/DEFAULT.WORKSPACE.SUFFIX:413:13: in <toplevel>
Repository rule http_archive defined at:
/private/var/tmp/_bazel_jsimard/7140f038a5c13b01a171c93151a000da/external/bazel_tools/tools/build_defs/repo/http.bzl:353:31: in <toplevel>
ERROR: /private/var/tmp/_bazel_jsimard/7140f038a5c13b01a171c93151a000da/external/bazel_tools/tools/cpp/BUILD:60:19: While resolving toolchains for target @bazel_tools//tools/cpp:current_cc_toolchain: No matching toolchains found for types @bazel_tools//tools/cpp:toolchain_type. Maybe --incompatible_use_cc_configure_from_rules_cc has been flipped and there is no default C++ toolchain added in the WORKSPACE file? See https://github.com/bazelbuild/bazel/issues/10134 for details and migration instructions.
ERROR: Analysis of target '//:android_dist' failed; build aborted:
INFO: Elapsed time: 0.221s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (1 packages loaded, 1336 targets configured)
Here's a smaller repro case keith/bazel-rust-mobile-demo#3, passing --java_runtime_version=remotejdk_11
is what triggers things. Versus it defaulting to the local_jdk (maybe arm64 darwin specific?)
Verified it repros on x86_64 macOS as well
I have a bunch of issues caused by the same problem, described at bazelbuild/bazel#17085. There's a reproducer there for several variants (wrong binaries used on exec platform, toolchain resolution failures that entirely break builds that use globs). @comius
This is still causing problem for the Envoy project and is blocking our move to bazel 6.2.0. Is there any more information we can provide to expedite this?