# WASM updates (Reply 1)

**URL:** <https://swi-prolog.discourse.group/t/wasm-updates-reply-1/6524>\
**Category:** Help!\
**Tags:** wasm\
**Created:** [May 3, 2023, 11:15pm UTC](https://swi-prolog.discourse.group/t/wasm-updates-reply-1/6524 "2023-05-03T23:15:32Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jeswr](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jeswr/32/5469_2.png) [@jeswr](https://swi-prolog.discourse.group/u/jeswr)\
**Post date:** [May 3, 2023, 11:15pm UTC](https://swi-prolog.discourse.group/t/wasm-updates-reply-1/6524/1 "2023-05-03T23:15:32Z")

</div>

@jan - Not sure there is much to do on my end; the CI/CD in place on [GitHub - SWI-Prolog/npm-swipl-wasm: SWI-Prolog WebAssembly build as a NPM package](https://github.com/SWI-Prolog/npm-swipl-wasm) should take care of preparing a new npm release whenever you release your new version of SWI-Prolog.

> For building or running on node this needs a fairly recent version of Node.js. v18.16 works.

Is this necessary? Currently; [we test for Node 16+](https://github.com/SWI-Prolog/npm-swipl-wasm/blob/719a07da0f470bbf6eaa66ae0869f095ac91c7ec/.github/workflows/nodejs.yml#L19) in the npm distribution; and I’d prefer to still support Node 16 until it’s EOL in April 2024 (c.f. [Node v16.13.0 (LTS) | Node.js](https://nodejs.org/en/blog/release/v16.13.0))

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [May 4, 2023, 7:06am UTC](https://swi-prolog.discourse.group/t/wasm-updates-reply-1/6524/2 "2023-05-04T07:06:15Z")

</div>

> [@jeswr](#):
>
> Not sure there is much to do on my end

You get most automatically. I had a quick look at the Dockerfile of the repo. Compared to [Building SWI-Prolog using Emscripten for WebAssembly (WASM)](https://www.swi-prolog.org/build/WebAssembly.md), this is lacking behind a bit. As we discussed, I’d include pcre2 and remove GMP. That gives an images that is only marginally larger, has more functionality and is completely covered by permissive licenses (BSD-2, MIT, a little Apache and some non-standard permissive licenses). Only (notably) rational number arithmetic is slower.

> [@jeswr](#):
>
> Is this necessary?

I don’t know what version, but after updating to 3.1.37 on [dev.swi-prolog.org](http://dev.swi-prolog.org) the build failed because node.js complained about invalid opcodes. That is node.js from Ubuntu 20.04. Forgotten which version. 10? After upgrading to the latest stable, all worked fine again.

---

<div class="post-metadata">

**Author:** ![jeswr](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jeswr/32/5469_2.png) [@jeswr](https://swi-prolog.discourse.group/u/jeswr)\
**Post date:** [May 5, 2023, 10:30am UTC](https://swi-prolog.discourse.group/t/wasm-updates-reply-1/6524/3 "2023-05-05T10:30:02Z")

</div>

@jan - I’m trying to reproduce your all test passed results; some questions:

- Do you have a docker image with all this working; if not
  - What commit of swi-prolog did you test this with?
  - What was your `.emscripten` config?

Currently each attempt I am making at running `ctest [-j 16]` results in a failure on the `swipl:basic` test.

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [May 5, 2023, 11:29am UTC](https://swi-prolog.discourse.group/t/wasm-updates-reply-1/6524/4 "2023-05-05T11:29:59Z")

</div>

> [@jeswr](#):
>
> Do you have a docker image with all this working

No. Local machine. Ubuntu 22.04, Emscripten 3.1.37, Node.js 18.16. Current head of swipl-devel.git.  
I use this configure run:

```prolog
WASM_HOME=$HOME/wasm
source $WASM_HOME/emsdk/emsdk_env.sh
TOOLCHAIN=$EMSDK/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake
[-f $TOOLCHAIN] || echo "Could not find emscripten toolchain"

cmake -DCMAKE_TOOLCHAIN_FILE=$TOOLCHAIN \
          -DCMAKE_BUILD_TYPE=Release \
	  -DCMAKE_FIND_ROOT_PATH=$HOME/wasm \
	  -DUSE_GMP=OFF \
	  -DINSTALL_DOCUMENTATION=OFF \
	  -G Ninja .. $@

```

pcre and zlib installed as [Building SWI-Prolog using Emscripten for WebAssembly (WASM)](https://www.swi-prolog.org/build/WebAssembly.md)

After build, simply ran `ctest -j 16` (16 core desktop). Reproduced on two machines, the [dev.swi-prolog.org](http://dev.swi-prolog.org) server and my local development machine.

On older versions I had crashes due to C-stack overflows (fixed by passing the right link flags) and IEEE float tests failing. Apparently fixed in Emscripten and/or Node.

---

<div class="post-metadata">

**Author:** ![jeswr](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jeswr/32/5469_2.png) [@jeswr](https://swi-prolog.discourse.group/u/jeswr)\
**Post date:** [May 5, 2023, 9:48pm UTC](https://swi-prolog.discourse.group/t/wasm-updates-reply-1/6524/5 "2023-05-05T21:48:55Z")

</div>

Got it working now (c.f. [Feat/ctest passing by jeswr · Pull Request #143 · SWI-Prolog/npm-swipl-wasm · GitHub](https://github.com/SWI-Prolog/npm-swipl-wasm/pull/143)). So will have all of this goodness in swipl-wasm once the next release of SWIPL is made.
