Skip to content

Commit 2a85b24

Browse files
committed
Add compilation instructions for RISC-V
1 parent d459bb9 commit 2a85b24

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

contributing/development/compiling/compiling_for_linuxbsd.rst

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,72 @@ You don't even need to copy them, you can just reference the resulting
363363
files in the ``bin/`` directory of your Godot source folder, so the next
364364
time you build, you automatically have the custom templates referenced.
365365

366+
Cross-compiling for RISC-V devices
367+
----------------------------------
368+
369+
To cross-compile Godot for RISC-V devices, we need to setup the following items:
370+
371+
- `riscv-gnu-toolchain <https://github.com/riscv-collab/riscv-gnu-toolchain/releases>`__.
372+
While we are not going to use this directly, it provides us with a sysroot, as well
373+
as header and libraries files that we will need. There are many versions to choose
374+
from, however, the older the toolchain, the more compatible our final binaries will be.
375+
If in doubt, `use this version <https://github.com/riscv-collab/riscv-gnu-toolchain/releases/tag/2021.12.22>`__,
376+
and download ``riscv64-glibc-ubuntu-18.04-nightly-2021.12.22-nightly.tar.gz``. Extract
377+
it somewhere and remember its path.
378+
- Clang. RISC-V GCC has
379+
`bugs with its atomic operations <https://github.com/riscv-collab/riscv-gcc/issues/15>`__
380+
which prevent it from compiling Godot correctly. Any version of Clang from 16.0.0 upwards
381+
will suffice. Download it from the package manager of your distro, and make sure that
382+
it *can* compile to RISC-V. You can verify by executing this command ``clang -print-targets``,
383+
make sure you see ``riscv64`` on the list of targets.
384+
- `mold <https://github.com/rui314/mold/releases>`__. This fast linker,
385+
is the only one that correctly links the resulting binary. Download it, extract it,
386+
and make sure to add its ``bin`` folder to your PATH. Run
387+
``mold --help | grep support`` to check if your version of Mold supports RISC-V.
388+
If you don't see RISC-V, your Mold may need to be updated.
389+
390+
To make referencing our toolchain easier, we can set an environment
391+
variable like this:
392+
393+
::
394+
395+
export RISCV_TOOLCHAIN_PATH="path to toolchain here"
396+
397+
This way, we won't have to manually set the directory location
398+
each time we want to reference it.
399+
400+
With all the above setup, we are now ready to build Godot.
401+
402+
Go to the root of the source code, and execute the following build command:
403+
404+
::
405+
406+
scons arch=rv64 use_llvm=yes linker=mold lto=none target=editor \
407+
ccflags="--sysroot=$RISCV_TOOLCHAIN_PATH/sysroot --gcc-toolchain=$RISCV_TOOLCHAIN_PATH -target riscv64-unknown-linux-gnu" \
408+
linkflags="--sysroot=$RISCV_TOOLCHAIN_PATH/sysroot --gcc-toolchain=$RISCV_TOOLCHAIN_PATH -target riscv64-unknown-linux-gnu"
409+
410+
The command is similar in nature, but with some key changes. ``ccflags`` and
411+
``linkflags`` append additional flags to the build. ``--sysroot`` points to
412+
a folder simulating a Linux system, it contains all the headers, libraries,
413+
and ``.so`` files Clang will use. ``--gcc-toolchain`` tells Clang where
414+
the complete toolchain is, and ``-target riscv64-unknown-linux-gnu``
415+
indicates to Clang the target architecture, and OS we want to build for.
416+
417+
If all went well, you should now see a ``bin`` directory, and within it,
418+
a binary similar to the following:
419+
420+
::
421+
422+
godot.linuxbsd.editor.rv64.llvm
423+
424+
You can now copy this executable to your favorite RISC-V device,
425+
then launch it there by double-clicking, which should bring up
426+
the project manager.
427+
428+
If you later decide to compile the export templates, copy the above
429+
build command but change the value of ``target`` to ``template_debug`` for
430+
a debug build, or ``template_release`` for a release build.
431+
366432
Using Clang and LLD for faster development
367433
------------------------------------------
368434

0 commit comments

Comments
 (0)