Do you guys know how to make it work with the Wasm backend, or should I try asking at the Emscripten GitHub page? The LLVM Wasm backend is the latest, tip-of-the-tree build of vanilla LLVM. It can be installed with the `latest-upstream` package (`emsdk install latest-upstream`).

Do you guys know how to make it work with the Wasm backend, or should I try asking at the Emscripten GitHub page? The LLVM Wasm backend is the latest, tip-of-the-tree build of vanilla LLVM. It can be installed with the `latest-upstream` package (`emsdk install latest-upstream`).

I'm not building Qt. I installed Qt 5.13.1 binaries. I'm trying to build the Notepad App to Wasm (from the Getting Started Guide (I already built it natively in Qt Creator)).

The problem I'm having right now is that the Makefile that the qmake program generated for the Notepad app has BINARYEN_TRAP_MODE set which for the Emscripten Wasm backend is bad. But even after removing that I still get errors.

Do you guys know how to make it work with the Wasm backend, or should I try asking at the Emscripten GitHub page? The LLVM Wasm backend is the latest, tip-of-the-tree build of vanilla LLVM. It can be installed with the `latest-upstream` package (`emsdk install latest-upstream`).

I'm not building Qt. I installed Qt 5.13.1 binaries. I'm trying to build the Notepad App to Wasm (from the Getting Started Guide (I already built it natively in Qt Creator)).

The problem I'm having right now is that the Makefile that the qmake program generated for the Notepad app has BINARYEN_TRAP_MODE set which for the Emscripten Wasm backend is bad. But even after removing that I still get errors.

I installed the latest version of Emscripten. I did need to execute git pull just now though. But it could be that the version I have is too new for Qt (could that be the case?).

