What is the status of SWI-Prolog ported to WebAssembly

@jan

In a recent discussion with the developers of Discourse (ref) it was suggest that one way to use SWI-Prolog in a Discourse post would be to use SWI-Prolog compiled to WASM.

I gave the demo a quick test but it could not return multiple answers via entering ;.

To avoid an extended period of time building, integrating and testing to see if this would work with our Discourse pages, it is just easier to ask if SWI-Prolog compiled to WASM is known to have problems for practical use within a browser page.

I did see the GitHub RoadMap item and also saw SWI-Prolog ported to WebAssembly.

I tried to compile it recently, but failed because the CMake toolchain description in Emscripten was broken, causing problems running ar (the library archiver). Might be fixed of course.

As is though, SWI-Prolog as WASM is pretty much a demonstrator. It doesn’t have a good working console (AFAIK), is only the basic core system with limited libraries. I guess it can be turned into an alternative for teaching on web applications. The advantage is that you do not need to have a sandbox. That is still a lot of work though. For now (and possibly for a long time) SWISH offers the best integration. See the LPN pages for integrating the SWISH ui in a page. It would be fairly easy to have a button like LPN to open and ```prolog block using SWISH. Just needs injecting a little Javascript into the page.

1 Like

For those wondering what the LPN comment is about see this post which has my latest notes on the concept.

also WASM will have to --disable-mt ?

It is called different in the CMake days, but yes. The WASM version is 32-bit and single threaded. For LPN that is good enough :slight_smile:

It could have multi engine support. That now relies on threads, but this can be untangled.

I’m working on WASM right now, and fyi it does have multithreading support! I’ve actually been wanting it as a backend for Swish, but no reason it couldn’t work on Discourse as well.

(in case anyone is curious, in terms of progress: I currently have a full build working with thread support compiled in, and it is capable of at least generating its own boot.prc. No packages yet, though.)

5 Likes