register_execution_platforms advice wanted - Compiling Java under WSL2 picks Windows JDK not linux

80 views
Skip to first unread message

carpen...@gmail.com

unread,
Apr 7, 2022, 6:00:53 AM4/7/22
to bazel-discuss
Hi, 
I am trying to wrap my head around register_execution_platforms as the docs seem a bit light. 

I have a bazel 5.2 setup with bazel running under WSL2 and native windows. I have found out that if I used the default remote JDK bazel will use the windows version of the jdk (you can see javac.exe) however it tries to execute javac (without .exe on the end). Essentially it thinks it is executing on Windows not linux. 

I have two platforms registered with register_execution_platforms the linux 64bit and the windows 64bit platform. If the windows one is first and I try and run bazel coverage (or even the bazel java ProjectRunneer example) under WSL2 I get:

```
ERROR: /tmp/bazel-output-base/external/bazel_tools/tools/jdk/BUILD:333:14: JavaToolchainCompileClasses external/bazel_tools/tools/jdk/platformclasspath_classes/DumpPlatformClassPath.class failed: (Exit 1): javac failed: error executing command
  (cd /tmp/bazel-output-base/sandbox/linux-sandbox/363/execroot/esg && \
  exec env - \
  external/remotejdk11_win/bin/javac -source 8 -target 8 -Xlint:-options -cp external/remotejdk11_win/lib/tools.jar -d bazel-out/k8-opt/bin/external/bazel_tools/tools/jdk/platformclasspath_classes external/bazel_tools/tools/jdk/DumpPlatformClassPath.java)
# Configuration: e2ae2db464e63a93a1374fe86bdfd237bfb93e5e8d265a92c73e0733bdfc988f
# Execution platform: //tools/config:win_x64_platform

Use --sandbox_debug to see verbose messages from the sandbox
src/main/tools/linux-sandbox-pid1.cc:478: "execvp(external/remotejdk11_win/bin/javac, 0x1ea22d0)": No such file or directory
INFO: Elapsed time: 1.698s, Critical Path: 1.47s
```

If I switch order or remove the execution planforms all is OK. 

What I expected was that register execution platform would look a the host constraints and only accept the platforms matching the constraint. However this doesn't appear to be the case.  Everything seems OK when I don't register any execution platforms. 

I am after some rough guidance on how/why you would want to use register_execution_platforms, the docs don't see  too clear to me. 

Would you normally use a select statement, or a WORKSPACE rule to generate the correct platform for the current host?

Thanks

Reply all
Reply to author
Forward
0 new messages