Commit graph

55 commits

Author SHA1 Message Date
Ashod Nakashian
8d49d33da4 wasm: truncate string only if will log
Change-Id: I7bcc420633563abb858354a7cdb6c4a74c79b548
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2023-12-09 19:22:24 +00:00
Ashod Nakashian
87fdb4a185 wasm: header include cleanup
Change-Id: Ia6396d9e10b9597602a88fced932c27c329b394b
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2023-12-09 19:22:24 +00:00
Ashod Nakashian
a96f8a0f92 configure: WASMAPP is now defined for WASM targets
This is in line with MOBILEAPP and GTKAPP and
is independent of __EMSCRIPTEN__.

Replace all application-specific cases, leaving
only toolchain-specific ones (such as include
protection).

Change-Id: Ic44288aa5ace51e0a8b54566170c19120f7bf0dd
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2023-12-09 19:22:24 +00:00
Caolán McNamara
cf33d0bdd0 update wasm.README for distro-config
the default suggestion uses --enable-qt5 which isn't needed for
LOKit and breaks finding custom notebookbar widgets so online
notebookbar doesn't work with it.

Signed-off-by: Caolán McNamara <caolan.mcnamara@collabora.com>
Change-Id: I644924a0f8cdb01d4ec20d70ff7aedb27a2c899f
2023-12-08 14:08:30 +00:00
Caolán McNamara
9daba64dc1 use of gseparate-dwarf can block some optimizations
with in in place the sizes are

-Os for core and online
  du -h online.wasm 155M

-Oz for core and online
  du -h online.wasm 145M

and a warning of:

em++: warning: running limited binaryen optimizations because DWARF info requested (or indirectly required) [-Wlimited-postlink-optimizations]

without gseparate-dwarf the sizes are:

-Os for core and online without -gseparate-dwarf
  du -h online.wasm 133M

-Oz for core and online without -gseparate-dwarf
  du -h online.wasm 119M

Signed-off-by: Caolán McNamara <caolan.mcnamara@collabora.com>
Change-Id: I91586abe0e52f6de20d0f04636bb5a2be93d92be
Signed-off-by: Caolán McNamara <caolan.mcnamara@collabora.com>
2023-12-06 12:39:46 +01:00
Caolán McNamara
5232e3d735 hack to get this up and working
Signed-off-by: Caolán McNamara <caolan.mcnamara@collabora.com>
Change-Id: I6d3d273f59f58a0c3b2027039dcc7de95ad971b9
2023-11-27 10:48:44 +00:00
Ashod Nakashian
0631593c96 wasm: proxy wopi documents
Change-Id: I3104ac9a6fd180f11aef06b9d4f516a392e021a9
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2023-11-27 10:48:44 +00:00
Ashod Nakashian
c2c0fe6f51 wasm: accept url as command-line argument
Change-Id: I005cd45ed0c6bfbf20bf74c84c670d2f9a0b289e
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2023-11-27 10:48:44 +00:00
Ashod Nakashian
3a0a4c1225 wasm: readme update
Change-Id: Ie3f1fb3800597f719f2764ec1ee2cad0ba48e62f
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2023-11-27 10:48:44 +00:00
Michael Meeks
b45f4b8f93 spdx: improve machine and human readability of headers.
Change-Id: I71f1421debf31b8c6cd0fd75c0cb45e2563b8a5a
Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
2023-11-20 14:30:02 +00:00
Michael Meeks
4423770c52 cowasm: disable werror for now for dlopen detection:
otherwise generated:

