Alpine Linux on x64 and AArch64
Aleksei Voitylov
aleksei.voitylov at bell-sw.com
Sun May 16 19:00:47 UTC 2021
Hi Lilian,
One has to be knowledgeable to understand all the nuances of
cross-compiling while changing target libc implementation (and,
possibly, version), architecture, and non-system compiler. I do, as
previously, recommend to read sections Operating System Requirements,
External Library Requirements, and Cross compiling the easy way with
OpenJDK devkits, and Boot JDK and Build JDK of the Build Guide [1], and
just use normal compilation on AArch64 Alpine. With this in mind, let's
do the experiment you are after: build for Alpine AArch64 on x86_64
glibc system.
1. Create a sysroot. Install all the required packages suggested in the
build guide on a live Alpine AArch64 system:
sudo apk add build-base bash grep zip freetype-dev cups-dev
fontconfig-dev alsa-lib-dev libx11-dev libxext-dev libxtst-dev
libxrender-dev libxrandr-dev libxt-dev
Create a snapshot of the filesystem and put its contents into $SYSROOT
on your build machine.
2. Choose your gcc. If you have selected musl.cc and its
aarch64-linux-musl-cross cross compiler as your trusted gcc, normalize
the multiarch tuples in the compiler bin/ folder (for some reason only
required with the latest x86_64 cross):
for i in addr2line dwp gcc-ranlib ld.bfd readelf ar elfedit gcov ld.gold
size as g++ gcov-dump lto-dump strings c++ gcc gcov-tool nm strip
c++filt gcc-10.2.1 gfortran objcopy cc gcc-ar gprof objdump cpp ld
ranlib; do
ln -s aarch64-linux-musl-$i aarch64-alpine-linux-musl-$i
done
Denote the location of your compiler as $DEVKIT.
3. Select your boot JDK. This is typically production JDK from N-1
release for the release you are trying to build. Denote that JDK it as
$BOOT_JDK.
4. Build your build JDK. Checkout JDK tag you'd like to build and build
JDK the normal way for your developer machine architecture. Denote the
target JDK it as $BUILD_JDK.
5. sh ./configure --with-boot-jdk=$BOOT_JDK --with-build-jdk=$BUILD_JDK
--openjdk-target=aarch64-alpine-linux-musl --with-devkit=$DEVKIT
--with-sysroot=$SYSROOT --disable-warnings-as-errors && make product-bundles
6. On target, observe:
./jdk/bin/java -version
openjdk version "16.0.1-internal" 2021-04-20
OpenJDK Runtime Environment (build
16.0.1-internal+0-adhoc.bellsoft.jdk16ugit)
OpenJDK 64-Bit Server VM (build
16.0.1-internal+0-adhoc.bellsoft.jdk16ugit, mixed mode)
Would I use a binary produced this way for anything beyond such an
experiment? I'm not sure. To avoid hiccups, it's best to use regular
compilation on AArch64 Alpine.
-Aleksei
On 15/05/2021 01:00, Lilian BENOIT wrote:
>
> Hi Aleksei,
>
> Thanks for your response.
>
> devkit is a archive that i must download on musl.cc website.
>
> This archive must uncompress on sysroot of qemu-debootstrap
> cd ~/sysroot-arm64; unzip xxx-linux-musl-cross.tgz
>
> my command is correct, isn't it ?
>
>
> But i hesitate on two archives
> - https://musl.cc/aarch64-linux-musl-cross.tgz
> - https://musl.cc/x86_64-linux-musl-cross.tgz
>
> I must use first ou second link if i want build on my computer (Linux
> debian x86 64) for aarch64 ?
> In fact, first part is target or platform of build ?
>
> Best Regards,
> Lilian Benoit,
>
> Le 14/05/2021 23:09, Aleksei Voitylov a écrit :
>> Hi Lilian,
>>
>> I had high hopes the documentation I integrated together with the
>> sources for Alpine Linux support [1] would be understandable, let me
>> know if it is not, I'll be happy to improve it :)
>>
>> To build it yourself, you have two options:
>>
>> * build on Alpine Linux AArch64 natively, without passing
>> --with-devkit. That's the way we do it at BellSoft.
>> * build with a cross compiler which should be passed to
>> --with-devkit=, for example, someone provides cross compilers here
>> [2].
>>
>> Thanks,
>>
>> -Aleksei
>>
>> [2] https://musl.cc/
>> On 14/05/2021 23:26, Lilian BENOIT wrote:
>>
>>> Hi Aleksei,
>>>
>>> Thanks for your reply.
>>>
>>> We can find binary for Alpine Linux on x86 64 (for exemple, on
>>> website AdoptOpenJDK or Azul)
>>> But I don't find binaries for Alpine Linux on AArch64.
>>>
>>> On linux x86 64, we can build binary for Alpine Linux (cross
>>> compilation with musl)
>>> ON linux x64 64, we can build binary for Linux AArch64 (cross
>>> complation with debian sysroots)
>>>
>>> Can i build binaries for Alpine Linux on AArch64 ?
>>> I must use --with-devkit=$DEVKIT but i don't understand which value
>>> do i put ?
>>>
>>> Best Regards.
>>> Lilian Benoit
>>>
>>> Le 14/05/2021 01:00, Aleksei Voitylov a écrit :
>>> Hi Lilian,
>>>
>>> the code integrated in OpenJDK project source code as part of JEP
>>> 386
>>> into JDK 16 is production ready, otherwise it would not have been
>>> integrated. It's possible to build OpenJDK for Alpine Linux with the
>>>
>>> provided instructions [1] or find an OpenJDK distribution that
>>> provides
>>> pre-built binaries for the target architecture of your choice.
>>>
>>> Thanks,
>>>
>>> -Aleksei
>>>
>>> [1] https://openjdk.java.net/groups/build/doc/building.html
>>>
>>> On 10/05/2021 18:51, Lilian BENOIT wrote:
>>> Hi everyone,
>>>
>>> In JEP 386, Alpine Linux Port, this summary is "Port the JDK to
>>> Alpine
>>> Linux, and to other Linux distributions that use musl as their
>>> primary
>>> C library, on both the x64 and AArch64 architectures"
>>>
>>> Alpine Linux Build is not included in JDK 16 because it isn't enough
>>>
>>> mature for production. (cf. notes on http://jdk.java.net/16/)
>>>
>>> This build is available on JDK 17 => Alpine Linux / x64
>>>
>>> But should it not available too on Alpine Linux / AArch64 build ?
>>>
>>> Is it on future ?
>>>
>>> Best Regards,
>>> Lilian BENOIT.
More information about the portola-dev
mailing list