halcyon / asdf-java

A Java plugin for asdf-vm.
MIT License
466 stars 86 forks source link

Install x86_64 JVM on M1 mac #156

Open nedtwigg opened 3 years ago

nedtwigg commented 3 years ago

I've got an M1 mac. Sometimes I need an aarch64-native JVM, but othertimes I need an x86_64 JVM under rosetta translation. It would be great for asdf-java to support this. As best I can tell, it can't do that right now.

This M1 arm/rosetta divide was discussed a bit at https://github.com/asdf-vm/asdf/issues/834, where it was suggested that one solution is for plugins to encode CPU architecture in the version string.

If I understand correctly, this plugin offers one set of JVMs on an Intel machine, and a different set of JVMs on Apple Silicon (e.g. no AdoptOpenJDK on Apple Silicon). What do you think about making the Intel JVMs available to Apple Silicon machines, but under a -rosetta version string (or some other name)?

jgenunez commented 3 years ago

Yes, there are different sets of JVM depending on the underlying architecture. The plugin stores the set of JVM releases in a cache file which then gets used for all subsequent asdf java plugin commands. I made a change to make the cache file platform specific by adding the OS and architecture to the name of the cache file. Pull request is pending approval

bayeslearner commented 2 years ago

You can get around this by creating a profile in the terminal app for running bash in rosetta, then using asdf to install the x86 version of the binary in a new window of that profile.

image
leonard84 commented 1 year ago

The readme mentions this workaround:

To switch your terminal from native ARM to Rosetta use arch -x86_64 /bin/zsh.

Howerver, the architecture detection in the script isn't affected by that anymore. When starting a shell this way arch reports i386 but uname -m reports arm64.

RafaelMoreira1180778 commented 1 year ago

The readme mentions this workaround:

To switch your terminal from native ARM to Rosetta use arch -x86_64 /bin/zsh.

Howerver, the architecture detection in the script isn't affected by that anymore. When starting a shell this way arch reports i386 but uname -m reports arm64.

This is problematic because:

$ env /usr/bin/arch -x86_64 /bin/zsh --login

$ arch
i386

$ uname -m
arm64

$ asdf install java adoptopenjdk-11.0.21+9
############################################################################################################################################################################################## 100.0%
OpenJDK11U-jdk_aarch64_mac_hotspot_11.0.21_9.tar.gz
OpenJDK11U-jdk_aarch64_mac_hotspot_11.0.21_9.tar.gz: OK

Notice the architecture that was installed, because of the difference between uname -m and arch.

I believe this should be changed!