| int
| main ()
| {
| return dlopen ();

wasm-ld: warning: function signature mismatch: dlopen
>>> defined as () -> i32 in /tmp/emscripten_temp_6nz4f0ww/conftest_0.o
>>> defined as (i32, i32) -> i32 in /home/builder/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/libc.a(dynlink.o)
em++: error: running limited binaryen optimizations because DWARF info requested (or indirectly required) [-Wlimited-postlink-optimizations] [-Werror]

and erroneously claims that dlopen is not present, and
configure fails.

Change-Id: Ie54db7c2099787a0b63b76b0b6e3e44750c9046e
Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
2023-10-29 11:05:18 -04:00
Michael Meeks
08f60bc72b cowasm: parameterize masses of paths included in command-lines.
Change-Id: I2a73e876290c10ee34385f807364ca4dd5b52063
Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
2023-10-27 20:49:26 -04:00
Ashod Nakashian
d9d13d7092 wasm: support serving wasm files
Updates README with instructions.

Change-Id: I5188d3ca267ff88a956dc17f302a70bda1046266
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2023-10-24 21:33:02 -04:00
Ashod Nakashian
9ad6a69086 wasm: improved build instructions in readme
Change-Id: I420891a555ef4b51304cff26fdcab2ba0bc5fbdd
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2023-10-24 09:20:32 +02:00
Balázs Varga (allotropia)
99c14f99e1 WASM: fix wasm build errors
Signed-off-by: Balázs Varga (allotropia) <balazs.varga.extern@allotropia.de>
Change-Id: I104e98ae1ddc64af55e4df0ccb301d5e88e0288d
2023-10-03 10:18:46 +02:00
Tor Lillqvist
0b74d4ead1 Drop POCO_HAVE_FD_EPOLL for Emscripten
Not sure why I now suddenly needed this, too, when I recompiled Poco
for WASM (with different options than before).

Signed-off-by: Tor Lillqvist <tml@collabora.com>
Change-Id: I7221947e0cd2264535b6d34e0640b95d7cfc7cf4
2023-02-22 09:00:39 +01:00
Tor Lillqvist
6d26fe07a2 Provide separate documentation for building COWASM without the container
Signed-off-by: Tor Lillqvist <tml@collabora.com>
Change-Id: I8c1697732a9102197d4c273c23e60378420e598a
2023-02-13 13:57:43 +01:00
Tor Lillqvist
78a1b062b2 Bin superfluous logging of what we are about to send to the JS bits
We are logging what we are evaluating as JavaScript later in the
function anyway.

Signed-off-by: Tor Lillqvist <tml@collabora.com>
Change-Id: I79972ec585dee128bbcca910def1d46e8134cdc5
2023-02-10 18:37:16 +01:00
Tor Lillqvist
a07f81388c I don't see the reason to use the intermediate libonline.a for WASM
Signed-off-by: Tor Lillqvist <tml@collabora.com>
Change-Id: I520aa232f6ac51a6a57f36d8ac775150aa095a4d
2023-01-30 10:02:06 +02:00
Tor Lillqvist
b360c21c7f Avoid warning: deprecated item in EXPORTED_RUNTIME_METHODS: printErr use err instead.
We don't seem to need it anyway, so drop.

Signed-off-by: Tor Lillqvist <tml@collabora.com>
Change-Id: Idcccb3e46de692f179f0c01b5179eb43b816dcd5
2023-01-30 08:10:17 +02:00
Tor Lillqvist
c944348ad7 Adapt to newer Emscripten SDK
Newer Emscripten SDKs no longer provide <sys/epoll.h> and
<sys/inotify.h>. The corresponding functionality is not present, I
assume.

Until now we have been using Emscripten SDK 2.0.31 and that is still
the recommended known-to-work version, but I am experimenting with the
latest, 3.1.30.

Signed-off-by: Tor Lillqvist <tml@collabora.com>
Change-Id: I26e89dc38554548aee3ce2dbf6ba352917ba6266
2023-01-30 08:10:17 +02:00
Tor Lillqvist
4417ec556b The poco-no-special-expat-sauce.diff wants -p0 to apply
Signed-off-by: Tor Lillqvist <tml@collabora.com>
Change-Id: Ib0b7227996a7fc9b79ad976cc73b7f8dbbd6ce34
2023-01-30 08:10:17 +02:00
Tor Lillqvist
78b0e82f98 There is no need to call lok_cpp_init() here
LOKit will be initialised in the lok_init_2() call in lokit_main() in
Kit.cpp. This change also puts setting and getting the LOK_OPTIONS
environment variable in the right order.

Signed-off-by: Tor Lillqvist <tml@collabora.com>
Change-Id: Iee6f5adcb60bb887083c67666c2d597a15686bf9
Signed-off-by: Tor Lillqvist <tml@collabora.com>
2023-01-29 22:05:20 +02:00
Tor Lillqvist
457c17d7f1 Use COOL log level 'error' instead of 'trace'
Signed-off-by: Tor Lillqvist <tml@collabora.com>
Change-Id: I50285b974403e95f48106950a81a1ea9bbd95b86
2023-01-29 21:23:44 +02:00
Tor Lillqvist
cee9bf493a Change hardcoded sample document name and verify that we get it
You now must pass --with-wasm-additional-files=<path> where path
contains a file called sample.docx.

Signed-off-by: Tor Lillqvist <tml@collabora.com>
Change-Id: I21e62feb6282833a5d60b31db26328eda63cdaea
2023-01-29 06:56:08 +02:00
Tor Lillqvist
38171388c8 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-28 22:04:39 +02:00
Tor Lillqvist
fe7daff506 Drop the temporary experimenting with loading a document through the LOKit API
After my shortly upcoming commits the document gets loaded and its
tiles displayed by the code that normally does that. No need to
separately verify that loading a document works.

Signed-off-by: Tor Lillqvist <tml@collabora.com>
Change-Id: Id5883f36644b5e9b79c3f80ea2131e9f35823b2f
2023-01-28 20:57:03 +02:00
Tor Lillqvist
1e55de0924 Use -gseparate-dwarf like in core
Signed-off-by: Tor Lillqvist <tml@collabora.com>
Change-Id: Ie7814a0f0f02a577f641a7d223fbb0c81ab3b2ab
2023-01-27 10:06:12 +02:00
Tor Lillqvist
48c96e70ca More WASM hacking
Apparently handle_cool_message() gets called from a web worker thread
and then using emscripten_run_script() in wasmapp.cpp to run a JS
snippet that refers to the 'window' variable will not work. That
variable exists only in the main thread. So use MAIN_THREAD_EM_ASM()
instead.

Hardcode the document URL for now also in wasmapp.cpp.

Try to send the HULLO message from COOLWSD::innerMain().

Signed-off-by: Tor Lillqvist <tml@collabora.com>
Change-Id: Ic48042c6d0c6239a3b82e74f0565056a15f3d98d
2023-01-26 22:01:14 +02:00
Tor Lillqvist
b1bb133e52 Bump PTHREAD_POOL_SIZE to 15
Signed-off-by: Tor Lillqvist <tml@collabora.com>
Change-Id: I9c6c7075fff9d67c921d0c525eb8c0fe474b847c
2023-01-26 09:12:06 +02:00
Tor Lillqvist
2c5522aebe Add some debugging output
Signed-off-by: Tor Lillqvist <tml@collabora.com>
Change-Id: I2db4a002dfafd5db15362a3ab8d8df33b1153138
2023-01-16 18:43:21 +02:00
Tor Lillqvist
d9024e8955 Add patch that prevents expat in Poco from causing trouble with WASM
As we build a single statically linked bunary for WASM, we will end up
with just one copy of each function in it. Both LO core and Poco
include expat. Upstream Poco builds one of the expat source files as
C++. That causes trouble as it then isn't compatible with what LO core
wants to call. Or something like that. You get "RuntimeError: null
function or function signature mismatch". (The "signature" concept in
WASM is orthogonal to C++ name mangling.)

