bazel: Can't compile java with java toolchains for the host platform with remote execution enabled
I’m trying to switch a repo to use --incompatible_use_toolchain_resolution_for_java_rules
. I’m running into issues with the interplay with remote execution, and building either with the default --platforms
, or when running bazel run
. When building without remote execution, my toolchains are working properly.
My goal is for the host machine to be used for compiles which are both exec_compatible_with
and target_compatible_with
the host platform, if the remote execution system doesn’t support such a platform.
I am also using a C++ toolchain with --incompatible_enable_cc_toolchain_resolution
- this works fine already.
My set up:
- Running on a Mac.
- Remote execution cluster which supports Linux execution (requiring a particular platform properties), but which does not support Mac execution. Bazel has one
--extra_execution_platforms
registered which points at the Linux platform properties. I’ve also tried adding@bazel_tools//platforms:host_platform
as an--extra_execution_platforms
to no avail. - Both a Linux and Mac JDK are registered using
register_toolchains
- these haveexec_compatible_with
set to["@platforms//os:macos"]
or["@platforms//os:linux"]
. - Running
bazel build //some/java:binary --remote_executor=redacted
orbazel run //some/java:binary --remote_executor=redacted
orbazel build //some/java:binary --remote_executor=redacted --platforms=@bazel_tools//platforms:host_platform
I’ve tried using bazel 4.0.0 and bazel at 3733065ddd418357e0e74091789ace5884b01fef.
Here’s what I see in each combination of flags:
$ bazel build //some/java:binary --remote_executor=redacted --extra_execution_platforms=//my/remote/linux:platform
Attempts to run javac with a Linux JDK on the remote execution system with no platform properties set, and so complains that the remote execution platform doesn’t support macOS (though note: it is including a Linux JDK as inputs to the action). The same result happens when also adding ,@bazel_tools//platforms:host_platform
to --extra_execution_platforms
.
$ bazel build //some/java:binary --remote_executor=redacted --extra_execution_platforms=//my/remote/linux:platform --platforms=@bazel_tools//platforms:host_platform
Errors because it claims that the C++ toolchain mismatches with the platform on values osx, x86_64
even though it is defined as:
exec_compatible_with = [
"@platforms//cpu:x86_64",
"@platforms//os:osx",
],
target_compatible_with = [
"@platforms//os:osx",
"@platforms//cpu:x86_64",
],
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 18 (18 by maintainers)
I created a reproduction https://github.com/comius/bazel_issue_13157.
It is a bug in the old resolution, but there is nothing to worry about, because the right JDK is used for both compilation and execution. I’ll check if I can fix this, if not, this will be fixed once old resolution is removed.