godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
89.56k stars 20.28k forks source link

Unable to compile correctly on RISC-V platform #91381

Closed DSOE1024 closed 4 weeks ago

DSOE1024 commented 5 months ago

Tested versions

4.2 4.1.2

System information

openKylin 2.0 riscv64 StarFive VisionFive V2

Issue description

Hi, this is the fourth system I've tried compiling Godot on a RISC-V device (I've tried Debian, Arch, Ubuntu before, I still haven't built success, all failed). I know RISC-V doesn't have the right chips to run games right now, but there's still a need to run a Godot editor, export templates, and a graphicless server.

Previously I knew that building with gcc would cause problems, this time I tried it and ran into problems again, even though I upgraded to GCC-13.

But clang can't be built this time, that is, can Godot currently compile and run on RISC-V? I don't know if anyone else has tested it.

I added in the Godot document that compiling in RISC-V should use clang, but now there seem to be some problems. First of all, I confirm that gcc13 version is required to be normal in the compilation phase, but errors will be reported in the linking phase, and clang is the same.

Here is my error log information and compiler information.

when use gcc 13 and g++ 13

when use clang

openkylin@openkylin:~/godot$ scons use_llvm=yes -j3
scons: Reading SConscript files ...
Automatically detected platform: linuxbsd
Building for platform "linuxbsd", architecture "rv64", target "editor".
Checking for C header file mntent.h... yes
scons: done reading SConscript files.
scons: Building targets ...
[ 96%] Linking Program bin/godot.linuxbsd.editor.rv64.llvm ...
[100%] progress_finish(["progress_finish"], [])
[100%] drivers/libdrivers.linuxbsd.editor.rv64.llvm.a(rendering_device_vulkan.linuxbsd.editor.rv64.llvm.o): in function `.LBB173_7':
rendering_device_vulkan.cpp:(.text+0x3d39e): relocation truncated to fit: R_RISCV_BRANCH against `.LBB177_194'
servers/libservers.linuxbsd.editor.rv64.llvm.a(render_forward_mobile.linuxbsd.editor.rv64.llvm.o): in function `.LBB6_20':
render_forward_mobile.cpp:(.text+0xa16): relocation truncated to fit: R_RISCV_BRANCH against `.LBB6_339'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
scons: *** [bin/godot.linuxbsd.editor.rv64.llvm] Error 1
scons: building terminated because of errors.
[Time elapsed: 00:11:06.292]

openkylin@openkylin:~/godot$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/riscv64-linux-gnu/13/lto-wrapper
Target: riscv64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Openkylin 13.2.0-4ok3.3' --with-bugurl=file:///usr/share/doc/gcc-13/README.Bugs --enable-languages=c,ada,c++,go,d,fortran,objc,obj-c++,m2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-13 --program-prefix=riscv64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/libexec --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-libitm --disable-libquadmath --disable-libquadmath-support --enable-plugin --with-system-zlib --enable-libphobos-checking=release --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --disable-multilib --with-arch=rv64gc --with-abi=lp64d --enable-checking=release --build=riscv64-linux-gnu --host=riscv64-linux-gnu --target=riscv64-linux-gnu --with-build-config=bootstrap-lto-lean --enable-link-serialization=8
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 13.2.0 (Openkylin 13.2.0-4ok3.3) 

openkylin@openkylin:~/godot$ g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/riscv64-linux-gnu/13/lto-wrapper
Target: riscv64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Openkylin 13.2.0-4ok3.3' --with-bugurl=file:///usr/share/doc/gcc-13/README.Bugs --enable-languages=c,ada,c++,go,d,fortran,objc,obj-c++,m2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-13 --program-prefix=riscv64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/libexec --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-libitm --disable-libquadmath --disable-libquadmath-support --enable-plugin --with-system-zlib --enable-libphobos-checking=release --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --disable-multilib --with-arch=rv64gc --with-abi=lp64d --enable-checking=release --build=riscv64-linux-gnu --host=riscv64-linux-gnu --target=riscv64-linux-gnu --with-build-config=bootstrap-lto-lean --enable-link-serialization=8
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 13.2.0 (Openkylin 13.2.0-4ok3.3) 

openkylin@openkylin:~/godot$ clang -v
Openkylin clang version 15.0.7
Target: riscv64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc/riscv64-linux-gnu/12
Found candidate GCC installation: /usr/bin/../lib/gcc/riscv64-linux-gnu/13
Found candidate GCC installation: /usr/bin/../lib/gcc/riscv64-linux-gnu/8
Found candidate GCC installation: /usr/bin/../lib/gcc/riscv64-linux-gnu/9
Selected GCC installation: /usr/bin/../lib/gcc/riscv64-linux-gnu/13

If you have a different RISC-V board (I tested VisionFive2 and MilkV Mars), you can try compiling Godot and attaching the question to this issue, thank you very much! Love for Godot

Steps to reproduce

scons -j4 scons -j4 use_llvm=yes

akien-mga commented 5 months ago

