Installing and using third party packs in WASM swipl

As the title says, I didn’t find a way to install and use a third party pack while using WASM swipl. Can this be done?

You mean a Prolog pack? pack_install/1,2 won’t work. Typically I’d clone the pack as a git submodule of your application and use attach_packs/1,2 to make them available.

1 Like

Thank you @jan. I’m not sure how to use the attach_packs/1,2 family of predicates. I put the pack in static/prolog/packs in my webapp, and am trying to include them with:

:- attach_packs('static/prolog/packs').
:- use_module(library(mavis)).

but this doesn’t work, and pack_attach/1 doesn’t really take a string as an argument, and I’m unsure what the right way of setting this up is.

attach_packs/1 takes a directory name as argument. Is the directory really there in the WASM version? And is mavis below that dir with a file pack.pl and a directory prolog holding mavis.pl?

I’m not sure, here’s how my directory structure looks like:

...
β”œβ”€β”€ src
β”‚   β”œβ”€β”€ app.css
β”‚   β”œβ”€β”€ app.html
β”‚   β”œβ”€β”€ lib
β”‚   β”‚   β”œβ”€β”€ components
β”‚   β”‚       β”œβ”€β”€ ... js specific components ...
β”‚   β”‚   └── index.js
β”‚   └── routes
β”‚       β”œβ”€β”€ +layout.svelte
β”‚       └── +page.svelte
β”œβ”€β”€ static
β”‚   β”œβ”€β”€ favicon.png
β”‚   β”œβ”€β”€ prolog
β”‚   β”‚   β”œβ”€β”€ ... application specific prolog code ...
β”‚   └── prolog_packs
β”‚       └── mavis-0.2.3
β”‚           β”œβ”€β”€ pack.pl
β”‚           β”œβ”€β”€ prolog
β”‚           β”‚   └── mavis.pl
β”‚           β”œβ”€β”€ README.md
β”‚           └── t
β”‚               β”œβ”€β”€ intersection.pl
β”‚               β”œβ”€β”€ predicates.pl
β”‚               └── subtypes.pl
...

I am passing the prolog_packs directory, in different variations, and the command doesn’t error out, but then the command:

:- attach_packs('/prolog_packs').
:- use_module(library(mavis)).

Fails because source_sink library(mavis) does not exist. I suppose the static directory could not be the right place, because that’s for js to find stuff, not prolog, but I installed swipl wasm version from npm, so I’m not sure where else to put the files.

I’m afraid I know very little about web packaging. What matters is what ends up in the WASM file system. Or, do you plan to server the Prolog files from the server?

A good way to package many applications for the wasm version is to use

 swipl qlf compile --include <mainfile.pl>

That should give a stand-alone .qlf file that you can then load from the WASM app. Does require swipl to be the same version as the WASM version you target.

There may be other ways. The docs may help. @jeswr, how do you package?