Skip to content

build: Fix qt build for riscv64 #30

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

Merged
merged 2 commits into from
Aug 30, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 3 additions & 1 deletion depends/packages/qt.mk
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ $(package)_patches += support_new_android_ndks.patch fix_android_jni_static.patc
$(package)_patches+= no_sdk_version_check.patch
$(package)_patches+= fix_lib_paths.patch fix_android_pch.patch
$(package)_patches+= qtbase-moc-ignore-gcc-macro.patch fix_limits_header.patch
$(package)_patches += fix_qml_python.patch
$(package)_patches += fix_qml_python.patch riscv_detection.patch fix_riscv_atomic.patch

$(package)_qtdeclarative_file_name = qtdeclarative-$($(package)_suffix)
$(package)_qtdeclarative_sha256_hash = 1267e029abc8424424c419bc1681db069ec76e51270cc220994e0f442c9f78d3
Expand Down Expand Up @@ -267,6 +267,8 @@ define $(package)_preprocess_cmds
patch -p1 -i $($(package)_patch_dir)/qtbase-moc-ignore-gcc-macro.patch && \
patch -p1 -i $($(package)_patch_dir)/fix_limits_header.patch && \
patch -p1 -i $($(package)_patch_dir)/fix_qml_python.patch && \
patch -p1 -i $($(package)_patch_dir)/riscv_detection.patch && \
patch -p1 -i $($(package)_patch_dir)/fix_riscv_atomic.patch && \
mkdir -p qtbase/mkspecs/macx-clang-linux &&\
cp -f qtbase/mkspecs/macx-clang/qplatformdefs.h qtbase/mkspecs/macx-clang-linux/ &&\
cp -f $($(package)_patch_dir)/mac-qmake.conf qtbase/mkspecs/macx-clang-linux/qmake.conf && \
Expand Down
17 changes: 17 additions & 0 deletions depends/patches/qt/fix_riscv_atomic.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
A workaround for error when building for riscv64.

Upstream report: https://bugreports.qt.io/browse/QTBUG-84580

Patch concept: https://bugs.gentoo.org/790689


--- old/qtdeclarative/src/qml/qml.pro
+++ new/qtdeclarative/src/qml/qml.pro
@@ -19,6 +19,7 @@ solaris-cc*:QMAKE_CXXFLAGS_RELEASE -= -O2

# Ensure this gcc optimization is switched off for mips platforms to avoid trouble with JIT.
gcc:isEqual(QT_ARCH, "mips"): QMAKE_CXXFLAGS += -fno-reorder-blocks
+gcc:isEqual(QT_ARCH, "riscv64"): LIBS += -latomic
Copy link
Member

Choose a reason for hiding this comment

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

This differs form the mentioned patch by excluding the check for riscv32. This is ok as we do not release riscv32 binaries:

original patch's relevant line

+ gcc:if(isEqual(QT_ARCH, "riscv32")|isEqual(QT_ARCH, "riscv64")): LIBS += -latomic


DEFINES += QT_NO_FOREACH

41 changes: 41 additions & 0 deletions depends/patches/qt/riscv_detection.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
Add RISC-V detection

Upstream commit:
- Qt 5.14: 9a6a84731131b205f74b10f866ae212e0895bd4a

--- old/qtbase/src/corelib/global/archdetect.cpp
+++ new/qtbase/src/corelib/global/archdetect.cpp
@@ -67,6 +67,10 @@
# define ARCH_PROCESSOR "power"
#elif defined(Q_PROCESSOR_POWER_64)
# define ARCH_PROCESSOR "power64"
+#elif defined(Q_PROCESSOR_RISCV_32)
+# define ARCH_PROCESSOR "riscv32"
+#elif defined(Q_PROCESSOR_RISCV_64)
+# define ARCH_PROCESSOR "riscv64"
#elif defined(Q_PROCESSOR_S390_X)
# define ARCH_PROCESSOR "s390x"
#elif defined(Q_PROCESSOR_S390)

--- old/qtbase/src/corelib/global/qprocessordetection.h
+++ old/qtbase/src/corelib/global/qprocessordetection.h
@@ -282,6 +282,19 @@
// Q_BYTE_ORDER not defined, use endianness auto-detection

+ /*
+ RISC-V family, known variants: 32- and 64-bit
+ RISC-V is little-endian.
+*/
+#elif defined(__riscv)
+# define Q_PROCESSOR_RISCV
+# if __riscv_xlen == 64
+# define Q_PROCESSOR_RISCV_64
+# else
+# define Q_PROCESSOR_RISCV_32
+# endif
+# define Q_BYTE_ORDER Q_LITTLE_ENDIAN
+
/*
S390 family, known variant: S390X (64-bit)

S390 is big-endian.