CC @aaronfranke

MBCX commented 2 months ago

Hello @DSOE1024!

For some time now I was able to successfully cross-compile my custom build of Godot (4.3.beta and 4.2.rc) for RISC-V using GCC+LLVM 19.0.0git. So, I was wondering if you could test these simple 2D projects to see if everything works. Thanks in advance.

test-rv64-43.zip

test-rv64-42.zip

aaronfranke commented 2 months ago

I was able to compile the master branch for RISC-V on the official 2024-05 image, with Clang, and debug builds only (using the command scons use_llvm=yes).

You may also wish to test if export templates compile for you (scons use_llvm=yes target=template_debug).

I made a chart of what compiles and doesn't compile for me here: https://github.com/godotengine/godot-proposals/issues/3374

DSOE1024 commented 2 months ago

我能够在官方 2024-05 映像上使用 Clang 编译 RISC-V 的主分支,并且仅调试构建(使用命令)。scons use_llvm=yes

您可能还希望测试导出模板是否适合您编译 ()。scons use_llvm=yes target=template_debug

我在这里为我制作了一个编译和不编译的图表:godotengine/godot-proposals#3374

Hello, thank you very much for your reply. It seems that version 3.6 has been able to run, but I think version 4.x still can't run on RISC-V platform. What is the cause?

P.s. : I was able to compile with GCC 13, but it didn't start properly

DSOE1024 commented 2 months ago

Hello @DSOE1024!

For some time now I was able to successfully cross-compile my custom build of Godot (4.3.beta and 4.2.rc) for RISC-V using GCC+LLVM 19.0.0git. So, I was wondering if you could test these simple 2D projects to see if everything works. Thanks in advance.

test-rv64-43.zip

test-rv64-42.zip

Hello, I will try to test it in the near future and give you the results

DSOE1024 commented 1 month ago

Hello @DSOE1024!

For some time now I was able to successfully cross-compile my custom build of Godot (4.3.beta and 4.2.rc) for RISC-V using GCC+LLVM 19.0.0git. So, I was wondering if you could test these simple 2D projects to see if everything works. Thanks in advance.

test-rv64-43.zip

test-rv64-42.zip

Hello, I'm sorry for taking so long to reply. Due to performance reasons, I changed my RISC-V device and upgraded it from JH7110 Soc to SpacemiT Key Stone K1. I have tested your project and it starts smoothly and normally using the soft rendering pipeline OpenGL, which is great!

DSOE1024 commented 1 month ago

Hello @DSOE1024!

一段时间以来,我能够使用 GCC+LLVM 19.0.0git 成功地交叉编译用于 RISC-V 的 Godot(4.3.beta 和 4.2.rc)的自定义构建。所以,我想知道你是否可以测试这些简单的 2D 项目,看看是否一切正常。提前致谢。

test-rv64-43.zip

test-rv64-42.zip

Please how did you compile it, the 4.x version currently I can only run in headless mode

I built successfully with llvm17 but it doesn't work, I'm going to try llvm19

Thank you so much

MBCX commented 1 month ago

