Description
TLDR: As Kiwix Offline Wikipedia reader supports legacy browsers, we need to find a way to compile a complex library to ASM without Atomics / pthreads. The problem seems to arise in the zlib library, but --disable-pthreads
is not supported by the zlib configure
command. We also use WORKERFS. Is there a way to prevent Emscripten compiling with Atomics?
DETAILS: The Kiwix offline Wikipedia browser needs to support a wide range of legacy browsers in its JavaScript version. Until recently, we used specific Emscripten ports of XZ and ZStandard to provide decompression of strings from very large (up to 93GB) archives, and this works well even in Internet Explorer. We recently managed to compile our entire libzim application to WASM (and ASM) with Emscripten, which provides significant advantages over the earlier ports, e.g. use of Xapian full-text search. However, it only works in the latest browsers.
The issue is that the Emscripten port of libzim uses Atomics. Unfortunately, a number of our target browsers don't support the JS Atomics object. We understand that we need to compile without pthread support in order to disable Atomics, but it's proving difficult to do so. We believe we've narrowed the problem down to the linked zlib library, used by a number of the libraries in the project, though the issue may also be that we are forced to use the WORKERFS file system because it is the only one that supports passing a reference to 93GB File objects. Unlike with the ZStandard port, the libzim application needs to work on files rather than on strings or file slices.
This is how we compile zlib in our makefile:
wget -N https://zlib.net/zlib-1.2.13.tar.gz
tar xf zlib-1.2.13.tar.gz
cd zlib-1.2.13 ; emconfigure ./configure --prefix=`pwd`/../build
cd zlib-1.2.13 ; emmake make
cd zlib-1.2.13 ; emmake make install
Unfortunately, the zlib configure
command does not support --disable-pthreads
or --disable-threaded-resolver
. It lists very few, basic options (configure [--const] [--zprefix] [--prefix=PREFIX] [--eprefix=EXPREFIX] [--static] [--64] [--libdir=LIBDIR] [--sharedlibdir=LIBDIR] [--includedir=INCLUDEDIR] [--archs="-arch i386 -arch x86_64"]
).
When we link the required libraries together for the ASM version, we don't link with -lpthread
, but we are still getting Atomics emitted in the JavaScript:
em++ -o libzim-asm.js --bind libzim_bindings.cpp -I/src/build/include -L/src/build/lib -lzim -llzma -lzstd -lxapian -lz -licui18n -licuuc -licudata -O3 --pre-js prejs_file_api.js --post-js postjs_file_api.js -s WASM=0 --memory-init-file 0 -s MIN_EDGE_VERSION=40 -s "EXPORTED_RUNTIME_METHODS=['ALLOC_NORMAL','printErr','ALLOC_STACK','print']" -s INITIAL_MEMORY=83886080 -s ALLOW_MEMORY_GROWTH=1 -lworkerfs.js
Is there a way to disable Atomics? The -s MIN_IE_VERSION=11 or -s MIN_EDGE_VERSION=40 don't make any difference in this regard. Oddly, ZStandard also requires zlib, but we have been able to compile that in a version that worked even with IE11. Is WORKERFS the real problem here?