GaussianSplats3D icon indicating copy to clipboard operation
GaussianSplats3D copied to clipboard

Modernize emscripten usage ("env" "pthread_self": function import requires a callable)

Open PeterZhizhin opened this issue 7 months ago • 6 comments

If I recompile with a new emscripten compiler version (3.1.64), I get the following error on importing the WebAssembly module:

LinkError: WebAssembly.instantiate(): Import #0 "env" "pthread_self": function import requires a callable
    at 0026ddb4-d116-4418-b697-5ee71eb6c206:157:36
(anonymous) @ 0026ddb4-d116-4418-b697-5ee71eb6c206:157
Promise.then
self.onmessage @ 0026ddb4-d116-4418-b697-5ee71eb6c206:159

The reason for this is that a more recent emscripten (less than ~3 years old) compiler exports additional symbols that we are not defining when calling instantiate.

When compiling as a regular module, emscripten will generate additional JS output file that actually loads all functions:

em++ -std=c++11 sorter.cpp -o sorter.js -s WASM=1 -s USE_PTHREADS=1 -msimd128

This generates the following files:

sorter.js
sorter.wasm

The sorter.js file will actually load the sorter.wasm file into a Module variable. This variable can then be used to access defined C++ functions.

This approach will be more future-proof, since the generated .js file will be different depending on the compiler version.

I'd like to know if something like this was considered. And if it wasn't used, then why.

PeterZhizhin avatar Aug 01 '24 14:08 PeterZhizhin