termux-user-repository / tur

A place for all types of Termux packages.
Other
460 stars 86 forks source link

[Help wanted] Unable to get Qt5 with QOpenGLContext support #848

Closed knyipab closed 8 months ago

knyipab commented 8 months ago

I am working on another package called MLT (which depends on only qt5-qtbase and qt5-qtsvg) and run into Qt OpenGL issue similar to one mentioned in https://github.com/termux-user-repository/tur/issues/510. I copied x11-packages/qt5-qtbase into tur/qt5-qtbase-opengl and modify build.sh as below (and rename subpackages) in the hope of building OpenGL support.

--- x11-packages/qt5-qtbase/build.sh    2024-02-24 08:58:50.133842739 +0000
+++ tur/qt5-qtbase-opengl/build.sh      2024-02-25 02:11:30.893129172 +0000
@@ -6,13 +6,17 @@
 TERMUX_PKG_REVISION=4
 TERMUX_PKG_SRCURL="https://download.qt.io/official_releases/qt/5.15/${TERMUX_PKG_VERSION}/submodules/qtbase-everywhere-opensource-src-${TERMUX_PKG_VERSION}.tar.xz"
 TERMUX_PKG_SHA256=c0d06cb18d20f10bf7ad53552099e097ec39362d30a5d6f104724f55fa1c8fb9
-TERMUX_PKG_DEPENDS="dbus, double-conversion, freetype, glib, harfbuzz, krb5, libandroid-execinfo, libandroid-shmem, libandroid-posix-semaphore, libc++, libice, libicu, libjpeg-turbo, libpng, libsm, libuuid, libx11, libxcb, libxi, libxkbcommon, openssl, pcre2, postgresql, ttf-dejavu, xcb-util-image, xcb-util-keysyms, xcb-util-renderutil, xcb-util-wm, zlib"
+TERMUX_PKG_DEPENDS="dbus, double-conversion, freetype, glib, harfbuzz, krb5, libandroid-execinfo, libandroid-shmem, libandroid-posix-semaphore, libc++, libice, libicu, libjpeg-turbo, libpng, libsm, libuuid, libx11, libxcb, libxi, libxkbcommon, mesa, openssl, pcre2, postgresql, ttf-dejavu, vulkan-loader, xcb-util-image, xcb-util-keysyms, xcb-util-renderutil, xcb-util-wm, zlib"
+TERMUX_PKG_BUILD_DEPENDS="vulkan-headers"
 # gtk3 dependency is a run-time dependency only for the gtk platformtheme subpackage
 TERMUX_PKG_BUILD_DEPENDS="gtk3"
+TERMUX_PKG_CONFLICTS="qt5-qtbase"
+TERMUX_PKG_PROVIDES="qt5-qtbase"
 TERMUX_PKG_SUGGESTS="qt5-qmake"
 TERMUX_PKG_BUILD_IN_SRC=true
 TERMUX_PKG_NO_STATICSPLIT=true

+
 TERMUX_PKG_RM_AFTER_INSTALL="
 bin/fixqt4headers.pl
 bin/syncqt.pl
@@ -84,6 +88,11 @@
         -I "${TERMUX_PREFIX}/include/freetype2" \
         -I "${TERMUX_PREFIX}/include/gdk-pixbuf-2.0" \
         -I "${TERMUX_PREFIX}/include/gtk-3.0" \
+        -I "${TERMUX_PREFIX}/include/GL" \
+        -I "${TERMUX_PREFIX}/include/GLES" \
+        -I "${TERMUX_PREFIX}/include/GLES2" \
+        -I "${TERMUX_PREFIX}/include/GLES3" \
+        -I "${TERMUX_PREFIX}/include/vulkan" \
         -L "${TERMUX_PREFIX}/lib" \
         -nomake examples \
         -no-pch \
@@ -100,8 +109,6 @@
         -no-system-proxies \
         -no-cups \
         -system-harfbuzz \
-        -no-opengl \
-        -no-vulkan \
         -qpa xcb \
         -no-eglfs \
         -no-gbm \
@@ -181,7 +188,7 @@
     #######################################################

     # Limit the scope, otherwise it'll touch other Qt files in a dirty host env
-    for i in Bootstrap Concurrent Core DBus DeviceDiscoverySupport EdidSupport EventDispatcherSupport FbSupport FontDatabaseSupport Gui InputSupport Network PrintSupport ServiceSupport Sql Test ThemeSupport Widget XcbQpa XkbCommonSupport Xml Zlib; do
+    for i in Bootstrap Concurrent Core DBus DeviceDiscoverySupport EdidSupport EventDispatcherSupport FbSupport FontDatabaseSupport Gui InputSupport Network PrintSupport ServiceSupport Sql Test ThemeSupport Widgets OpenGL XcbQpa XkbCommonSupport Xml Zlib; do
         ## Drop QMAKE_PRL_BUILD_DIR because reference the build dir.
         find "${TERMUX_PREFIX}/lib" -type f -name "libQt5${i}.prl" \
             -exec sed -i -e '/^QMAKE_PRL_BUILD_DIR/d' "{}" \;

This qt5-qtbase-opengl package does compile, but does not resolve or change anything of the MLT OpenGLContext error (shown below):

FAILED: src/modules/qt/CMakeFiles/mltqt.dir/consumer_qglsl.cpp.o 
/home/vscode/.termux-build/_cache/android-r26b-api-24-v1/bin/clang++ --target=aarch64-none-linux-android --gcc-toolchain=/home/vscode/.termux-build/_cache/android-r26b-api-24-v1 --sysroot=/home/vscode/.termux-build/_cache/android-r26b-api-24-v1/sysroot -DGPL3 -DNODEPLOY -DQT_CORE_LIB -DQT_GUI_LIB -DQT_NO_DEBUG -DQT_SVG_LIB -DQT_WIDGETS_LIB -DQT_XML_LIB -DUSE_QT_OPENGL -Dmltqt_EXPORTS -I/home/vscode/.termux-build/mlt/build/src/modules/qt/mltqt_autogen/include -I/home/vscode/.termux-build/mlt/src/src/mlt++ -I/home/vscode/.termux-build/mlt/src/src/framework/.. -isystem /data/data/com.termux/files/usr/include/QtCore -isystem /data/data/com.termux/files/usr/lib/qt/mkspecs/termux-cross -isystem /data/data/com.termux/files/usr/include/QtGui -isystem /data/data/com.termux/files/usr/include/QtXml -isystem /data/data/com.termux/files/usr/include/QtSvg -isystem /data/data/com.termux/files/usr/include/QtWidgets -fstack-protector-strong -Oz --target=aarch64-linux-android24  -I/data/data/com.termux/files/usr/include -O3 -DNDEBUG -std=c++14 -fPIC -ffast-math -fPIC -MD -MT src/modules/qt/CMakeFiles/mltqt.dir/consumer_qglsl.cpp.o -MF src/modules/qt/CMakeFiles/mltqt.dir/consumer_qglsl.cpp.o.d -o src/modules/qt/CMakeFiles/mltqt.dir/consumer_qglsl.cpp.o -c /home/vscode/.termux-build/mlt/src/src/modules/qt/consumer_qglsl.cpp
/home/vscode/.termux-build/mlt/src/src/modules/qt/consumer_qglsl.cpp:38:25: error: allocation of incomplete type 'QOpenGLContext'
        , m_context(new QOpenGLContext)
                        ^~~~~~~~~~~~~~
/data/data/com.termux/files/usr/include/QtGui/qsurfaceformat.h:49:7: note: forward declaration of 'QOpenGLContext'
class QOpenGLContext;
      ^
/home/vscode/.termux-build/mlt/src/src/modules/qt/consumer_qglsl.cpp:47:18: error: member access into incomplete type 'QOpenGLContext'
        m_context->setFormat(format);
                 ^
/data/data/com.termux/files/usr/include/QtGui/qsurfaceformat.h:49:7: note: forward declaration of 'QOpenGLContext'
class QOpenGLContext;
      ^
/home/vscode/.termux-build/mlt/src/src/modules/qt/consumer_qglsl.cpp:48:18: error: member access into incomplete type 'QOpenGLContext'
        m_context->create();
                 ^
/data/data/com.termux/files/usr/include/QtGui/qsurfaceformat.h:49:7: note: forward declaration of 'QOpenGLContext'
class QOpenGLContext;
      ^
/home/vscode/.termux-build/mlt/src/src/modules/qt/consumer_qglsl.cpp:49:18: error: member access into incomplete type 'QOpenGLContext'
        m_context->moveToThread(this);
                 ^
/data/data/com.termux/files/usr/include/QtGui/qsurfaceformat.h:49:7: note: forward declaration of 'QOpenGLContext'
class QOpenGLContext;
      ^
/home/vscode/.termux-build/mlt/src/src/modules/qt/consumer_qglsl.cpp:58:27: error: member access into incomplete type 'QOpenGLContext'
        Q_ASSERT(m_context->isValid());
                          ^
/data/data/com.termux/files/usr/include/QtGui/qsurfaceformat.h:49:7: note: forward declaration of 'QOpenGLContext'
class QOpenGLContext;
      ^
/home/vscode/.termux-build/mlt/src/src/modules/qt/consumer_qglsl.cpp:59:18: error: member access into incomplete type 'QOpenGLContext'
        m_context->makeCurrent(m_surface.get());
                 ^
/data/data/com.termux/files/usr/include/QtGui/qsurfaceformat.h:49:7: note: forward declaration of 'QOpenGLContext'
class QOpenGLContext;
      ^
/home/vscode/.termux-build/mlt/src/src/modules/qt/consumer_qglsl.cpp:61:18: error: member access into incomplete type 'QOpenGLContext'
        m_context->doneCurrent();
                 ^
/data/data/com.termux/files/usr/include/QtGui/qsurfaceformat.h:49:7: note: forward declaration of 'QOpenGLContext'
class QOpenGLContext;

If I patch MLT by commenting all QOpenGLContext related lines, it does compile. But later when I compile shotcut, there will be more and I cannot simply comment them. So, I need to get QOpenGLContext ready. What does this error actually mean and how can I compile the qt5-qtbase-opengl to really support QOpenGLContext?

Full log (qt5-qtbase-opengl and then mlt): mlt-build.log

Full build source code mlt: https://github.com/knyipab/tur/tree/MLT/tur/mlt Full build source code qt5-qtbase-opengl: https://github.com/knyipab/tur/tree/MLT/tur/qt5-qtbase-opengl

knyipab commented 8 months ago

I found out the root cause. MLT depends on qt5-qtsvg which depends on qt5-qtbase therefore remove my qt5-qtbase-opengl before building MLT. I could not find a fix other than making a qt5-qtsvg-opengl package.

licy183 commented 8 months ago

You can try adding qt5-qtbase to TERMUX_PKG_ANTI_BUILD_DEPENDS.

knyipab commented 8 months ago

Thanks for advice. Unfortunately it does not seem to work.

mlt succeeds (shown in this github action) with this line (qt5-qtsvg-opengl) in build.sh:

TERMUX_PKG_DEPENDS="ffmpeg, frei0r-plugins, qt5-qtbase-opengl, qt5-qtsvg-opengl, sdl, sdl2, swig"

mlt-2 fails (shown in this github action) with these lines (TERMUX_PKG_ANTI_BUILD_DEPENDS) in build.sh:

TERMUX_PKG_DEPENDS="ffmpeg, frei0r-plugins, qt5-qtbase-opengl, qt5-qtsvg, sdl, sdl2, swig"
TERMUX_PKG_BUILD_DEPENDS="qt5-qtbase-opengl-cross-tools"
TERMUX_PKG_ANTI_BUILD_DEPENDS="qt5-qtbase, qt5-qtbase-cross-tools"

We know that it's really not ideal to rebuild the whole series of qt5-* packages in qt5-*-opengl fashion, neither making a request to qt5-qtbase in the main repo. More qt5 packages will be needed when building apps like shotcut.

I guess the most similar case is mesa. Perhaps (??? Not sure) that mesa-zink serves same libs and include files as mesa, so mesa-zink-dependent packages would not feel any difference in build time when dependencies of dependencies contain mesa?

licy183 commented 8 months ago

Packaging all the qt5-* packages should be a solution. Extra testing should be done on these packages before adding them to the main repo. I suppose that enabling opengl in qt will make UI clunky because default opengl library is CPU-based llvmpipe...

knyipab commented 8 months ago

I found that writing the corresponding version into $TERMUX_BUILT_PACKAGES_DIRECTORY/qt5-qtbase can trick the build system to believe that the dependency is satisfied. But that doesn't work for qt5 packages (segfault in runtime), perhaps because some function or struct specifications changes when opengl feature is turned on.

At the end, I have to rebuild the series of qt5-*-opengl. I doubt whether to add back to the main repo as qt5 is end of life.

Still, termux native build is preferred over proot Also, proot qt has opengl ON and seems to work just fine. And perhaps the performance impact on non-opengl app is not that significant.

Besides, I hope to see qt6 with opengl feature ON in the future. I'm happy to contribute but building qt6 doesn't seem easy (building twice with cmake, first building natively and second cross compiling).