No problem! I can give you the steps I took to compile it. Keep in mind that I have to do a bit more since I'm cross-compiling, but hopefully not too bad.

  1. Get the official-pre-compiled riscv gnu toolchain. Now, I don't use the GCC that is built here, but instead I use the sysroot it creates so that LLVM can then use to link the correct headers, .so files, etc. In my case, I built this version that is a bit old by now, but has worked for me and for compatibility purposes.
  2. Get a LLVM version that supports risc-v. IIRC, LLVM 16+ will do. This is the one I use
    clang version 19.0.0git (https://github.com/llvm/llvm-project.git 0cee89431d77d0bb0809fd9b2c9d21da2a2783aa)
    Target: x86_64-unknown-linux-gnu
    Thread model: posix
    InstalledDir: /usr/local/bin
  3. Use the mold linker instead of LLD, mold is a fast linker and the only one that (for me) correctly links the resulting binary. You may not needed anyway since I assume you compile on bare metal, but also give it a try as well if you can. My version is
    mold 2.31.0 (3ec4b1787ea412409fbb571f3b9911f23fae2325; compatible with GNU ld)
  4. The full-command I then execute to build godot is:
    scons -j4 arch="rv64" use_llvm="yes" linker="mold" lto="none" \
     target="template_debug" platform="linux" \
     precision="single" module_text_server_fb_enabled="yes" \
     module_theora_enabled="no" \
     module_denoise_enabled="no" \
     module_raycast_enabled="no" \
     module_xatlas_unwrap_enabled="no" \
     ccflags="--sysroot=$HOME/sysroot/riscv-unknown-linux-gnu/sysroot --gcc-toolchain=$HOME/sysroot/riscv-unknown-linux-gnu -target riscv64-unknown-linux-gnu" \
     linkflags="--sysroot=$HOME/sysroot/riscv-unknown-linux-gnu/sysroot --gcc-toolchain=$HOME/sysroot/riscv-unknown-linux-gnu -target riscv64-unknown-linux-gnu"

    where --sysroot is where the sysroot inside the toolchain is located and --gcc-toolchain is the complete toolchain, and finally -target riscv64-unknown-linux-gnu to force LLVM to compile code for RISC-V (again, I assume you're compiling on bare metal so you may not need it).

MBCX commented 1 month ago

Hello @DSOE1024! For some time now I was able to successfully cross-compile my custom build of Godot (4.3.beta and 4.2.rc) for RISC-V using GCC+LLVM 19.0.0git. So, I was wondering if you could test these simple 2D projects to see if everything works. Thanks in advance. test-rv64-43.zip test-rv64-42.zip

Hello, I'm sorry for taking so long to reply. Due to performance reasons, I changed my RISC-V device and upgraded it from JH7110 Soc to SpacemiT Key Stone K1. I have tested your project and it starts smoothly and normally using the soft rendering pipeline OpenGL, which is great!

Good to know that all that time I spent setting-up the toolchain was worth it!

Which version worked though? 4.2, 4.3? Both? @DSOE1024

DSOE1024 commented 1 month ago

您好 !一段时间以来,我能够使用 GCC+LLVM 19.0.0git 成功地为 RISC-V 交叉编译我的 Godot 自定义版本(4.3.beta 和 4.2.rc)。所以,我想知道您是否可以测试这些简单的 2D 项目,看看是否一切正常。提前感谢。 test-rv64-43.zip test-rv64-42.zip

您好,很抱歉花了这么长时间才回复。由于性能原因,我更换了我的 RISC-V 设备,并将其从 JH7110 Soc 升级到 SpacemiT Key Stone K1。我已经测试了您的项目,它使用软渲染管道 OpenGL 顺利且正常地启动,这太棒了!

很高兴知道我花在设置工具链上的所有时间都是值得的!

不过哪个版本有效?4.2, 4.3?双?

Yes, they all work

In the meantime, I'm trying to compile to follow your guide and I'm verifying if it works, thanks

DSOE1024 commented 1 month ago

您好 !一段时间以来,我能够使用 GCC+LLVM 19.0.0git 成功地为 RISC-V 交叉编译我的 Godot 自定义版本(4.3.beta 和 4.2.rc)。所以,我想知道您是否可以测试这些简单的 2D 项目,看看是否一切正常。提前感谢。 test-rv64-43.zip test-rv64-42.zip

您好,很抱歉花了这么长时间才回复。由于性能原因,我更换了我的 RISC-V 设备,并将其从 JH7110 Soc 升级到 SpacemiT Key Stone K1。我已经测试了您的项目,它使用软渲染管道 OpenGL 顺利且正常地启动,这太棒了!

很高兴知道我花在设置工具链上的所有时间都是值得的!

不过哪个版本有效?4.2, 4.3?双?

Yes, they all work

In the meantime, I'm trying to compile to follow your guide and I'm verifying if it works, thanks

MBCX commented 1 month ago

Sweet!!

I'd like you to do one more test if you can, confirm if my builds also make a fully-usable 4.x editor Download them here (too big to upload on GitHub)

Friendly ping @aaronfranke, could you also test these binaries and confirm if they work on your RISC-V devices, if you can?

DSOE1024 commented 1 month ago

甜!!

如果可以的话,我希望你再做一次测试,确认我的构建是否也能成为一个完全可用的 4.x 编辑器 在这里下载它们(太大了,无法上传到 GitHub)

友好的 ping ,如果可以,您能否也测试这些二进制文件并确认它们是否适用于您的 RISC-V 设备?

Wow, they can all run up, on top of my MuseBook (K1 chip)

DSOE1024 commented 1 month ago

Sweet!!

I'd like you to do one more test if you can, confirm if my builds also make a fully-usable 4.x editor Download them here (too big to upload on GitHub)

Friendly ping @aaronfranke, could you also test these binaries and confirm if they work on your RISC-V devices, if you can?

Can we fork a godot repository and create an Action for the RISC-V version?

DSOE1024 commented 4 weeks ago

Sweet!!

I'd like you to do one more test if you can, confirm if my builds also make a fully-usable 4.x editor Download them here (too big to upload on GitHub)

Friendly ping @aaronfranke, could you also test these binaries and confirm if they work on your RISC-V devices, if you can?

Hello, I verified that compiling and running Godot natively on RISC-V devices, using clang-17 under openKylin 2.0 system (I think it may be better than clang-19, more stable), gcc-13, mold 2.4 compiling Godot went very smoothly, and the GPU DDK in openKylin 2.0 is complete, so you can call IMG's GPU to start with GLES backend, which is relatively smooth.

I have verified on SpacemiT K1, and I will verify the operation on the development board equipped with JH7110, SG2042, etc

MBCX commented 4 weeks ago

Thanks, so it sounds I've discovered the krappy-patty formula!

I'm currently writing the detailed instructions in the docs, so that you can give them a look.