Compile OpenJDK 9 and up with ARM64 musl-libs

Denis Voloshin :

A bit background.

My goal is to create a super slim docker image with JRE on ARM64. Here are possible areas where I can affect on the final image size.

  1. Using JAVA 9 and up allows me to leverage new java modules capability.
  2. Using Alpine for ARM64 provides a super slim base image.

What I have done so far: There is OpenJDK 9 and up releases for ARM64, using modules capability I got JRE size around 30M, that's a great achievement.

Now I'm working on moving to the Alpine base image, it requires to have an OpenJDK be compiled with musl-libc. I managed to recompile the lasted OpenJDK with glibc, my question is how it's complicated to compile the OpenJDK 9 with musl libc, my understanding says, the glibc and musl expose the same interface, basically, the OpenJDK should be compatible with musl-libc.

Any directions to hit this challenge will be appreciated.

valiano :

Just in (May/19) - openjdk9 (experimental) for AArch64 is now available from Alpine repositories!

Package details: https://pkgs.alpinelinux.org/package/edge/testing/aarch64/openjdk9

Grab it using:

apk add openjdk9 --repository=http://dl-cdn.alpinelinux.org/alpine/edge/testing

The other day I had to build OpenJDK from source on musl Alpine 3.8. Luckily, it was quite smooth! So, if you'll end up having to build OpenJDK from source for ARM64 musl support, you could follow these steps with some modifications for your target.

Note 1: To extend the discussion in comments, OpenJDK on musl Alpine is currently work in progress. The latest available is JDK 12 early access, for X64 only: http://jdk.java.net/12. JDK 9, 10 and 11 have development branches, but were not GA'd and officially released. Depending on your usage of the built OpenJDK, this should be seriously considered.

Naturally, it's always better to use ready and tested OpenJDK binaries, if such are available.

Note 2: The below steps were tested with OpenJDK 11, over Alpine 3.8 traditional disk installation (not docker), on a X86 workstation.

Prerequisites:

Packages

The following packages should be installed prior to build (hope I'm not missing any):

// build tools and utilities  
apk add build-base autoconf bash coreutils gawk grep mercurial zip  
// X11 libraries   
apk add libx11-dev libxext-dev libxrender-dev libxtst-dev libxt-dev  
// Additional libraries  
apk add alsa-lib-dev cups-dev fontconfig-dev

Boot JDK

Then, ironically, you need a boot JDK: OpenJDK of the same of previous version installed... It could be OpenJDK that runs on the host (not cross compiled), so you should get your hands on OpenJDK 10 or 11 musl X86 builds.

At some point, an OpenJDK 11 early access binary was made available, but it was removed from the OpenJDK download page, since it was not production ready. For JDK bootstrapping, it may be enough, so try getting a hold of it: openjdk-11+28_linux-x64-musl_bin.tar.gz. If you want (or have to) stick to JDK9, then OpenJDK 8 could be used for bootstrapping, and no problem there since it's available as the openjdk8 apk package.

Usually the boot JDK is automatically picked by the build, but if not, you could specify it to configure with --with-boot-jdk=[path-to-jdk].

Sources:

For Alpine OpenJDK builds, you should use OpenJDK's Portola branches. These are already compatible with musl. There are branches for JDK 9, 10 and 11. As noted above, they are experimental.

For grabbing the OpenJDK 11 source code:

hg clone https://hg.openjdk.java.net/portola/jdk11

Building:

Once you had everything set up, build is quite simple. I used:

cd jdk11
bash configure
make JOBS=8 LOG=info hotspot

References:

For further reference, see the JDK11 build instructions (not for Alpine specifically):

OpenJDK cross compiling:

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=107442&siteId=1