Signed-off-by: Tor Lillqvist <tml@collabora.com>
Change-Id: Iacf75ed34eea98611cb6aa6867e460697ea1fc4a
2023-01-16 18:43:21 +02:00
Tor Lillqvist
f8819137c5 Experiment with explicitly loading a document through LOKit
This revealed some interestring problems related to expat, static
linking, and how expat was built in Poco.

Don't bother saving the document, though.

Signed-off-by: Tor Lillqvist <tml@collabora.com>
Change-Id: I6715beb46ad6c4854ffc8aff6a26419c05727ae7
2023-01-16 18:43:21 +02:00
Tor Lillqvist
bc5f8d16e9 Add _handle_cool_message to EXPORTED_FUNCTIONS
Signed-off-by: Tor Lillqvist <tml@collabora.com>
Change-Id: I93d987284e2b14a08c4dd1613101572a72e85136
2023-01-15 19:46:37 +01:00
Tor Lillqvist
3441dc27d8 Just run the COOLWSD run() method directly in main()
No need to start a separate thread to run it, like in the gtk+
"mobile" app, I think.

Also no need for a cleanup function, I think.

Signed-off-by: Tor Lillqvist <tml@collabora.com>
Change-Id: I23e94200047a195b7fecbdf370142daebc3df55c
2023-01-15 19:46:37 +01:00
Tor Lillqvist
6b05db3c89 Don't expect any command-line arguments at least for now
We want the code to go further and not stop right away.

Signed-off-by: Tor Lillqvist <tml@collabora.com>
Change-Id: Id285f119dde0894cda59b68ebd02a9f6b0e2fbee
2023-01-15 19:46:37 +01:00
Tor Lillqvist
fc0b538a19 Increase PTHREAD_POOL_SIZE
Just 4 is very likely not nearly enough. I think I did see some error
that could be related to running out of threads. Does
PTHREAD_POOL_SIZE limit how many threads can exist simultaneously?

Signed-off-by: Tor Lillqvist <tml@collabora.com>
Change-Id: I5da637b5660e89655f7049b6754f70c74dff6da2
2023-01-15 19:46:37 +01:00
Balázs Varga (allotropia)
158fe2f93a Trying to init LOKit cause mysterious runtime error
Also using soffice.data name instead online.data: online.js
looking for soffice.data

