Skip to content

Commit

Permalink
8305118: Add RISC-V related content to building.md
Browse files Browse the repository at this point in the history
Reviewed-by: erikj
  • Loading branch information
lgxbslgx committed Apr 7, 2023
1 parent 314e9b3 commit ce6e746
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 7 deletions.
34 changes: 29 additions & 5 deletions doc/building.html
Expand Up @@ -134,6 +134,8 @@ <h1 class="title">Building the JDK</h1>
Debian sysroots</a></li>
<li><a href="#building-for-armaarch64"
id="toc-building-for-armaarch64">Building for ARM/aarch64</a></li>
<li><a href="#building-for-risc-v" id="toc-building-for-risc-v">Building
for RISC-V</a></li>
<li><a href="#building-for-musl" id="toc-building-for-musl">Building for
musl</a></li>
<li><a href="#verifying-the-build"
Expand Down Expand Up @@ -1376,10 +1378,10 @@ <h3 id="cross-compiling-with-debian-sysroots">Cross compiling with
Debian sysroots</h3>
<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
<code>debootstrap</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
Expand All @@ -1389,7 +1391,7 @@ <h3 id="cross-compiling-with-debian-sysroots">Cross compiling with
<code>apt install g++-aarch64-linux-gnu gcc-aarch64-linux-gnu</code></p></li>
<li><p>Create chroot on the <em>build</em> system, configuring it for
<em>target</em> system:
<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,libffi-dev \ --resolve-deps \ buster \ ~/sysroot-arm64 \ http://httpredir.debian.org/debian/</code></p></li>
<code>sudo 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,libffi-dev \ --resolve-deps \ buster \ ~/sysroot-arm64 \ http://httpredir.debian.org/debian/ # If the target architecture is `riscv64`, # the path should be `debian-ports` instead of `debian`.</code></p></li>
<li><p>Make sure the symlinks inside the newly created chroot point to
proper locations:
<code>sudo chroot ~/sysroot-arm64 symlinks -cr .</code></p></li>
Expand Down Expand Up @@ -1516,6 +1518,13 @@ <h3 id="cross-compiling-with-debian-sysroots">Cross compiling with
<td style="text-align: left;">sh4-linux-gnu</td>
<td>zero</td>
</tr>
<tr class="even">
<td style="text-align: left;">riscv64</td>
<td style="text-align: left;">sid</td>
<td style="text-align: left;">riscv64</td>
<td style="text-align: left;">riscv64-linux-gnu</td>
<td>(all)</td>
</tr>
</tbody>
</table>
<h3 id="building-for-armaarch64">Building for ARM/aarch64</h3>
Expand All @@ -1525,6 +1534,21 @@ <h3 id="building-for-armaarch64">Building for ARM/aarch64</h3>
arm-vfp-sflt, arm-vfp-hflt, arm-sflt, armv5-vfp-sflt, armv6-vfp-hflt.
Note that soft-float ABIs are no longer properly supported by the
JDK.</p>
<h3 id="building-for-risc-v">Building for RISC-V</h3>
<p>The RISC-V community provides a basic <a
href="https://github.com/riscv-collab/riscv-gnu-toolchain">GNU compiler
toolchain</a>, but the <a href="#External-Library-Requirements">external
libraries</a> required by OpenJDK complicate the building process. The
placeholder <code>&lt;toolchain-installed-path&gt;</code> shown below is
the path where you want to install the toolchain.</p>
<ul>
<li><p>Install the RISC-V GNU compiler toolchain:
<code>git clone --recursive https://github.com/riscv-collab/riscv-gnu-toolchain cd riscv-gnu-toolchain ./configure --prefix=&lt;toolchain-installed-path&gt; make linux export PATH=&lt;toolchain-installed-path&gt;/bin:$PATH</code></p></li>
<li><p>Cross-compile all the required libraries:
<code># An example for libffi git clone https://github.com/libffi/libffi cd libffi ./configure --host=riscv64-unknown-linux-gnu --prefix=&lt;toolchain-installed-path&gt;/sysroot/usr make make install</code></p></li>
<li><p>Configure and build OpenJDK:
<code>bash configure \ --with-boot-jdk=$BOOT_JDK \ --openjdk-target=riscv64-linux-gnu \ --with-sysroot=&lt;toolchain-installed-path&gt;/sysroot \ --with-toolchain-path=&lt;toolchain-installed-path&gt;/bin \ --with-extra-path=&lt;toolchain-installed-path&gt;/bin make images</code></p></li>
</ul>
<h3 id="building-for-musl">Building for musl</h3>
<p>Just like it's possible to cross-compile for a different CPU, it's
possible to cross-compile for musl libc on a glibc-based <em>build</em>
Expand Down
45 changes: 43 additions & 2 deletions doc/building.md
Expand Up @@ -1147,7 +1147,7 @@ Note that X11 is needed even if you only want to build a headless JDK.
### Cross compiling with Debian sysroots

