8256182: Update qemu-debootstrap cross-compilation recipe

Reviewed-by: ihse
This commit is contained in:
Aleksey Shipilev 2020-11-11 16:06:08 +00:00
parent 6247736fc9
commit 421a7c3b41
2 changed files with 52 additions and 27 deletions

View File

@ -629,21 +629,30 @@ cp: cannot stat `arm-linux-gnueabihf/libXt.so&#39;: No such file or directory</c
<p>Fortunately, you can create sysroots for foreign architectures with tools provided by your OS. On Debian/Ubuntu systems, one could use <code>qemu-deboostrap</code> to create the <em>target</em> system chroot, which would have the native libraries and headers specific to that <em>target</em> system. After that, we can use the cross-compiler on the <em>build</em> system, pointing into chroot to get the build dependencies right. This allows building for foreign architectures with native compilation speed.</p> <p>Fortunately, you can create sysroots for foreign architectures with tools provided by your OS. On Debian/Ubuntu systems, one could use <code>qemu-deboostrap</code> to create the <em>target</em> system chroot, which would have the native libraries and headers specific to that <em>target</em> system. After that, we can use the cross-compiler on the <em>build</em> system, pointing into chroot to get the build dependencies right. This allows building for foreign architectures with native compilation speed.</p>
<p>For example, cross-compiling to AArch64 from x86_64 could be done like this:</p> <p>For example, cross-compiling to AArch64 from x86_64 could be done like this:</p>
<ul> <ul>
<li>Install cross-compiler on the <em>build</em> system:</li> <li><p>Install cross-compiler on the <em>build</em> system:</p>
</ul> <pre><code>apt install g++-aarch64-linux-gnu gcc-aarch64-linux-gnu</code></pre></li>
<pre><code>apt install g++-aarch64-linux-gnu gcc-aarch64-linux-gnu</code></pre> <li><p>Create chroot on the <em>build</em> system, configuring it for <em>target</em> system:</p>
<ul> <pre><code>sudo qemu-debootstrap \
<li>Create chroot on the <em>build</em> system, configuring it for <em>target</em> system:</li> --arch=arm64 \
</ul> --verbose \
<pre><code>sudo qemu-debootstrap --arch=arm64 --verbose \ --include=fakeroot,symlinks,build-essential,libx11-dev,libxext-dev,libxrender-dev,libxrandr-dev,libxtst-dev,libxt-dev,libcups2-dev,libfontconfig1-dev,libasound2-dev,libfreetype6-dev,libpng-dev \
--include=fakeroot,build-essential,libx11-dev,libxext-dev,libxrender-dev,libxrandr-dev,libxtst-dev,libxt-dev,libcups2-dev,libfontconfig1-dev,libasound2-dev,libfreetype6-dev,libpng12-dev \ --resolve-deps \
--resolve-deps jessie /chroots/arm64 http://httpredir.debian.org/debian/</code></pre> buster \
<ul> ~/sysroot-arm64 \
<li>Configure and build with newly created chroot as sysroot/toolchain-path:</li> http://httpredir.debian.org/debian/</code></pre></li>
</ul> <li><p>Make sure the symlinks inside the newly created chroot point to proper locations:</p>
<pre><code>CC=aarch64-linux-gnu-gcc CXX=aarch64-linux-gnu-g++ sh ./configure --openjdk-target=aarch64-linux-gnu --with-sysroot=/chroots/arm64/ --with-toolchain-path=/chroots/arm64/ <pre><code>sudo chroot ~/sysroot-arm64 symlinks -cr .</code></pre></li>
<li><p>Configure and build with newly created chroot as sysroot/toolchain-path:</p>
<pre><code>CC=aarch64-linux-gnu-gcc CXX=aarch64-linux-gnu-g++ sh ./configure \
--openjdk-target=aarch64-linux-gnu \
--with-sysroot=~/sysroot-arm64 \
--with-toolchain-path=~/sysroot-arm64 \
--with-freetype-lib=~/sysroot-arm64/usr/lib/aarch64-linux-gnu/ \
--with-freetype-include=~/sysroot-arm64/usr/include/freetype2/ \
--x-libraries=~/sysroot-arm64/usr/lib/aarch64-linux-gnu/
make images make images
ls build/linux-aarch64-normal-server-release/</code></pre> ls build/linux-aarch64-server-release/</code></pre></li>
</ul>
<p>The build does not create new files in that chroot, so it can be reused for multiple builds without additional cleanup.</p> <p>The build does not create new files in that chroot, so it can be reused for multiple builds without additional cleanup.</p>
<p>Architectures that are known to successfully cross-compile like this are:</p> <p>Architectures that are known to successfully cross-compile like this are:</p>
<table> <table>

View File

@ -1092,16 +1092,32 @@ apt install g++-aarch64-linux-gnu gcc-aarch64-linux-gnu
* Create chroot on the *build* system, configuring it for *target* system: * Create chroot on the *build* system, configuring it for *target* system:
``` ```
sudo qemu-debootstrap --arch=arm64 --verbose \ sudo qemu-debootstrap \
--include=fakeroot,build-essential,libx11-dev,libxext-dev,libxrender-dev,libxrandr-dev,libxtst-dev,libxt-dev,libcups2-dev,libfontconfig1-dev,libasound2-dev,libfreetype6-dev,libpng12-dev \ --arch=arm64 \
--resolve-deps jessie /chroots/arm64 http://httpredir.debian.org/debian/ --verbose \
--include=fakeroot,symlinks,build-essential,libx11-dev,libxext-dev,libxrender-dev,libxrandr-dev,libxtst-dev,libxt-dev,libcups2-dev,libfontconfig1-dev,libasound2-dev,libfreetype6-dev,libpng-dev \
--resolve-deps \
buster \
~/sysroot-arm64 \
http://httpredir.debian.org/debian/
```
* Make sure the symlinks inside the newly created chroot point to proper locations:
```
sudo chroot ~/sysroot-arm64 symlinks -cr .
``` ```
* Configure and build with newly created chroot as sysroot/toolchain-path: * Configure and build with newly created chroot as sysroot/toolchain-path:
``` ```
CC=aarch64-linux-gnu-gcc CXX=aarch64-linux-gnu-g++ sh ./configure --openjdk-target=aarch64-linux-gnu --with-sysroot=/chroots/arm64/ --with-toolchain-path=/chroots/arm64/ CC=aarch64-linux-gnu-gcc CXX=aarch64-linux-gnu-g++ sh ./configure \
--openjdk-target=aarch64-linux-gnu \
--with-sysroot=~/sysroot-arm64 \
--with-toolchain-path=~/sysroot-arm64 \
--with-freetype-lib=~/sysroot-arm64/usr/lib/aarch64-linux-gnu/ \
--with-freetype-include=~/sysroot-arm64/usr/include/freetype2/ \
--x-libraries=~/sysroot-arm64/usr/lib/aarch64-linux-gnu/
make images make images
ls build/linux-aarch64-normal-server-release/ ls build/linux-aarch64-server-release/
``` ```
The build does not create new files in that chroot, so it can be reused for multiple builds The build does not create new files in that chroot, so it can be reused for multiple builds