Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bazel 4.1.0 can't find javabase on Apple M1 macmini #13573

Closed
devjgm opened this issue Jun 11, 2021 · 8 comments
Closed

bazel 4.1.0 can't find javabase on Apple M1 macmini #13573

devjgm opened this issue Jun 11, 2021 · 8 comments
Labels
area-java-toolchains javabase, java_toolchain flags, JDK selection, java_toolchain rules, java_tools repository team-Rules-Java Issues for Java rules type: bug

Comments

@devjgm
Copy link

devjgm commented Jun 11, 2021

Description of the problem / feature request:

bazel gives an error and asks for the --host_javabase when building my project on an Apple M1 macmini.

Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

$ git clone https://github.com/googleapis/google-cloud-cpp
...
$ USE_BAZEL_VERSION=4.1.0 bazelisk --bazelrc=/dev/null build ...
ERROR: /private/var/tmp/_bazel_jgm/e74a2c349bb49ff8069f80cc5514c617/external/bazel_tools/tools/jdk/BUILD:490:6: Configurable attribute "actual" doesn't match this configuration: Could not find a JDK for host execution environment, please explicitly provide one using `--host_javabase.`
...

What operating system are you running Bazel on?

Apple M1 macmini

$ sw_vers
ProductName:    macOS
ProductVersion: 11.4
BuildVersion:   20F71

$ arch
arm64

What's the output of bazel info release?

$ USE_BAZEL_VERSION=4.1.0 bazelisk info release
release 4.1.0
$ USE_BAZEL_VERSION=4.1.0 bazelisk info
bazel-bin: /private/var/tmp/_bazel_jgm/e74a2c349bb49ff8069f80cc5514c617/execroot/com_github_googleapis_google_cloud_cpp/bazel-out/darwin_arm64-fastbuild/bin
bazel-genfiles: /private/var/tmp/_bazel_jgm/e74a2c349bb49ff8069f80cc5514c617/execroot/com_github_googleapis_google_cloud_cpp/bazel-out/darwin_arm64-fastbuild/bin
bazel-testlogs: /private/var/tmp/_bazel_jgm/e74a2c349bb49ff8069f80cc5514c617/execroot/com_github_googleapis_google_cloud_cpp/bazel-out/darwin_arm64-fastbuild/testlogs
character-encoding: file.encoding = ISO-8859-1, defaultCharset = ISO-8859-1
command_log: /private/var/tmp/_bazel_jgm/e74a2c349bb49ff8069f80cc5514c617/command.log
committed-heap-size: 154MB
execution_root: /private/var/tmp/_bazel_jgm/e74a2c349bb49ff8069f80cc5514c617/execroot/com_github_googleapis_google_cloud_cpp
gc-count: 13
gc-time: 291ms
install_base: /var/tmp/_bazel_jgm/install/d0b631b3e5a643567f221e133629d965
java-home: /private/var/tmp/_bazel_jgm/install/d0b631b3e5a643567f221e133629d965/embedded_tools/jdk
java-runtime: OpenJDK Runtime Environment (build 11.0.10+9-LTS) by Azul Systems, Inc.
java-vm: OpenJDK 64-Bit Server VM (build 11.0.10+9-LTS, mixed mode) by Azul Systems, Inc.
max-heap-size: 4294MB
output_base: /private/var/tmp/_bazel_jgm/e74a2c349bb49ff8069f80cc5514c617
output_path: /private/var/tmp/_bazel_jgm/e74a2c349bb49ff8069f80cc5514c617/execroot/com_github_googleapis_google_cloud_cpp/bazel-out
package_path: %workspace%
release: release 4.1.0
repository_cache: /var/tmp/_bazel_jgm/cache/repos/v1
server_log: /private/var/tmp/_bazel_jgm/e74a2c349bb49ff8069f80cc5514c617/java.log.appleslice.jgm.log.java.20210611-123309.95376
server_pid: 95376
used-heap-size: 72MB
workspace: /Users/jgm/google-cloud-cpp

Have you found anything relevant by searching the web?

#10377 is similar but for Power9

Any other information, logs, or outputs that you want to share?

Adding the --host_javabase flag works

$ USE_BAZEL_VERSION=4.1.0 bazelisk --bazelrc=/dev/null build --host_javabase=@local_jdk//:jdk ...
... 
@oquenchil oquenchil added area-java-toolchains javabase, java_toolchain flags, JDK selection, java_toolchain rules, java_tools repository type: bug untriaged team-Rules-Java Issues for Java rules labels Jun 14, 2021
@comius
Copy link
Contributor

