libreoffice-online/wasm/Makefile.am

91 lines
2.7 KiB
Text
Raw Normal View History

EXEEXT = .js
AM_CXXFLAGS = \
-pthread -s USE_PTHREADS=1 \
-s DISABLE_EXCEPTION_CATCHING=0
AM_CPPFLAGS = \
-I$(top_srcdir) \
-I$(top_srcdir)/common \
-I$(top_srcdir)/kit \
-I$(top_srcdir)/net \
-I$(top_srcdir)/wsd \
-I@LOBUILDDIR@/workdir/UnpackedTarball/libpng \
-I@LOBUILDDIR@/workdir/UnpackedTarball/zlib \
-DCOOLWSD_CONFIGDIR='"@COOLWSD_CONFIGDIR@"' \
-DDEBUG_ABSSRCDIR='"@abs_srcdir@"' \
-DMOBILEAPP=1
bin_PROGRAMS = online
online_SOURCES = \
wasmapp.cpp \
../common/Authorization.cpp \
../common/ConfigUtil.cpp \
../common/Crypto-stub.cpp \
../common/FileUtil.cpp \
../common/CommandControl.cpp \
../common/Log.cpp \
../common/TraceEvent.cpp \
../common/Protocol.cpp \
../common/StringVector.cpp \
../common/Session.cpp \
../common/SigUtil.cpp \
../common/Simd.cpp \
../common/SpookyV2.cpp \
../common/Unit.cpp \
../common/Util.cpp \
../common/Util-mobile.cpp \
../kit/ChildSession.cpp \
../kit/Kit.cpp \
../kit/KitQueue.cpp \
../kit/KitWebSocket.cpp \
../kit/DeltaSimd.c \
../net/FakeSocket.cpp \
../net/Socket.cpp \
../wsd/ClientSession.cpp \
../wsd/DocumentBroker.cpp \
../wsd/COOLWSD.cpp \
../wsd/ClientRequestDispatcher.cpp \
../wsd/RequestDetails.cpp \
../wsd/Storage.cpp \
../wsd/TileCache.cpp \
../wsd/coolwsd-fork.cpp
online_DEPENDENCIES = \
@LOBUILDDIR@/instdir/program/soffice.html.linkdeps \
soffice.data \
soffice.data.js.metadata
# note cannot add content of .linkdeps to DEPENDENCIES because it contains -lFoo
online_LDADD = \
${POCOLIB}/libPocoEncodings@POCODEBUG@.a \
${POCOLIB}/libPocoNet@POCODEBUG@.a \
${POCOLIB}/libPocoUtil@POCODEBUG@.a \
${POCOLIB}/libPocoXML@POCODEBUG@.a \
${POCOLIB}/libPocoJSON@POCODEBUG@.a \
${POCOLIB}/libPocoFoundation@POCODEBUG@.a \
${ZSTDLIB}/libzstd.a \
-L@LOBUILDDIR@/instdir/program \
$(shell cat @LOBUILDDIR@/instdir/program/soffice.html.linkdeps)
# TODO these are just copypasta from core
online_LDFLAGS = \
-pthread -s MODULARIZE -s EXPORT_NAME=createOnlineModule -s USE_PTHREADS=1 -s TOTAL_MEMORY=1GB -s PTHREAD_POOL_SIZE=15 --bind -s FORCE_FILESYSTEM=1 -s WASM_BIGINT=1 -s ERROR_ON_UNDEFINED_SYMBOLS=1 -s FETCH=1 -s ASSERTIONS=1 -s EXIT_RUNTIME=0 -s EXPORTED_RUNTIME_METHODS=["UTF16ToString","stringToUTF16","UTF8ToString","allocateUTF8","ccall","cwrap","FS"] -pthread -s USE_PTHREADS=1 -s DISABLE_EXCEPTION_CATCHING=0 -s EXPORTED_FUNCTIONS=["_main","_libreofficekit_hook","_libreofficekit_hook_2","_lok_preinit","_lok_preinit_2","_handle_cool_message"] \
--pre-js @LOBUILDDIR@/workdir/CustomTarget/static/emscripten_fs_image/soffice.data.js.link
if ENABLE_DEBUG
online_LDFLAGS += \
-gseparate-dwarf
endif
Make the temporary "WASM app" work Now I hope things are initialised in the right order and the plumbing gets set up so that messages are passed as expected. It seems to work most of the time. Main changes are: - The online WASM executable is built using the -s MODULARIZE -s EXPORT_NAME=createOnlineModule options. This means that the WASM runtime is not automatically initialized and the main() function is not automatically started. Only when the createOnlineModule() function is called is that done. Calling exported C/C++ functions is a little bit more complicated. - Code to actually Base64-encode strings to be executed as JavaScript when expected is now present in wasmapp.cpp. (After being passed through the Base64ToArrayBuffer function on the JS side.) Whether this is actually necessary is not fully clear, but to keep the code similar to that in the GTK, iOS, and Android apps, this is kept as such for now. It would probably work fine to just directly create the ArrayBuffer in the C++ (using the EM_ASM magic). - The COOLWSD::run() function is now run in a separate thread so that main() can return. - The FakeWebSocket's onopen() function is now called from innerMain(), where the HULLO message is sent. It remains a bit unclear if this really is the ideal place. In the mobile apps the HULLO message is sent and the onopen() function is called in the window.socket.onopen() function in global.js. But note that despite that the WASM app and the mobile apps are largely quite similarly constructed and the FakeSocket and FakeWebSocket plumbing is the same, there is an important difference. In a mobile app the C++ code is what runs first, and that then loads the HTML page into WebKit, in which the JS runs. In the WASM app it is the other way around. The web page is naturaly the one that is loaded and the JS code then starts running the C++ code as WASM. Finally, note that the whole concept that there is a separate "WASM app" is temporary. What we eventually want to achieve is that the COOL webpage upon loading will connect a COOL server. As it does currently. The COOL server runs the online and core C++ code to load a document, and renders document tiles and sends those to the client JS code to dispay. The new thing will be that, if enabled, in addition to the HTML and JS resources, the client will also download the WASM code and data resources. Also, the document and updates to it will be downloaded while being edited so that a copy can be kept in client memory. But the WASM code and the downloaded document will remain unused most of the time. Only if the connection to the COOL server breaks will the JS start running the WASM code and the JS will talk to online code running locally as WASM instead of to a COOL server. Obviously there are still lots of things hanging in the air here regarding how exactly this will work. Signed-off-by: Tor Lillqvist <tml@collabora.com> Change-Id: Ib1786a0b485d51797b0f2302d4296aa1ff9df5c1
2023-01-05 12:11:01 -06:00
if ENABLE_WASM_ADDITIONAL_FILES
online_LDFLAGS += \
--preload-file $(WASM_ADDITIONAL_FILES)@
endif
soffice.dat%: @LOBUILDDIR@/instdir/program/soffice.dat%
cp $< $@