Skip to content

Instantly share code, notes, and snippets.

@delitescere
Last active February 18, 2021 10:21
Show Gist options
  • Save delitescere/d80c6782cb8d1b6f987dbcb9488f58ca to your computer and use it in GitHub Desktop.
Save delitescere/d80c6782cb8d1b6f987dbcb9488f58ca to your computer and use it in GitHub Desktop.
Portola (OpenJDK using musl) on Alpine

Get the JDK source (per the OpenJDK instructions):

hg clone http://hg.openjdk.java.net/portola/portola
cd portola
bash ./get_source.sh

You need an existing Alpine with an already-built JDK. I have a Docker image of Alpine with glibc-based Zulu JDK:

docker run -ti --volume $PWD:/code delitescere/jdk sh

In the container, we need to grab the Alpine 3.4 package repo also in order to limit to g++ less than version 6:

echo 'http://dl-cdn.alpinelinux.org/alpine/v3.4/main/' >> /etc/apk/repositories
apk update
apk add 'g++<6'
apk add alsa-lib-dev bash cups-dev file freetype-dev grep libelf-dev libx11-dev libxext-dev libxrender-dev libxt-dev libxtst-dev linux-headers make mercurial tar zip

unset JAVA_HOME
cd /code
bash ./configure

The --host=x86_64-unknown-linux-musl --build=x86_64-unknown-linux-musl arguments are no longer needed.

I've added libelf-dev so AOT can happen (it's a Linux, after all).


If you are running Alpine version 3.3 or below (or until warnings-are-errors is disabled in jdk/make/lib/SoundLibraries.gmk):

ln -snf /usr/include/poll.h /usr/include/sys/poll.h

Make:

make

And have a nice cup of tea while you wait.


Now, back to your host and run the official, vanilla Alpine (no glibc):

docker run -ti --rm --volume $PWD:/code alpine:3.5 /code/build/linux-x86_64-normal-server-release/jdk/bin/java -version

# openjdk version "10-internal"
# OpenJDK Runtime Environment (build 10-internal+0-adhoc..code)
# OpenJDK 64-Bit Server VM (build 10-internal+0-adhoc..code, mixed mode)

Huzzah!

@delitescere
Copy link
Author

delitescere commented May 19, 2017

Alas, building with Alpine 3.5 (which defaults to g++ 6.2) yields these C++ compilation issues with the min max macros:

====================================================
A new configuration has been successfully created in
/code/build/linux-x86_64-normal-server-release
using default settings.

Configuration summary:
* Debug level:    release
* HS debug level: product
* JDK variant:    normal
* JVM variants:   server
* OpenJDK target: OS: linux, CPU architecture: x86, address length: 64
* Version string: 10-internal+0-adhoc..code (10-internal)

Tools summary:
* Boot JDK:       openjdk version "1.8.0_131" OpenJDK Runtime Environment (Zulu 8.21.0.1-linux64) (build 1.8.0_131-b11) OpenJDK 64-Bit Server VM (Zulu 8.21.0.1-linux64) (build 25.131-b11, mixed mode)  (at /usr/local/java)
* Toolchain:      gcc (GNU Compiler Collection)
* C Compiler:     Version 6.2.1 (at /usr/bin/gcc)
* C++ Compiler:   Version 6.2.1 (at /usr/bin/g++)

Build performance summary:
* Cores to use:   3
* Memory limit:   5957 MB

WARNING: Your build output directory is not on a local disk.
This will severely degrade build performance!
It is recommended that you create an output directory on a local disk,
and run the configure script again from that directory.

/code # make
Building target 'default (exploded-image)' in configuration 'linux-x86_64-normal-server-release'
Compiling 8 files for BUILD_TOOLS_LANGTOOLS
Creating hotspot/variant-server/tools/adlc/adlc from 13 file(s)
Compiling 2 files for BUILD_JVMTI_TOOLS
Creating support/modules_libs/java.base/libjsig.so from 1 file(s)
Parsing 1 properties into enum-like class for jdk.compiler
Compiling 19 properties into resource bundles for jdk.javadoc
Compiling 17 properties into resource bundles for jdk.compiler
Compiling 7 properties into resource bundles for jdk.jshell
Compiling 12 properties into resource bundles for jdk.jdeps
Compiling 117 files for BUILD_INTERIM_java.compiler
Compiling 395 files for BUILD_INTERIM_jdk.compiler
Compiling 61 files for BUILD_INTERIM_jdk.jdeps
Compiling 456 files for BUILD_INTERIM_jdk.javadoc
Creating support/modules_libs/java.base/server/libjvm.so from 695 file(s)
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Compiling 159 files for BUILD_TOOLS_JDK
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Compiling 141 files for BUILD_IDLJ
Compiling 6 files for BUILD_TOOLS_CORBA
Note: /code/corba/src/java.corba/share/classes/com/sun/tools/corba/se/idl/som/idlemit/MetaPragma.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Creating hotspot/variant-server/libjvm/gtest/libjvm.so from 52 file(s)
Creating hotspot/variant-server/libjvm/gtest/gtestLauncher from 1 file(s)
Compiling 198 files for BUILD_INTERIM_RMIC
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
In file included from /code/test/fmw/gtest/include/gtest/gtest.h:54:0,
                 from /code/hotspot/test/native/unittest.hpp:31,
                 from /code/hotspot/test/native/logging/logTestFixture.hpp:24,
                 from /code/hotspot/test/native/logging/logTestFixture.cpp:25:
/usr/include/c++/6.2.1/limits:320:11: error: macro "min" requires 2 arguments, but only 1 given
       min() _GLIBCXX_USE_NOEXCEPT { return _Tp(); }
           ^
/usr/include/c++/6.2.1/limits:324:11: error: macro "max" requires 2 arguments, but only 1 given
       max() _GLIBCXX_USE_NOEXCEPT { return _Tp(); }
           ^
/usr/include/c++/6.2.1/limits:387:11: error: macro "min" requires 2 arguments, but only 1 given
       min() _GLIBCXX_USE_NOEXCEPT { return false; }
           ^
/usr/include/c++/6.2.1/limits:390:11: error: macro "max" requires 2 arguments, but only 1 given
       max() _GLIBCXX_USE_NOEXCEPT { return true; }
           ^
/usr/include/c++/6.2.1/limits:456:11: error: macro "min" requires 2 arguments, but only 1 given
       min() _GLIBCXX_USE_NOEXCEPT { return __glibcxx_min(char); }
           ^
/usr/include/c++/6.2.1/limits:459:11: error: macro "max" requires 2 arguments, but only 1 given
       max() _GLIBCXX_USE_NOEXCEPT { return __glibcxx_max(char); }
           ^
/usr/include/c++/6.2.1/limits:523:11: error: macro "min" requires 2 arguments, but only 1 given
       min() _GLIBCXX_USE_NOEXCEPT { return -__SCHAR_MAX__ - 1; }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment