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

ahead-of-time compilation of QML #242

Closed
Be-ing opened this issue Sep 8, 2022 · 5 comments · Fixed by #649
Closed

ahead-of-time compilation of QML #242

Be-ing opened this issue Sep 8, 2022 · 5 comments · Fixed by #649
Assignees
Labels
🔨 build system Issues related to integrating CXX-Qt into CMake/Cargo
Milestone

Comments

@Be-ing
Copy link
Contributor

Be-ing commented Sep 8, 2022

It would be nice if qt-build could call qmlcachegen (Qt5) or qmlsc (Qt6).

https://www.qt.io/blog/the-new-qtquick-compiler-technology

However qmlsc is not open source yet:

qmlsc is available for commercial customers and some of its features are merged into qmlcachegen, which continues to be available with all versions of Qt.

https://doc.qt.io/qt-6/qtqml-tool-qmlsc.html

@ahayzen-kdab
Copy link
Collaborator

There is also the qmltc https://doc.qt.io/qt-6/qtqml-tool-qmltc.html https://www.qt.io/blog/qml-type-compilation

And we should support commercial tools as well.

@Be-ing
Copy link
Contributor Author

Be-ing commented Feb 9, 2023

After reading various posts on the Qt blog and the documentation for the upcoming Qt 6.5 release, I have a better understanding of the various QML processing tools and how to approach this.

Originally, in Qt 5, qmlcachegen only generated precompiled bytecode from QML files to improve startup performance. qmake could automatically call qmlcachegen and add the generated bytecode to the Qt resource system. In Qt 5, qmlcachegen didn't optimize runtime performance though.

This has changed in Qt6. qmlcachegen can now compile some parts of QML to C++ files containing "QML compilation units", which include the compiled parts of the QML and the rest as bytecode embedded into the C++ files. qmlsc does the same thing as qmlcachegen but can compile QML to C++ in more cases. qmlsc is not open source and it doesn't seem it will be, but I'm not entirely sure.

qmltc works differently than both qmlcachegen and qmlsc. It generates C++ classes from the QML files which are more efficient at runtime than the "QML compilation units" generated by qmlcachegen & qmlsc. However, qmltc only works with a limited subset of QML, so using it must be optional. In Qt 6.3 - 6.4, C++ headers generated by qmltc need to be #included to instatiate these classes. I was afraid we'd need to automatically generate Rust bindings for these, but fortunately Qt 6.5 will add a new QQmlApplicationEngine::loadFromModule function which will be able to load qmltc compiled QML types via their QML module URI and type name as QStrings, so we won't need to generate Rust bindings to the generated C++ classes.

So, qmlcachegen is helpful in any case when qmltc isn't used. However, qmlcachegen in Qt 6 has some new command line options in Qt 5 which are used by the qt_add_qml_module CMake function, so figuring out how to use qmlcachegen with Qt5 would require examining how qmake works with it. In the end, it might require substantially different code between Qt 5 and Qt 6. Considering that drawback, and that qmlcachegen only speeds up load time but not run time in Qt 5, I suggest only supporting qmlcachegen for Qt 6 (qmltc was added in Qt 6.3).

@Be-ing
Copy link
Contributor Author

Be-ing commented Feb 9, 2023

For examining how the qt_add_qml_module CMake function works, I pushed a branch which has commented out code to use it. It needs the headers generated by the Cargo build script, so you need to run a build first with the CMake code commented out, then uncomment the CMake code and comment linking "$<LINK_LIBRARY:WHOLE_ARCHIVE,${CRATE}-static>" to avoid duplicate symbol errors when linking.

@Be-ing Be-ing self-assigned this Feb 9, 2023
@Be-ing Be-ing added this to the 0.6 milestone Feb 9, 2023
@Be-ing
Copy link
Contributor Author

Be-ing commented Feb 20, 2023

qmlcachegen is helpful in any case when qmltc isn't used.

I asked about this on a recent Qt blog post and this isn't quite right. qmlcachegen is always helpful. qmltc can be used together with qmlcachegen; they work on different aspects of speeding up QML.

@Be-ing Be-ing added the 🔨 build system Issues related to integrating CXX-Qt into CMake/Cargo label Jul 7, 2023
Be-ing added a commit to Be-ing/cxx-qt that referenced this issue Jul 25, 2023
This avoids the need to repeatedly specify the URI and version
of the QML module in the bridges. QObjects that are registered as
QML elements are now marked by
[cxx_qt::qobject(qml_element = "OptionalName")]