comius commented Jul 21, 2021

Bazel uses remote JDKs for the host_javabase and has a preconfigured set in /src/main/java/com/google/devtools/build/lib/bazel/rules/java/jdk.WORKSPACE.tmpl

The set is missing M1 architecture, so the --host_javabase workaround is the simplest.
You can also import M1 remote JDK in your own WORKSPACE file.

@comius comius closed this as completed Jul 21, 2021
@comius comius removed the untriaged label Jul 21, 2021
@keith
Copy link
Member

keith commented Jul 21, 2021

This should be fixed on head

@brentleyjones
Copy link
Contributor

@keith Do you know if the required commits have been cherry-picked into the 4.2.0 RC?

@keith
Copy link
Member

keith commented Jul 21, 2021

not sure, it has been too hard to follow

@PengKuang
Copy link

I still see the same error. Is it fixed? If not, why this issue is closed?

@Jdban
Copy link

Jdban commented Nov 30, 2021

Om 4.2.1 I get this error on my M1 mac still:

Configurable attribute "actual" doesn't match this configuration: Could not find a JDK for host execution environment, please explicitly provide one using `--host_javabase.

@wookayin
Copy link

bazel cannot find a proper JAVA base installed on arm64 macs. I had java11 installed via homebrew, so I had to add the following command line flag: --define=ABSOLUTE_JAVABASE=/opt/homebrew/opt/java11 (Feel free to change the JAVABASE path according to your installation):

bazel test \
    --define=ABSOLUTE_JAVABASE=/opt/homebrew/opt/java11 \
    --host_javabase=@bazel_tools//tools/jdk:absolute_javabase \
    --host_java_toolchain=@bazel_tools//tools/jdk:toolchain_vanilla \
    --java_toolchain=@bazel_tools//tools/jdk:toolchain_vanilla \
    //...

Or put these lines in .bazelrc file:

build --define=ABSOLUTE_JAVABASE=/opt/homebrew/opt/java11
build --host_javabase=@bazel_tools//tools/jdk:absolute_javabase
build --host_java_toolchain=@bazel_tools//tools/jdk:toolchain_vanilla
build --java_toolchain=@bazel_tools//tools/jdk:toolchain_vanilla

See https://stackoverflow.com/questions/59040291/configuring-bazel-to-build-test-using-a-specific-jvm-version as well for reference.

@scoquelin
Copy link

scoquelin commented Jan 6, 2022

Day 2 using bazel here so be nice 😉

I was facing the same issue with bazel 4.2.2 and new M1 laptop and first used the workaround provided by @wookayin

After that I figured that bazel build ... --host_javabase=@remotejdk11_macos_aarch64//:jdk is actually working fine.

Then while searching more I noticed this PR : bazelbuild/platforms#22

I went ahead and added this to my WORKSPACE file (or any relevant .bzl file) as described here

http_archive(
    name = "platforms",
    urls = [
        "https://mirror.bazel.build/github.com/bazelbuild/platforms/releases/download/0.0.4/platforms-0.0.4.tar.gz",
        "https://github.com/bazelbuild/platforms/releases/download/0.0.4/platforms-0.0.4.tar.gz",
    ],
    sha256 = "079945598e4b6cc075846f7fd6a9d0857c33a7afc0de868c2ccb96405225135d",
)

and now bazel build ... seems to work as expected (remote jdk11 being downloaded) and issue is gone on my end..
Hopefully someone will make sense of this 🤞 Hope that helps...

Note : was able to validate this workaround against this issue as well (although it now fails with a compilation error)

hanwen pushed a commit to GerritCodeReview/gerrit that referenced this issue Apr 26, 2022
Running the bazel build on Mac M1 yields the following error:

Configurable attribute "actual" doesn't match this configuration:
Could not find a JDK for host execution environment, please explicitly
provide one using `--host_javabase.`

Follow hints in [1] and fix this by loading bazel platforms 0.0.5
which contains a fix [2] making aarch64 an alias of arm64.

[1] bazelbuild/bazel#13573
[2] bazelbuild/platforms#22

Release-Notes: Fix bazel build on Mac M1 (aarch64)
Change-Id: I5a4ebcd50012a53e5ff92a12e4fa8ba766aed0a7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-java-toolchains javabase, java_toolchain flags, JDK selection, java_toolchain rules, java_tools repository team-Rules-Java Issues for Java rules type: bug
Projects
None yet
Development

No branches or pull requests

9 participants