Fortunately, you can create sysroots for foreign architectures with tools
provided by your OS. On Debian/Ubuntu systems, one could use `qemu-deboostrap` to
provided by your OS. On Debian/Ubuntu systems, one could use `debootstrap` to
create the *target* system chroot, which would have the native libraries and headers
specific to that *target* system. After that, we can use the cross-compiler on the *build*
system, pointing into chroot to get the build dependencies right. This allows building
Expand All @@ -1162,14 +1162,16 @@ For example, cross-compiling to AArch64 from x86_64 could be done like this:

* Create chroot on the *build* system, configuring it for *target* system:
```
sudo qemu-debootstrap \
sudo 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,libffi-dev \
--resolve-deps \
buster \
~/sysroot-arm64 \
http://httpredir.debian.org/debian/
# If the target architecture is `riscv64`,
# the path should be `debian-ports` instead of `debian`.
```

* Make sure the symlinks inside the newly created chroot point to proper locations:
Expand Down Expand Up @@ -1217,6 +1219,7 @@ Architectures that are known to successfully cross-compile like this are:
m68k sid m68k m68k-linux-gnu zero
alpha sid alpha alpha-linux-gnu zero
sh4 sid sh4 sh4-linux-gnu zero
riscv64 sid riscv64 riscv64-linux-gnu (all)

### Building for ARM/aarch64

Expand All @@ -1226,6 +1229,44 @@ available using `--with-abi-profile`: arm-vfp-sflt, arm-vfp-hflt, arm-sflt,
armv5-vfp-sflt, armv6-vfp-hflt. Note that soft-float ABIs are no longer
properly supported by the JDK.

### Building for RISC-V

The RISC-V community provides a basic
[GNU compiler toolchain](https://github.com/riscv-collab/riscv-gnu-toolchain),
but the [external libraries](#External-Library-Requirements) required by OpenJDK
complicate the building process. The placeholder `<toolchain-installed-path>`
shown below is the path where you want to install the toolchain.

* Install the RISC-V GNU compiler toolchain:
```
git clone --recursive https://github.com/riscv-collab/riscv-gnu-toolchain
cd riscv-gnu-toolchain
./configure --prefix=<toolchain-installed-path>
make linux
export PATH=<toolchain-installed-path>/bin:$PATH
```

* Cross-compile all the required libraries:
```
# An example for libffi
git clone https://github.com/libffi/libffi
cd libffi
./configure --host=riscv64-unknown-linux-gnu --prefix=<toolchain-installed-path>/sysroot/usr
make
make install
```

* Configure and build OpenJDK:
```
bash configure \
--with-boot-jdk=$BOOT_JDK \
--openjdk-target=riscv64-linux-gnu \
--with-sysroot=<toolchain-installed-path>/sysroot \
--with-toolchain-path=<toolchain-installed-path>/bin \
--with-extra-path=<toolchain-installed-path>/bin
make images
```

### Building for musl

Just like it's possible to cross-compile for a different CPU, it's possible to
Expand Down

1 comment on commit ce6e746

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.