Add a riscv64 cross build, generalizing the loongarch64 one

The pieces were nearly all in place already - CMakeLists has detected
riscv64 and set RISCV64 since the backend landed - so this is mostly a
matter of not hardcoding loongarch64 in the cross-build plumbing:

- setup-loongarch64-cross.sh becomes setup-cross.sh <target>, taking the
  triple and dynamic linker name from the argument.
- b.sh gains --riscv64, and the GL stub block is keyed off a compiler
  variable rather than a loongarch64-only flag.
- New cmake/Toolchains/riscv64-linux-gnu.cmake, mirroring the existing one.

The SDL carve-out moves from LOONGARCH64_DEVICE to a new HEADLESS_CROSS
option set by b.sh. That flag was keyed off the target architecture, which
is also true when building natively on such a machine - harmless so far,
but riscv64 hardware that people actually build PPSSPP on exists, and it
should still get the normal SDL frontend.

Both toolchain files now find qemu rather than assuming the static build:
Debian ships the static binaries in qemu-user-static and the dynamic ones
in qemu-user, and only the latter is available on some releases. Neither
being present is fine too - it just means no compile-check programs run.

Verified by a clean loongarch64 build; riscv64 is untested so far, the
toolchain isn't installed here yet.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
This commit is contained in:
Henrik RydgårdandClaude Opus 5 committed 2026-09-19 11:52:16 -06:00
1 parent ba06b454f3
commit 9a29bf84d8
6 files changed
+129 -46

No files matched your search

+12 -7
View File
@@ -31,9 +31,14 @@ do
CMAKE_ARGS="-DCMAKE_TOOLCHAIN_FILE=cmake/Toolchains/raspberry.armv8.cmake ${CMAKE_ARGS}"
;;
--loongarch64)
CMAKE_ARGS="-DCMAKE_TOOLCHAIN_FILE=cmake/Toolchains/loongarch64-linux-gnu.cmake -DHEADLESS=ON -DUSE_SYSTEM_LIBPNG=OFF -DUSE_SYSTEM_LIBSDL2=OFF ${CMAKE_ARGS}"
CMAKE_ARGS="-DCMAKE_TOOLCHAIN_FILE=cmake/Toolchains/loongarch64-linux-gnu.cmake -DHEADLESS=ON -DHEADLESS_CROSS=ON -DUSE_SYSTEM_LIBPNG=OFF -DUSE_SYSTEM_LIBSDL2=OFF ${CMAKE_ARGS}"
TARGET_OS=loongarch64
LOONGARCH64_BUILD=1
CROSS_STUB_CC=loongarch64-linux-gnu-gcc-14
;;
--riscv64)
CMAKE_ARGS="-DCMAKE_TOOLCHAIN_FILE=cmake/Toolchains/riscv64-linux-gnu.cmake -DHEADLESS=ON -DHEADLESS_CROSS=ON -DUSE_SYSTEM_LIBPNG=OFF -DUSE_SYSTEM_LIBSDL2=OFF ${CMAKE_ARGS}"
TARGET_OS=riscv64
CROSS_STUB_CC=riscv64-linux-gnu-gcc-14
;;
--android) CMAKE_ARGS="-DCMAKE_TOOLCHAIN_FILE=android/android.toolchain.cmake ${CMAKE_ARGS}"
TARGET_OS=Android
@@ -122,16 +127,16 @@ echo Building with $CORES_COUNT threads
mkdir -p ${BUILD_DIR}
# For loongarch64 cross-compilation, build a comprehensive GL/GLX stub into
# For the headless cross targets, build a comprehensive GL/GLX stub into
# <build>/stublibs/libGL.so so GLEW's static archive can resolve its symbols
# via PLT entries (a direct B26 branch to address 0 overflows on LoongArch).
# via PLT entries (a direct branch to address 0 overflows the relocation).
# This stub is always (re)generated to pick up any new needed symbols.
if [ ! -z "$LOONGARCH64_BUILD" ]; then
if [ ! -z "$CROSS_STUB_CC" ]; then
STUB_DIR=${BUILD_DIR}/stublibs
STUB_GL=${STUB_DIR}/libGL.so
mkdir -p "${STUB_DIR}"
STUB_C=$(mktemp /tmp/gl_stub_XXXXXX.c)
echo "/* Loongarch64 GL/GLX stub - cross-compilation only */" > "$STUB_C"
echo "/* ${TARGET_OS} GL/GLX stub - cross-compilation only */" > "$STUB_C"
# Collect all T (exported) symbols from GL/GLX libs, deduplicate, emit stubs
HOST_MULTIARCH=$(gcc -print-multiarch 2>/dev/null || dpkg-architecture -qDEB_HOST_MULTIARCH 2>/dev/null)
{
@@ -144,7 +149,7 @@ if [ ! -z "$LOONGARCH64_BUILD" ]; then
printf '%s\n' glXGetProcAddressARB glXGetClientString glXQueryVersion \
glBindTexture glGetString glGetIntegerv
} | sort -u | awk '{ print "void "$1"(void){}" }' >> "$STUB_C"
loongarch64-linux-gnu-gcc-14 -shared -fPIC -Wno-implicit-function-declaration \
$CROSS_STUB_CC -shared -fPIC -Wno-implicit-function-declaration \
-o "${STUB_GL}" "$STUB_C"
rm "$STUB_C"
fi