[Development] Wasm: Support for Emscripten JSPI
Morten Sørvig
Morten.Sorvig at qt.io
Thu Dec 12 16:00:00 CET 2024
> On 10 Dec 2024, at 15:55, Stephan Bergmann <sberg.fun at gmail.com> wrote:
>
> [You don't often get email from sberg.fun at gmail.com. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]
>
> Hi again,
>
> Another thing I'm looking into is the emerging support for JSPI in
> browsers, Emscripten, and Qt. And I wonder whether, in my below
> experiments, I'm holding anything fundamentally wrong (which might
> easily be the case):
Yes, JSP/improved asyncify support is in the works. We are looking at the 6.9+ timeframe, where it should be ready in time for when JSPI becomes supported in general for the browsers.
This should, if it works out, remove one of the obstacles for porting existing code by adding support for making exec() calls.
Some parts are in place already, like "-feature-wasm-jspi” Qt configure flag.
>
> I have a minimal qmake-based project that just shows a window with a
> button, and when the button gets clicked it opens a dialog:
>
>> $ cat dialog.pro
>> CONFIG += debug
>> HEADERS += window.h
>> QT += widgets
>> SOURCES += main.cc
>
>> $ cat window.h
>> #ifndef INCLUDED_window_h
>> #define INCLUDED_window_h
>>
>> #include "QtWidgets/QPushButton"
>> #include "QtWidgets/QWidget"
>>
>> class Window: public QWidget {
>> Q_OBJECT
>> public:
>> Window();
>>
>> private slots:
>> void showDialog();
>>
>> private:
>> QPushButton * button_;
>> };
>>
>> #endif
>
>> $ cat main.cc
>> #include "QtWidgets/QApplication"
>> #include "QtWidgets/QDialog"
>> #include "QtWidgets/QPushButton"
>>
>> #include "window.h"
>>
>> Window::Window() {
>> button_ = new QPushButton("dialog", this);
>> connect(button_, SIGNAL(clicked()), this, SLOT(showDialog()));
>> }
>>
>> void Window::showDialog() {
>> QDialog dialog(this);
>> dialog.exec();
>> }
>>
>> int main(int argc, char ** argv) {
>> QApplication app(argc, argv);
>> Window window;
>> window.show();
>> return app.exec();
>> }
>
> When building this for Wasm and running it in a browser, opening the
> dialog would give the expected
>
>> Warning: exec() is not supported on Qt for WebAssembly in this configuration. Please build with asyncify support, or use an asynchronous API like QDialog::open()
>> Uncaught Please compile your program with async support in order to use asynchronous operations like emscripten_sleep
>
> But when I build recent Qt dev branch configured with
> `-feature-wasm-jspi`, and add `QMAKE_LFLAGS += -sJSPI` to dialog.pro, my
> understanding is that opening the dialog should then work. However, at
> least when I build against recent emsdk 3.1.73, and run in recent Chrome
> 131 with JSPI enabled in <chrome://flags>, opening the dialog causes an
>
>> Uncaught RuntimeError: attempting to suspend without a WebAssembly.promising export
>
> Am I doing anything wrong?
No, this is an internal Qt implementation issue we need to fix (unless you are using EMSCRIPTEN_BINDINGS directly). You could check again closer to the 6.9 release next year - I’ll try to remember to give status update to this thread as well once the Qt implementation is in good shape.
>
> (And a minor observation regarding the need to explicitly set
> `QMAKE_LFLAGS += -sJSPI` as described at
> <https://code.qt.io/cgit/qt/qtdoc.git/commit/?id=7516b4e74feb55a34c4d1409854ad291cafd7b3e>
> "wasm: document asyncify JSPI": My naive understanding is that that
> should no longer be necessary thanks to
> <https://code.qt.io/cgit/qt/qtbase.git/commit/?id=7a21ba15ed0385878ba9bf9741b8df9b61ebe3cc>
> "wasm: support enabling JSPI via QT_EMSCRIPTEN_ASYNCIFY=2", but only
> actually works when configuring Qt with the old `-device-option
> QT_EMSCRIPTEN_ASYNCIFY=2`, but not with the new `-feature-wasm-jspi`
> alternative introduced in
> <https://code.qt.io/cgit/qt/qtbase.git/commit/?id=92ad0f1f014909a792d157dca680fca5cff01605>
> "wasm: add configure option for asyncify JSPI". The latter presumably
> forgot to adapt mkspecs/common/wasm/wasm.conf?)
Good point! The qmake config should be updated as well.
Regards,
Morten
More information about the Development
mailing list