This is a precursor to generating qmldir files which are required
for qmlcachegen and qmltc
(KDAB#242)
Be-ing added a commit to Be-ing/cxx-qt that referenced this issue Jul 25, 2023
This avoids the need to repeatedly specify the URI and version
of the QML module in the bridges. QObjects that are registered as
QML elements are now marked by
[cxx_qt::qobject(qml_element = "OptionalName")]

This is a precursor to generating qmldir files which are required
for qmlcachegen and qmltc
(KDAB#242)
Be-ing added a commit to Be-ing/cxx-qt that referenced this issue Jul 25, 2023
This avoids the need to repeatedly specify the URI and version
of the QML module in the bridges. QObjects that are registered as
QML elements are now marked by
[cxx_qt::qobject(qml_element = "OptionalName")]

This is a precursor to generating qmldir files which are required
for qmlcachegen and qmltc
(KDAB#242)
Be-ing added a commit to Be-ing/cxx-qt that referenced this issue Jul 25, 2023
This avoids the need to repeatedly specify the URI and version
of the QML module in the bridges. QObjects that are registered as
QML elements are now marked by
[cxx_qt::qobject(qml_element = "OptionalName")]

This is a precursor to generating qmldir files which are required
for qmlcachegen and qmltc
(KDAB#242)
Be-ing added a commit to Be-ing/cxx-qt that referenced this issue Jul 25, 2023
This avoids the need to repeatedly specify the URI and version
of the QML module in the bridges. QObjects that are registered as
QML elements are now marked by
[cxx_qt::qobject(qml_element = "OptionalName")]

This is a precursor to generating qmldir files which are required
for qmlcachegen and qmltc
(KDAB#242)
@Be-ing
Copy link
Contributor Author

Be-ing commented Jul 25, 2023

Qt 6.5 will add a new QQmlApplicationEngine::loadFromModule function which will be able to load qmltc compiled QML types via their QML module URI and type name as QStrings, so we won't need to generate Rust bindings to the generated C++ classes.

This is detailed in a new blog post now that Qt 6.5 has been released: https://www.qt.io/blog/whats-new-for-qml-modules-in-6.5

Be-ing added a commit to Be-ing/cxx-qt that referenced this issue Jul 25, 2023
This avoids the need to repeatedly specify the URI and version
of the QML module in the bridges. QObjects that are registered as
QML elements are now marked by
[cxx_qt::qobject(qml_element = "OptionalName")]

This is a precursor to generating qmldir files which are required
for qmlcachegen and qmltc
(KDAB#242)
Be-ing added a commit to Be-ing/cxx-qt that referenced this issue Jul 25, 2023
This avoids the need to repeatedly specify the URI and version
of the QML module in the bridges. QObjects that are registered as
QML elements are now marked by
[cxx_qt::qobject(qml_element = "OptionalName")]

This is a precursor to generating qmldir files which are required
for qmlcachegen and qmltc
(KDAB#242)
Be-ing added a commit to Be-ing/cxx-qt that referenced this issue Jul 26, 2023
This avoids the need to repeatedly specify the URI and version
of the QML module in the bridges. QObjects that are registered as
QML elements are now marked by
[cxx_qt::qobject(qml_element = "OptionalName")]

This is a precursor to generating qmldir files which are required
for qmlcachegen and qmltc
(KDAB#242)
ahayzen-kdab pushed a commit that referenced this issue Jul 26, 2023
This avoids the need to repeatedly specify the URI and version
of the QML module in the bridges. QObjects that are registered as
QML elements are now marked by
[cxx_qt::qobject(qml_element = "OptionalName")]

This is a precursor to generating qmldir files which are required
for qmlcachegen and qmltc
(#242)
Be-ing added a commit to Be-ing/cxx-qt that referenced this issue Aug 3, 2023
This is a prerequisite for using qmlcachegen
KDAB#242
Be-ing added a commit to Be-ing/cxx-qt that referenced this issue Aug 3, 2023
This is a prerequisite for using qmlcachegen
KDAB#242
Be-ing added a commit to Be-ing/cxx-qt that referenced this issue Aug 8, 2023
This is a prerequisite for using qmlcachegen
KDAB#242
Be-ing added a commit to Be-ing/cxx-qt that referenced this issue Aug 8, 2023
This is a prerequisite for using qmlcachegen
KDAB#242
Be-ing added a commit to Be-ing/cxx-qt that referenced this issue Aug 8, 2023
This is a prerequisite for using qmlcachegen
KDAB#242
Be-ing added a commit to Be-ing/cxx-qt that referenced this issue Aug 8, 2023
Be-ing added a commit to Be-ing/cxx-qt that referenced this issue Aug 8, 2023
This is a prerequisite for using qmlcachegen
KDAB#242
Be-ing added a commit to Be-ing/cxx-qt that referenced this issue Aug 8, 2023
Be-ing added a commit to Be-ing/cxx-qt that referenced this issue Aug 8, 2023
This is a prerequisite for using qmlcachegen
KDAB#242
Be-ing added a commit to Be-ing/cxx-qt that referenced this issue Aug 8, 2023
Be-ing added a commit to Be-ing/cxx-qt that referenced this issue Aug 8, 2023
Be-ing added a commit to Be-ing/cxx-qt that referenced this issue Aug 8, 2023
This is a prerequisite for using qmlcachegen
KDAB#242
Be-ing added a commit to Be-ing/cxx-qt that referenced this issue Aug 8, 2023
Be-ing added a commit to Be-ing/cxx-qt that referenced this issue Aug 8, 2023
This is a prerequisite for using qmlcachegen
KDAB#242
Be-ing added a commit to Be-ing/cxx-qt that referenced this issue Aug 8, 2023
Be-ing added a commit to Be-ing/cxx-qt that referenced this issue Aug 8, 2023
Be-ing added a commit to Be-ing/cxx-qt that referenced this issue Aug 8, 2023
Be-ing added a commit to Be-ing/cxx-qt that referenced this issue Aug 8, 2023
This is a prerequisite for using qmlcachegen
KDAB#242
Be-ing added a commit to Be-ing/cxx-qt that referenced this issue Aug 8, 2023
Be-ing added a commit to Be-ing/cxx-qt that referenced this issue Aug 8, 2023
This is a prerequisite for using qmlcachegen
KDAB#242
Be-ing added a commit to Be-ing/cxx-qt that referenced this issue Aug 8, 2023
Be-ing added a commit to Be-ing/cxx-qt that referenced this issue Aug 8, 2023
This is a prerequisite for using qmlcachegen
KDAB#242
Be-ing added a commit to Be-ing/cxx-qt that referenced this issue Aug 8, 2023
Be-ing added a commit to Be-ing/cxx-qt that referenced this issue Aug 8, 2023
This is a prerequisite for using qmlcachegen
KDAB#242
Be-ing added a commit to Be-ing/cxx-qt that referenced this issue Aug 8, 2023
Be-ing added a commit to Be-ing/cxx-qt that referenced this issue Aug 8, 2023
This is a prerequisite for using qmlcachegen
KDAB#242
Be-ing added a commit to Be-ing/cxx-qt that referenced this issue Aug 8, 2023
Be-ing added a commit to Be-ing/cxx-qt that referenced this issue Aug 8, 2023
This is a prerequisite for using qmlcachegen
KDAB#242
Be-ing added a commit to Be-ing/cxx-qt that referenced this issue Aug 8, 2023
Be-ing added a commit to Be-ing/cxx-qt that referenced this issue Aug 8, 2023
This is a prerequisite for using qmlcachegen
KDAB#242
Be-ing added a commit to Be-ing/cxx-qt that referenced this issue Aug 8, 2023
Be-ing added a commit to Be-ing/cxx-qt that referenced this issue Aug 8, 2023
This is a prerequisite for using qmlcachegen
KDAB#242
Be-ing added a commit to Be-ing/cxx-qt that referenced this issue Aug 8, 2023
Be-ing added a commit to Be-ing/cxx-qt that referenced this issue Aug 8, 2023
This is a prerequisite for using qmlcachegen
KDAB#242
Be-ing added a commit to Be-ing/cxx-qt that referenced this issue Aug 8, 2023
Be-ing added a commit to Be-ing/cxx-qt that referenced this issue Aug 8, 2023
This is a prerequisite for using qmlcachegen
KDAB#242
Be-ing added a commit to Be-ing/cxx-qt that referenced this issue Aug 8, 2023
ahayzen-kdab pushed a commit that referenced this issue Aug 8, 2023
This is a prerequisite for using qmlcachegen
#242
ahayzen-kdab pushed a commit that referenced this issue Aug 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🔨 build system Issues related to integrating CXX-Qt into CMake/Cargo
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants