User:Hossein/Build/wasm

This manual is for building LibreOffice Emscripten cross build. If this does match your platform, please refer to the development page on Wiki to find the correct build instructions.

LibreOffice Versions
This manual is written for the LibreOffice Dev 7.4, which is the latest git master.

Status
The build generates a Writer-only LO build. You should be able to run either

$ emrun --serve_after_close instdir/program/qt_soffice.html $ emrun --serve_after_close workdir/LinkTarget/Executable/qt_vcldemo.html $ emrun --serve_after_close workdir/LinkTarget/Executable/qt_wasm-qt5-mandelbrot.html REMINDER: Always start new tabs in the browser, reload might fail / cache! INFO: latest browser won’t work anymore with 0.0.0.0 and need 127.0.0.1.

Setup for the LO WASM build (with Qt)
We’re using Qt 5.15.2 with Emscripten 2.0.31. There are a bunch of Qt patches to fix the most grave bugs. Also newer Emscripten versions have various bugs with the FS image support.


 * See below under Docker build for another build option

Setup emscripten
https://emscripten.org/docs/getting_started/index.html

git clone https://github.com/emscripten-core/emsdk.git ./emsdk install 2.0.31 ./emsdk activate --embedded 2.0.31 Example  scriptlet:

EMSDK_ENV=$HOME/Development/libreoffice/git_emsdk/emsdk_env.sh [ -f &quot;$EMSDK_ENV&quot; ] &amp;&amp; \. &quot;$EMSDK_ENV&quot; 1&gt;/dev/null 2&gt;&amp;1

Setup Qt
https://doc.qt.io/qt-5/wasm.html

Most of the information from https://doc.qt.io/qt-6/wasm.html is still valid for Qt5; generally the Qt6 WASM documentation is much better, because it incorporated many information from the Qt Wiki.

FWIW: Qt 5.15 LTS is not maintained publicly and Qt WASM has quite a few bugs. Most WASM fixes from Qt 6 are needed for Qt 5.15 too. They can mainly be cherry-picked from: - git log origin/dev src/plugins/platforms/wasm/ - git log –grep wasm origin/dev

We will probably offer our own Qt repository clone at some point.

But even the public Qt 5.15 branch is still broken, so better start with the v5.15.2 tag.

git clone https://github.com/qt/qt5.git cd qt5 git checkout v5.15.2 ./init-repository --module-subset=qtbase ./configure -xplatform wasm-emscripten -feature-thread -prefix $PWD/install-5.15.2 make -j&lt;CORES&gt; module-qtbase Optionally you can add the configure flag “-compile-examples”. But then you also have to patch at least mkspecs/wasm-emscripten/qmake.conf with EXIT_RUNTIME=0, otherwise they will fail to run. In addition, building with examples will break with some of them, but at that point Qt already works and also most examples. Building with examples will break with some of them, but at that point Qt already works. Or just skip them. Other interesting flags might be “-nomake tests -no-pch -ccache”.

Linking takes quite a long time, because emscripten-finalize rewrites the whole WASM files with some options. This way the LO WASM needs at least 64GB RAM. For faster link times add “-s WASM_BIGINT=1”, change to ASSERTIONS=1 nd use -g3 to prevent rewriting the WASM file and generating source maps (see emscripten.py, finalize_wasm, and avoid modify_wasm = True). This is just needed for Qt examples, as LO already uses the correct flags!

The install is not really needed, as LO currently just uses qtbase on its own. You can do

make -j&lt;CORES&gt; install or make -j8 -C qtbase/src install_subtargets

Current Qt fails to start the demo webserver: https://bugreports.qt.io/browse/QTCREATORBUG-24072

Use  to run Qt WASM demos.

Setup LO
is patched to use emconfigure. That basically sets various environment vars, especially, which will create the correct output file names, checked by.

There’s a distro config for WASM, but it just provides –host=wasm32-local-emscripten, which should be enough setup. The build itself is a cross build and the cross-toolset just depends on a minimal toolset (gcc, libc-dev, flex, bison); all else is build from source, because the final result is not depending on the build system at all.

Recommended configure setup is thusly:


 * grab defaults
 * local config
 * if you want to use ccache on both sides of the build

FWIW: it’s also possible to build an almost static Linux LibreOffice by just using –disable-dynloading –enable-customtarget-components. System externals are still linked dynamically, but everything else is static.

“Deploying” soffice.wasm
tar -chf wasm.tar --xform 's/.*program/lo-wasm/' instdir/program/soffice.* \ instdir/program/qt* Your HTTP server needs to provide additional headers: * add_header Cross-Origin-Opener-Policy same-origin * add_header Cross-Origin-Embedder-Policy require-corp

The default html to use should be qt_soffice.html

Debugging setup
Since a few months you can use DWARF information embedded by LLVM into the WASM to debug WASM in Chrome. You need to enable an experimental feature and install an additional extension. The whole setup is described in:

https://developer.chrome.com/blog/wasm-debugging-2020/

This way you don’t need source maps (much faster linking!) and can resolve local WASM variables to C++ names!

Per default, the WASM debug build splits the DWARF information into an additional WASM file, postfixed ‘.debug.wasm’.

Using Docker to cross-build with emscripten
If you prefer a controlled environment (sadly emsdk install/activate is not stable over time, as e.g. nodejs versions evolve), that is easy to replicate across different machines - consider the docker images we’re providing.

Config/setup file see https://git.libreoffice.org/lode/+/ccb36979563635b51215477455953252c99ec013

Run

docker-compose build in the lode/docker dir to get the container prepared. Run

PARALLELISM=4 BUILD_OPTIONS= BUILD_TARGET=build docker-compose run --rm \ -e PARALLELISM -e BUILD_TARGET -e BUILD_OPTIONS builder to perform an actual  build; the container mounts checked-out git repo and output dir via   (so make sure the path names there match your setup):

The lode setup expects, inside the lode/docker subdir, the following directories:


 * core
 * workdir (the output dir - gets written into)
 * cache
 * tarballs (external project tarballs gets written and cached there)

Tools for problem diagnosis

 * should list the symbols in the archive, based on the index generated by ranlib. If you get linking errors that archive has no index.