Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix instruction for RISC-V (the previous instruction didn't work) #10374

Merged
merged 5 commits into from
Dec 26, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions contributing/development/compiling/compiling_for_linuxbsd.rst
Original file line number Diff line number Diff line change
Expand Up @@ -403,12 +403,6 @@ To cross-compile Godot for RISC-V devices, we need to setup the following items:
If in doubt, `use this version <https://github.com/riscv-collab/riscv-gnu-toolchain/releases/tag/2021.12.22>`__,
and download ``riscv64-glibc-ubuntu-18.04-nightly-2021.12.22-nightly.tar.gz``. Extract
it somewhere and remember its path.
- Clang. RISC-V GCC has
`bugs with its atomic operations <https://github.com/riscv-collab/riscv-gcc/issues/15>`__
which prevent it from compiling Godot correctly. Any version of Clang from 16.0.0 upwards
will suffice. Download it from the package manager of your distro, and make sure that
it *can* compile to RISC-V. You can verify by executing this command ``clang -print-targets``,
make sure you see ``riscv64`` on the list of targets.
Comment on lines -406 to -411
Copy link
Member

@aaronfranke aaronfranke Dec 21, 2024

Choose a reason for hiding this comment

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

We shouldn't remove this section for telling the user to install Clang, even if they can use the toolchain-provided one. The system clang worked for me, and there is no harm in having it. It's also important to tell the user that GCC does not work, and telling the user how to check if Clang supports the target.

Copy link
Contributor Author

@OS-of-S OS-of-S Dec 24, 2024

Choose a reason for hiding this comment

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

Well, the Clang dosn't work for me! It may be matter on the version you're using. What versions of Clang and riscv-gnu-toolchain do you use?

My versions:

  • Clang 18.1.8
  • riscv-gnu-toolchain 2023.06.09
  • Mold 2.34.1

Also a small note about riscv-gnu-toolchain: the official Godot documentation says: "the older the toolchain, the more compatible our final binaries will be", and recommends installing version 2021.12.22-ubuntu-18.04. But I installed version 2023.06.09-ubuntu-20.04, since this is the oldest version with which I was able to compile Godot. For newer ones I get the error
mold: fatal: huf_decompress_amd64.linuxbsd.editor.rv64.llvm.o: incompatible file type: riscv64 is expected but got x86_64
Most likely, a more correct way to install the necessary tools exists (I suspect, related to configuring Clang). It should also be noted that I did not check the functionality of the resulting Godot builds, and given the content of the forms on this topic, there is a high chance that they won't even start.

Copy link
Contributor Author

@OS-of-S OS-of-S Dec 24, 2024

Choose a reason for hiding this comment

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

The rest of the comments make sense and I fully agree with them. I will make corrections regarding the gcc and correct the command for the terminal.

But I still don't know what to say about Clang. May be you have an idea for appropriate wording that will not confuse the reader?

Copy link
Member

Choose a reason for hiding this comment

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

For RISC-V, this platform is so new that the advice about compiling for older Ubuntu versions for better compatibility is superseded by the need to use newer systems for including critical bugfixes. I have upgraded my Ubuntu systems to 24.04 since I last tried this, and I think that is fine as a baseline, given that RISC-V devices are still to this day very niche and will be for several years.

Copy link
Contributor Author

@OS-of-S OS-of-S Dec 24, 2024

Choose a reason for hiding this comment

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

I have upgraded my Ubuntu systems to 24.04 since I last tried this, and I think that is fine as a baseline, given that RISC-V devices are still to this day very niche and will be for several years.

Ok, so... No changes on this page needed?

I still think that if the toolchain have it's own Clang with which it works fine insted of newer one version of Clang we shouldn't insist on installing different Clang. I don't know how it works, but I have an issue with it. Otherwise we need to add a comment that the user should rely on newer versions of Linux (which is already contrary to the documentation and makes it more complicated for user).

I made changes on all other claims in my PR. Maybe we could add such note in page:

"You can use a self-installed version of Clang, but it may have compatibility issues with riscv-gnu-toolchain."

Will this be enough? I'll wait for your opinion.

- `mold <https://github.com/rui314/mold/releases>`__. This fast linker,
is the only one that correctly links the resulting binary. Download it, extract it,
and make sure to add its ``bin`` folder to your PATH. Run
Expand All @@ -425,6 +419,20 @@ variable like this:
This way, we won't have to manually set the directory location
each time we want to reference it.

You also need to add ``$RISCV_TOOLCHAIN_PATH/bin`` to your user's PATH environment variable.

::

PATH="$RISCV_TOOLCHAIN_PATH/bin:$PATH"
Copy link
Member

Choose a reason for hiding this comment

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

Setting this will only work if it's a part of the command as a prefix to it. Otherwise, it will only be changed in the shell itself. https://stackoverflow.com/questions/1158091/defining-a-variable-with-or-without-export

The command below should be edited to include this, it doesn't need its own separate code block.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.


.. warning:: Since riscv-gnu-toolchain uses its own Clang located
in the ``bin`` folder, this command may block you from
accessing another version of Clang if one is installed.
So it's recommended to run this command every time
before compiling Godot for RISC-V devices instead of adding it to the
``$HOME/.bash_profile`` file.


With all the above setup, we are now ready to build Godot.

Go to the root of the source code, and execute the following build command:
Expand All @@ -435,6 +443,13 @@ Go to the root of the source code, and execute the following build command:
ccflags="--sysroot=$RISCV_TOOLCHAIN_PATH/sysroot --gcc-toolchain=$RISCV_TOOLCHAIN_PATH -target riscv64-unknown-linux-gnu" \
linkflags="--sysroot=$RISCV_TOOLCHAIN_PATH/sysroot --gcc-toolchain=$RISCV_TOOLCHAIN_PATH -target riscv64-unknown-linux-gnu"

.. note::

RISC-V GCC has `bugs with its atomic operations <https://github.com/riscv-collab/riscv-gcc/issues/15>`__
which prevent it from compiling Godot correctly. That's why Clang is used instead. Make sure that
it *can* compile to RISC-V. You can verify by executing this command ``clang -print-targets``,
make sure you see ``riscv64`` on the list of targets.

The command is similar in nature, but with some key changes. ``ccflags`` and
``linkflags`` append additional flags to the build. ``--sysroot`` points to
a folder simulating a Linux system, it contains all the headers, libraries,
Expand Down