Signed-off-by: Balázs Varga (allotropia) <balazs.varga.extern@allotropia.de>
Change-Id: I62cee3f4866a2824a08b472f15bcdec06a6407b9
2023-01-15 19:46:37 +01:00
Michael Stahl
db532e12d0 WASM rename executable and copy missing data files from core
* add dependency on soffice.html.linkdeps to rebuild if core was rebuilt
* copy needed data files as-is from core build
* rename executable by setting automake EXEEXT var - appears to work

Signed-off-by: Michael Stahl <michael.stahl@allotropia.de>
Change-Id: I458b49290dae9d621a8043b1b3103d8b8fd606b8
2023-01-15 19:46:37 +01:00
Tor Lillqvist
8891cc1091 Remove TODO, we added a --pre-js a few commits ago
Signed-off-by: Tor Lillqvist <tml@collabora.com>
Change-Id: Id372422578c9d6f49e453ede6a70cdc9db01c8b1
2023-01-11 09:27:36 +02:00
Tor Lillqvist
d575447e5b Need DEBUG_ABSSRCDIR here, too, for build with --enable-debug
Signed-off-by: Tor Lillqvist <tml@collabora.com>
Change-Id: I02ee35797216135de79484e5929a4f72a1bb20b2
2023-01-11 09:27:36 +02:00
Tor Lillqvist
b004971e11 For now, link the WASM thing with the emscripten_fs_image from LO
The LO build directory in question needs to be one separately
configured for this (not one that would use Qt5 for UI, for instance),
so in the long run perhaps it does not make sense to create the FS
image there in core, but we should do it here in online? And we will
surely need additional files in the fs image anyway that core knows
nothing about.

Signed-off-by: Tor Lillqvist <tml@collabora.com>
Change-Id: I2cff0421da6075eefc017603ddf9d2ecf9dc79e2
2023-01-11 09:27:36 +02:00
Tor Lillqvist
933a8088c4 Clarify how handle_cool_message() in the WASM app would be used
It is called from JavaScript with one parameter, the string containing
the message to be sent to the Online C++ code. (See
browser/html/cool.html.m4.) It is not called from the mobile app glue
code.

Signed-off-by: Tor Lillqvist <tml@collabora.com>
Change-Id: I893dfff3b7d2dbfe4bd48393e58a8c6bfc6e2931
2023-01-11 09:27:36 +02:00
Balázs Varga (allotropia)
c6bdf11bb9 Add read and write functions from local files to emscripten filesystem
Signed-off-by: Balázs Varga (allotropia) <balazs.varga.extern@allotropia.de>
Change-Id: I7ea6d19573db4771d170692fab6a221e174f17ca
2023-01-11 09:27:36 +02:00
Balázs Varga (allotropia)
a5740dcde7 Using handle_cool_message and send2JS in wasmapp.cpp
Include emsripten headers and init some variables for later.

Signed-off-by: Balázs Varga (allotropia) <balazs.varga.extern@allotropia.de>
Change-Id: Ic2c8228d44a60b25ae495a2e9d75c10160161f11
2023-01-11 09:27:36 +02:00
Balázs Varga (allotropia)
5e2d9bb36a WASM init fakesocket on a new thread and adding some necessary headers for later
Also feature/wasm rebased with online master.

Signed-off-by: Balázs Varga (allotropia) <balazs.varga.extern@allotropia.de>
Change-Id: I1ecba4091c22878aacc3d6033ad350b0aa2276dc
2023-01-11 09:27:36 +02:00
Michael Stahl
a4b31d4966 WASM add a note about memory required for linking
Signed-off-by: Michael Stahl <michael.stahl@allotropia.de>
Change-Id: Ic7f2cffdeb4408a9f726ad70a8ceb8db372787d9
2023-01-10 22:02:22 +02:00
Tor Lillqvist
9f8c4f6741 No need to export _doc_postUnoCommand from the wasm here
That is needed by core:feature/wasm for the way it implements
conversion to PDF. Not relevant here.

Signed-off-by: Tor Lillqvist <tml@collabora.com>
2023-01-10 22:02:22 +02:00
Michael Stahl
ad6ea1a1db WASM improve README
Remove the dumb hard-coded home dir and add a section how to use the
pre-built dependencies from the container.

Signed-off-by: Michael Stahl <michael.stahl@allotropia.de>
Change-Id: Ibdc8d766be54dcde440682d2c77fb47f042f6056
2023-01-10 22:02:22 +02:00
Michael Stahl
244ca9a123 WASM add dummy main function, executable links successfully
Signed-off-by: Michael Stahl <michael.stahl@allotropia.de>
Change-Id: I698750236de88e76a493c075479a447add73dd7f
2023-01-10 22:02:22 +02:00