Jabba-Team / jabba

(cross-platform) Java Version Manager
Apache License 2.0
141 stars 11 forks source link

Not downloading aarch64 (ARM64) version of java when running on Apple M1 #14

Closed martonsz closed 1 year ago

martonsz commented 1 year ago

I'm not getting the arm64 version of java on my MacBook Pro M1

In the following example, I'm installing zulu@8.0.352 which exists in both darwin/aarch64 and darwin/amd64 in the index.json The amd64 version is downloaded instead of the aarch64.


❯ jabba install zulu@8.0.352
Downloading zulu@8.0.352 (https://api.foojay.io/disco/v3.0/ids/098fa753a35703dfe96f59e504d1b6af/redirect)
159012626/159012626
Extracting /var/folders/dx/2g7_y93s609bdsl5_87jg8pc0000gn/T/jabba-d-859770548 to /Users/marton.szucs/.jabba/jdk/zulu@8.0.352
zulu@8.0 -> /Users/marton.szucs/.jabba/jdk/zulu@8.0.352

The workaround is to download using an URL to the aarch64 version


❯ jabba install 8.0.352-zulu-arm=tgz+https://api.foojay.io/disco/v3.0/ids/c3f7c076bf335d1061c74f7fab42bb89/redirect
Downloading 8.0.352-zulu-arm (https://api.foojay.io/disco/v3.0/ids/c3f7c076bf335d1061c74f7fab42bb89/redirect)
106088447/106088447
Extracting /var/folders/dx/2g7_y93s609bdsl5_87jg8pc0000gn/T/jabba-d-3868316553 to /Users/marton.szucs/.jabba/jdk/8.0.352-zulu-arm
❯ jabba --version
0.12.0

❯ uname -a
Darwin AMAYXVXTHQVW1 21.6.0 Darwin Kernel Version 21.6.0: Sun Nov  6 23:31:13 PST 2022; root:xnu-8020.240.14~1/RELEASE_ARM64_T6000 arm64
nicerloop commented 1 year ago

It seems that GOOS and GOARCH are used to get available release/url list, meaning these are fixed at build time. https://github.com/Jabba-Team/jabba/blob/e33ac29133e0efd11f52d76c95dd31445ef01d88/command/install.go#L54

Did you build a native arm jabba from source, or did you use the amd64 binary ?

martonsz commented 1 year ago

I used the one that is downloaded when running the installer. Which is the darwin-amd64 version.

I didn't know that this was decided at compile time. That makes it even more problematic because I want to be able to download both AMD and ARM Java. Some projects we are using contains libraries with AMD binaries (that doesn't work on our Apple M1 MacBooks). So we are forced to run AMD-java with Rossetta 2 on some projects :(

I have built a darwin-arm jabba from source. But it doesn't list anything with ls-remote. I added darwin/arm64 to the makefile.

❯ ./jabba-0.12.0-darwin-arm64 ls-remote

❯ ./jabba-0.12.0-darwin-amd64 ls-remote |head -n2
aoj@16.0.1
aoj@16

❯ file jabba-0.12.0-darwin-arm64 jabba-0.12.0-darwin-amd64
jabba-0.12.0-darwin-arm64: Mach-O 64-bit executable arm64
jabba-0.12.0-darwin-amd64: Mach-O 64-bit executable x86_64
martonsz commented 1 year ago

When I'm debugging the application on my MacBook I get the following values for os and arch when running the install command. https://github.com/Jabba-Team/jabba/blob/a0d6422cfb856b3fcdb38f393e7e33d279374a88/command/install.go#L54 https://github.com/Jabba-Team/jabba/blob/a0d6422cfb856b3fcdb38f393e7e33d279374a88/command/ls-remote.go#L19

os = darwin
arch = arm64

But the index.json is using the nameaarch64 instead of arm64 https://github.com/Jabba-Team/jabba/blob/a0d6422cfb856b3fcdb38f393e7e33d279374a88/index.json#L3367

The ls-remote command is able to override the os and arch values. That would be great for the install command. So I can install both a AMD and ARM version of java. But I think that there will be an issue with duplicate names right? https://github.com/Jabba-Team/jabba/blob/a0d6422cfb856b3fcdb38f393e7e33d279374a88/jabba.go#L165-L166

❯ jabba ls-remote --arch aarch64 | head -n2
corretto@19.0.1
corretto@19
patrick-mccourt commented 1 year ago

I don't think there was ever much multi-arch support in Jabba originally but it's been requested in other ways before. (i.e. 64 bit Windows users wanting to also install 32-bit java).

Definitely something worth adding though. I would like to bring all the go modules up to date as a first step then I can take a look at this.

nicerloop commented 1 year ago

It is probably better to fix the index from darwin/aarch64 to darwin/amd64 during generation. See https://github.com/Jabba-Team/jabba-index/issues/5

nicerloop commented 1 year ago

@martonsz Can you check installing a jdk works on darwin/arm64 using a darwin/arm64 build?

martonsz commented 1 year ago

@nicerloop Short answer: Version 0.12.1-rc works now on my MacBook with Apple M1

I have downloaded the binaries from GitHub and now the ARM64 version is downloading a JDK with the correct architecture.

❯ uname -a
Darwin MyMacBook 22.2.0 Darwin Kernel Version 22.2.0: Fri Nov 11 02:03:51 PST 2022; root:xnu-8792.61.2~4/RELEASE_ARM64_T6000 arm64

❯ cd ~/.jabba/bin
❯ l
lrwxr-xr-x    25 marton.szucs  7 Jan 09:15  jabba -> jabba-0.12.0-darwin-amd64
.rwxr-xr-x@  10M marton.szucs  7 Jan 09:02  jabba-0.12.0-darwin-amd64
.rwxr-xr-x@  10M marton.szucs  6 Jan 20:30  jabba-0.12.1-rc-darwin-amd64
.rwxr-xr-x@ 9.9M marton.szucs  6 Jan 20:29  jabba-0.12.1-rc-darwin-arm64

❯ find . -type f -exec bash -c 'echo -n $(shasum $1); echo -en "\t"; echo "$(file $1)"| cut -d " " -f 2-' - '{}' \;
a4c4ba8208b9cbe35ece5e0e8a1a93b50791df63 ./jabba-0.12.1-rc-darwin-arm64 Mach-O 64-bit executable arm64
7d2a883d1d068887a2475a55fd02803adf788f92 ./jabba-0.12.0-darwin-amd64    Mach-O 64-bit executable x86_64
752c4e91c7caf42b101d2ca4bb8bd78f66a83061 ./jabba-0.12.1-rc-darwin-amd64 Mach-O 64-bit executable x86_64

# Count number of java installations
❯ find . -type f -exec bash -c 'ln -sfv $1 jabba; source "/Users/marton.szucs/.jabba/jabba.sh"  ;jabba --version; jabba ls-remote | wc -l' - '{}' \;
jabba -> ./jabba-0.12.1-rc-darwin-arm64
0.12.1-rc
     210
jabba -> ./jabba-0.12.0-darwin-amd64
0.12.0
     586
jabba -> ./jabba-0.12.1-rc-darwin-amd64
0.12.1-rc
     586

# Installing the same java version with the different jabba binaries
# I have then checked if the installed java is running as "Intel" or "Apple" in the Activity Monitor. 
# "Intel" means that Rosetta 2 is translating from AMD to ARM
# "Apple" means that we are running at full speed! :)

# 0.12.0 AMD64
# This downloaded an AMD64 JDK that shows up as Intel in the Activity Monitor
❯ ln -sf jabba-0.12.0-darwin-amd64 jabba
❯ jabba install temurin@19.0.1
Downloading temurin@19.0.1 (https://api.foojay.io/disco/v3.0/ids/8c8a5add5a04dcd698be0297764406ab/redirect)
195454218/195454218
Extracting /var/folders/dx/2g7_y93s609bdsl5_87jg8pc0000gn/T/jabba-d-3679347452 to /Users/marton.szucs/.jabba/jdk/temurin@19.0.1
temurin@19.0 -> /Users/marton.szucs/.jabba/jdk/temurin@19.0.1

# 0.12.1 AMD64
# This downloaded exactly the same JDK as 0.12.0 AMD64
❯ for j in $(jabba ls); do jabba uninstall  $j; done
❯ ln -sf jabba-0.12.1-rc-darwin-amd64 jabba
❯ jabba install temurin@19.0.1
Downloading temurin@19.0.1 (https://api.foojay.io/disco/v3.0/ids/8c8a5add5a04dcd698be0297764406ab/redirect)
195454218/195454218
Extracting /var/folders/dx/2g7_y93s609bdsl5_87jg8pc0000gn/T/jabba-d-2885191124 to /Users/marton.szucs/.jabba/jdk/temurin@19.0.1
temurin@19.0 -> /Users/marton.szucs/.jabba/jdk/temurin@19.0.1

# 0.12.1 ARM64
# This downloads an ARM64 JDK that shows up as 'Apple' in the Activity Monitor 🥳
❯ for j in $(jabba ls); do jabba uninstall  $j; done
❯ ln -sf jabba-0.12.1-rc-darwin-arm64 jabba
❯ jabba install temurin@19.0.1
Downloading temurin@19.0.1 (https://api.foojay.io/disco/v3.0/ids/e22625c9d01243314f0e711cfab17da8/redirect)
185292307/185292307
Extracting /var/folders/dx/2g7_y93s609bdsl5_87jg8pc0000gn/T/jabba-d-1665008487 to /Users/marton.szucs/.jabba/jdk/temurin@19.0.1
temurin@19.0 -> /Users/marton.szucs/.jabba/jdk/temurin@19.0.1