Errors while building polysemy for WASM

I’m trying to compile a project (GitHub - disco-lang/disco: Functional teaching language for use in a discrete mathematics course) to WASM, using haskell-wasm / ghc-wasm-meta · GitLab (GHC 9.10 flavour). Currently, however, compilation fails with this error:

$ wasm32-wasi-cabal build disco:exe:disco-wasm
...
Error: [Cabal-7125]
Failed to build polysemy-1.9.2.0 (which is required by exe:disco-wasm from disco-0.1.6). The failure occurred during the configure step. The exception was:
  /home/brent/.ghc-wasm/.cabal/logs/ghc-9.10.1.20241209/polysemy-1.9.2.0-0b93fd0a5b67d6e748c11008a1c7656674bcd3afd2bf6398a6adf44f221541b2.log: withFile: user error (Error: cabal: '/home/brent/.ghc-wasm/wasm32-wasi-ghc/bin/wasm32-wasi-ghc'
exited with an error:
wasm-ld: error: unable to find library -lHSrts-1.0.2_thr
wasm32-wasi-clang: error: linker command failed with exit code 1 (use -v to
see invocation)
wasm32-wasi-ghc-9.10.1.20241209: `wasm32-wasi-clang' failed in phase `Linker'.
(Exit code: 1)
)

Any ideas on how to get around this? Or is the polysemy dependency a no-go?

The branch where I’m working on this is here: GitHub - disco-lang/disco at web-ui

The immediate problem here is that polysemy uses build-type: Custom for doctests. This is easy to patch out (just change to build-type: Simple.

However, the deeper problem is that you also use polysemy-plugin, and plugins aren’t supported when cross-compiling (see #14335). There might be a way around this via external static plugins, but I am not sure if anyone has successfully used this with the Wasm backend so far. So I don’t think it is possible to make progress here :cry: (without sprinkling type applications to avoid polysemy-plugin).

2 Likes

Thanks! I’ll try and see how painful it will be to sprinkle type applications to avoid polysemy-plugin.

Update: I removed polysemy-plugin and was able to sprinkle enough type applications to get the whole thing to compile! Now I am just back to the regular problem of having no idea what I’m doing when it comes to web stuff.

3 Likes

You can probably do something with the Haskell type system to get better inference in one class of cases where the plugin is needed Inference helper class · Issue #23 · re-xyr/cleff · GitHub (e.g. when there is just one Reader in your effect stack so ask is unambiguous).