I compiled SWI-Prolog version 9.2.9 for WASM (cloned from git, emcc 4.0.4) and it seems to work fine with Node.js 18.9.0.
I want to be able to compile .qlf files of my projects to turn them into web apps. For that, I wanted to have one swipl locally to generate them, and then use the same version to interpret .qlf’s in a browser.
However, my compiled swipl-bundle.js does not seem to work in the browser. Namely,
swipl = await SWIPL()
gives swipl
without prolog
or consult()
! I tried the same with swipl-bundle.js from the npm package and from the swi-prolog website, and it worked.
Any suggestions what could have happened?
NB: I invoked CMake as
emcmake cmake -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_FIND_ROOT_PATH=~/src/emsdk/wasm-root/ \
-DINSTALL_DOCUMENTATION=OFF \
-DUSE_GMP=OFF \
-G Ninja ..
Maybe I should try the “official” way as in the manual, with pointing the toolchain path. I will also try to build a Debug version.
UPDATE: So, I compiled with -DCMAKE_BUILD_TYPE=Debug and I have now the following errors in the JS console:
Aborted(Attempt to set
Module.onRuntimeInitialized
after it has already been processed. This can happen, for example, when code is injected via ‘–post-js’ rather than ‘–pre-js’)
Unhandled Promise Rejection: RuntimeError: Aborted(Attempt to set
Module.onRuntimeInitialized
after it has already been processed. This can happen, for example, when code is injected via ‘–post-js’ rather than ‘–pre-js’)
This time I run CMake almost as described in the manual, calling
cmake -DCMAKE_TOOLCHAIN_FILE=$TOOLCHAIN \
-DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_FIND_ROOT_PATH=$WASM_ROOT \
-DINSTALL_DOCUMENTATION=OFF \
-DUSE_GMP=OFF \
-G Ninja ..
directly from shell (after calling emsdk_env.sh of course). The main difference with the manual is that it is suggested to put such a command into a script and run it with bash
. Also, I disabled GMP.
I also noticed that for both times I compiled the WASM swipl, I got a warning:
emcc: warning:
main
is defined in the input files, but_main
is not inEXPORTED_FUNCTIONS
. Add it to this list if you wantmain
to run. [-Wunused-main]
when swipl-bundle.js and swipl-bundle-nodata.js were built.