Skip to content

Template Haskell not working with WASM backend

Summary

The GHC wasm backend does not support Template Haskell. I am not sure if this is an issue with GHC itself or just an issue with ghc-wasm-meta; if it's the latter, I will close this issue.

Steps to reproduce

  • Clone source code from Anut-py/ghc-wasm-meta master
    • This fork bumps the cabal version to be compatible with ghc 9.8
    • Run FLAVOUR=9.8 ./setup.sh
  • Clone source code from Anut-py/h-raylib web (github)
    • Run source ~/.ghc-wasm/env
    • Run wasm32-wasi-cabal build basic-window --constraint="h-raylib -detect-platform +platform-web"
      • If it fails to build a dependency, just run the command again

It will fail with the following error message:

<no location info>: error:
    Couldn't find a target code interpreter. Try with -fexternal-interpreter
Error: cabal: Failed to build exe:basic-window from h-raylib-5.1.0.1.

This is because ghc-wasm-meta does not come with an iserv executable. I tried compiling ghc/utils/iserv with wasm32-wasi-ghc, which gave me iserv.wasm. I made a bash script wasm32-wasi-ghc-iserv to run it (see below).

#!/usr/bin/bash

wasmtime /path/to/iserv.wasm $@

However, when I ran it with wasm32-wasi-ghc-iserv 1 0 it outputted iserv.wasm: installHandler: unsupported operation (Operation is not supported), so it seems this is not the solution (I turned on verbose mode and it printed GHC iserv starting (in: {handle: <file descriptor: 0>}; out: {handle: <file descriptor: 1>}) so it is receiving the command line arguments). I also tried echo "hi" | ./wasm32-wasi-ghc-iserv 1 0 and it failed with the message iserv.wasm: fdType: unsupported operation (unknown file type).

Environment

  • GHC version used: wasm32-wasi-ghc-9.8.0.20230927

Optional:

  • Operating System: wsl Ubuntu on Windows 11
  • System Architecture: x86_64
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information