# OpenJDK RISC-V Port Cross-compiling Guide ## Prerequisites This guide is based on `adoptopenjdk/centos6_build_image`, which requires docker installed on your machine. - docker - [adoptopenjdk/centos6_build_image](https://hub.docker.com/r/adoptopenjdk/centos6_build_image) Get the latest centos6 build image: ``` $ docker pull adoptopenjdk/centos6_build_image:latest ``` ## Build OpenJDK RISC-V Port From Source Run `adoptopenjdk/centos6_build_image`: ``` $ docker run -it --rm adoptopenjdk/centos6_build_image ``` ### Get Source OpenJDK RISC-V port is upstreamed, you can get source from [openjdk/jdk](https://github.com/openjdk/jdk): ``` $ git clone https://github.com/openjdk/jdk.git ``` ### Configure & Build Cross-compiling setup: ``` # add riscv toolchain to PATH and LD_LIBRARY_PATH $ export RISCV64=/opt/riscv_toolchain_linux $ export LD_LIBRARY_PATH=$RISCV64/lib64:/usr/local/gcc/lib64:/usr/local/gcc/lib $ export PATH="$RISCV64/bin:$PATH" $ export CC=$RISCV64/bin/riscv64-unknown-linux-gnu-gcc $ export CXX=$RISCV64/bin/riscv64-unknown-linux-gnu-g++ # configure and build $ bash configure \ --openjdk-target=riscv64-unknown-linux-gnu \ --with-sysroot=/opt/fedora28_riscv_root \ --with-boot-jdk=/usr/lib/jvm/jdk-17 \ BUILD_CC=/usr/local/gcc/bin/gcc-7.5 \ BUILD_CXX=/usr/local/gcc/bin/g++-7.5 $ make images ``` ## Version Test ### Build QEMU from source Get source code: ``` git clone https://github.com/qemu/qemu.git ``` Configure and build: ``` cd qemu && mkdir build && cd build ../configure --prefix=/path/to/install/qemu --target-list=riscv64-linux-user,riscv64-softmmu make -j && make install ``` ### QEMU User Mode When running version test with QEMU user mode, you need to set the library path with `-L` option: ``` $ qemu-riscv64 -L /path/to/sysroot /path/to/openjdk-riscv/bin/java -version ``` For example: ``` $ qemu-riscv64 -L /opt/fedora28_riscv_root jdk/bin/java -version ``` ### QMEU System Mode It is easier to run in QEMU system mode, following command would be enough: ``` $ /path/to/openjdk-riscv/bin/java -version ``` For example: ``` $ jdk/bin/java -version ``` The output should be: ``` openjdk version "19-internal" 2022-09-20 OpenJDK Runtime Environment (build 19-internal+0-adhoc..riscv-port) OpenJDK 64-Bit Server VM (build 19-internal+0-adhoc..riscv-port, mixed mode, sharing) ```