By the way. Do you understand what I mean when I say "Emscripten Wasm backend"? That's the backend I'm using. It's the one using LLVM without the Emscripten changes to LLVM. Basically "vanilla" LLVM which you need the latest tip-of-the-tree version of. Later than the current stable version. The regular backend is called the Fastcomp backend. I heard they're going to make the Wasm backend the default backend. And the BINARYEN_TRAP_MODE setting being used is bad for the Wasm backend. (I don't mean to look down on you or anything. I'm really just checking to make sure we're on the same page here.)

I don't understand what the condition is in the Makefile that has to be false for the EMCC_COMMON_LFLAGS += -s \"BINARYEN_TRAP_MODE=\'clamp\'\" line to be added in its else clause. What kind of object files is it looking for?

I installed the latest version of Emscripten. I did need to execute git pull just now though. But it could be that the version I have is too new for Qt (could that be the case?).

By the way. Do you understand what I mean when I say "Emscripten Wasm backend"? That's the backend I'm using. It's the one using LLVM without the Emscripten changes to LLVM. Basically "vanilla" LLVM which you need the latest tip-of-the-tree version of. Later than the current stable version. The regular backend is called the Fastcomp backend. I heard they're going to make the Wasm backend the default backend. And the BINARYEN_TRAP_MODE setting being used is bad for the Wasm backend. (I don't mean to look down on you or anything. I'm really just checking to make sure we're on the same page here.)

I don't understand what the condition is in the Makefile that has to be false for the EMCC_COMMON_LFLAGS += -s \"BINARYEN_TRAP_MODE=\'clamp\'\" line to be added in its else clause. What kind of object files is it looking for?

Yes, I am well aware of emscripten/wasm issues.

To use wasm object files, you need to have a Qt built using -device-option=WASM_OBJECT_FILES=1, which will use emscripten upstream to bypass creating the intermediate javascript file when transpiling to wasm. This speeds up linking time.

The Qt released binaries were not built using the new upstream backend.

Apparently we need another check to detect when using the upstream emscripten and not apply the clamp mode.

You can either:

install and use emscripten 1.38.27 without the benefit of wasm object files, and will work correctly with Qt webassembly binaries.

edit the wasm-emscripten/qmake.conf file and simply remove the clamp mode line, and hope things work correctly due to mis-matched emscripten versions

Is there something I need to add in place of the clamp mode line? Because I do get a whole bunch of errors and exceptions from Python when I run nmake after removing the clamp mode line from the Makefile. Is it okay to assume that it'll work fine if I change the .conf file instead of the Makefile?

I took out that line completely, added the patch, and then ran qmake and nmake again but have the same error as before. A whole bunch of red lines with "unknown warning option" and other stuff in it. And I don't know why the -Werror option is being passed to the compiler backend.

I also have to forcibly close the window using the red button because just giving it the keyboard interrupt isn't enough.

The reason for the unknown warning error was a mismatch between the Clang version and the Emscripten version. But after fixing that I have an error from wasm-ld.exe saying that the machine type of library files needs to be wasm32. I don't know what I need to do here so some help would be good. I mentioned this in the Emscripten GitHub as well.

There are errors from wasm-ld.exe saying that there are object files that don't have the machine-type wasm32. The object files generated by running nmake definitely hve wasm code in them, even though wasm-ld is flagging them as well. Which is really weird. I see that the object files that come from the Qt library itself are also getting flagged though. Could you guys verify using wasm-dis if those are also wasm object files? Although there's still a problem there because wasm object files shouldn't even have a machine type--only bitcode files should which these aren't. This is really confusing.

@lorn-potter Do I need to do a complete downgrade? I have version 1.39.0 right now. Could that be what's causing the problem with the wasm-ld error saying that my object files aren't of machine-type wasm32?

@lorn-potter Do I need to do a complete downgrade? I have version 1.39.0 right now. Could that be what's causing the problem with the wasm-ld error saying that my object files aren't of machine-type wasm32?

Yes, because 1.39.0 switched to wasm object files by default, where as the older version used fastcomp to build.

You can install a different version alongside 1.39.0:
./emsdk install sdk-1.38.27-64bit

and then to switch to the newly installed version:
./emsdk activate --embedded sdk-1.38.27-64bit

When you want ot use a different version just use the activate line with the correct installed version.

@lorn-potter What's the use of the patch if Qt 5 still can't handle the Wasm backend? The reason for the machine type error from wasm-ld is something else: in later versions of Emscripten, it doesn't generate bitcode for Wasm object files. But for some weird reason wasm-ld still gives an error saying that the machine type of the object files isn't wasm32. That's very strange. Please read my conversation with this LLVM developer on this Emscripten GitHub issue I've opened. It would be good if these problems are fixed so that the Wasm backend on the latest version of Emscripten works well with Qt 5.

And right now I can't install the 1.38.27 SDK itself directly using the Emsdk; I have to install Emscripten, Clang and Binaryen separately through Emsdk and since I want to use my own Node, Python and Java anyway, I don't also get those. I had to use CMake to build and install Binaryen on my own though because what Emsdk did failed for me. When I try to install the SDK through Emsdk directly, I get a System Error Access denied when it unzips the Python zip file and gets to trying to add DLLs to the Emsdk Python installation directory.

Edit: I deleted the old files and tried to configure and build again, but now I have this error: shared:ERROR: fastcomp is not compatible with wasm object files:main.obj. I have Emscripten 1.38.27 now with the asm.js backend, so what's going on now? Why is it generating a Wasm object file? Do I still need to add something to the .conf file so that it won't generate Wasm object files when the asm.js backend is being used?

Edit: Actually, I should be able to make it work if I build Qt for WebAssembly myself. I just need to know what modules are usually built for Qt 5 for Windows. I'll build those same modules. Except if threading support isn't included in there, then I want to include that as well in addition to the rest of it. What module do I need for threading support?

I want to try to building Qt for WebAssebly again since I think if I had Qt built using the latest version of Emscripten, it may not do what it's not supposed to when using that version of Emscripten. So I want to know how to have it use LLVM 10 installed through the EMSDK and have it generate LLVM bitcode targeting the wasm32 machine type (for that I probably need to know how to pass (multiple) command line arguments to the Clang compiler itself when building Qt). Also, if I want to have it use C++17 rules when building Qt, what should I do? I tried passing the -c++std c++17 argument to configure.bat but it didn't work. Internally it was still using C++11.

Okay, but how can I pass the option to emit LLVM bitcode with machine-type wasm32? Will passing -device-option WASM_OBJECT_FILES=1 to Qt configure like you said be enough? I do want to know where to pass the --emit-llvm and --target=wasm32 flags to Clang.

Also, I heard on the Emscripten GitHub that .obj files with wasm in them aren't standard wasm files. And that Emscripten version 1.38.38 and above isn't supposed to generate it in the first place, especially with the new Wasm backend. The error I was before where wasm-ld.exe was saying that the .obj files don't have machine-type wasm32 was strange for that reason. Also because those object files all had Wasm code in them. wasm-ld.exe was also saying it about object files from the Qt library itself, though, and I don't know where to find them to check if they have Wasm code in them or not. They most likely have it as well though.

I've posted a link to the Emscripten GitHub issue I opened about this on here before. Have you looked at that? If not, then please do.

Also I've added this line to qmake.conf along with the recommended patch: QMAKE_CXXFLAGS_RELEASE += -Xclang --emit-llvm -Xclang --target=wasm32, but is that okay? Or did I make a mistake here? Also, if I add this patch to the Qt I build from source, and then I want to execute git pull, would it be okay to push my changes to the repository? Note: I'll keep the prebuilt binaries too and I try with both. Maybe I can still get this to work.

Edit: One more question: do I need the Qt Web module when targeting Wasm? The one that's takes too long and the documentation says to consider not building it.

If I pass -device-option WASM_OBJECT_FILES=1 to Qt configure when building Qt, will that fix this?

I checked notepad.obj and notepad.js_plugin_import.obj with wasm-dis.exe before and found that they were Wasm object files. But now when I check again, main.obj does have Wasm code in it but this is what I get for notepad.obj:

I get the exact same result with emrun. The error "TypeError: Body has already been read". How do I fix this? Someone please help. This seems like a JavaScript error so maybe I should also consult the Emscripten developers. But it's also something related to Qt and there may be something I need to know about how to run a Wasm module compiled from Qt code.

I used it in Chrome. The functionality of saving a file doesn't seem to work (may need to let WebAssembly use the filesystem) and the "Select Font" feature is giving me trouble. It opens up two dialogue boxes so I have cancel the second one. On the first one then, the font size selector goes crazy when I try to use it; it keeps going between different sets of two options in really fast succession and I can't choose one at all. Is there a special way to get the Notepad example to work as a Wasm app? These problems only appear in the Wasm app.

If I pass -device-option WASM_OBJECT_FILES=1 to Qt configure when building Qt, will that fix this?

I checked notepad.obj and notepad.js_plugin_import.obj with wasm-dis.exe before and found that they were Wasm object files. But now when I check again, main.obj does have Wasm code in it but this is what I get for notepad.obj: