WASM: Compilation error when using Template Haskell with WASM backend
Summary
Dear Maintainers,
I'm trying to compile ShellCheck and eventually Hadolint using GHC with the WASM backend. So far I've been making good progress with minor fixes one or the other library, but ShellCheck uses Template Haskell, which doesn't seem it can be compiled with GHC with the WASM backend.
│ ~/repos/shellcheck │► cabal --with-compiler=wasm32-wasi-ghc --with-ghc-pkg=wasm32-wasi-ghc-pkg --with-hsc2hs=wasm32-wasi-hsc2hs build .
Build profile: -w ghc-9.7.20230326 -O1
In order, the following will be built (use -v for more details):
- ShellCheck-0.9.0 (lib) (first run)
- ShellCheck-0.9.0 (exe:shellcheck) (first run)
Preprocessing library for ShellCheck-0.9.0..
Building library for ShellCheck-0.9.0..
[ 6 of 28] Compiling ShellCheck.Fixer ( src/ShellCheck/Fixer.hs, /home/moritz/repos/shellcheck/dist-newstyle/build/wasm32-wasi/ghc-9.7.20230326/ShellCheck-0.9.0/build/ShellCheck/Fixer.o )
<no location info>: error:
Couldn't find a target code interpreter. Try with -fexternal-interpreter
[16 of 28] Compiling ShellCheck.ASTLib ( src/ShellCheck/ASTLib.hs, /home/moritz/repos/shellcheck/dist-newstyle/build/wasm32-wasi/ghc-9.7.20230326/ShellCheck-0.9.0/build/ShellCheck/ASTLib.o )
<no location info>: error:
Couldn't find a target code interpreter. Try with -fexternal-interpreter
Error: cabal: Failed to build ShellCheck-0.9.0 (which is required by
exe:shellcheck from ShellCheck-0.9.0).
Although, I found here why it suggests to use -fexternal-interpreter
, the flag does not help, because the WASM backend does not provide that external interpreter:
Building library for ShellCheck-0.9.0..
[ 6 of 28] Compiling ShellCheck.Fixer ( src/ShellCheck/Fixer.hs, /home/moritz/repos/shellcheck/dist-newstyle/build/wasm32-wasi/ghc-9.7.20230326/ShellCheck-0.9.0/build/ShellCheck/Fixer.o )
<no location info>: error:
/home/moritz/.ghc-wasm/wasm32-wasi-ghc/lib64/wasm32-wasi-ghc-9.7.20230326/lib/bin/ghc-iserv: createProcess: posix_spawnp: does not exist (No such file or directory)
[16 of 28] Compiling ShellCheck.ASTLib ( src/ShellCheck/ASTLib.hs, /home/moritz/repos/shellcheck/dist-newstyle/build/wasm32-wasi/ghc-9.7.20230326/ShellCheck-0.9.0/build/ShellCheck/ASTLib.o )
<no location info>: error:
/home/moritz/.ghc-wasm/wasm32-wasi-ghc/lib64/wasm32-wasi-ghc-9.7.20230326/lib/bin/ghc-iserv: createProcess: posix_spawnp: does not exist (No such file or directory)
Error: cabal: Failed to build ShellCheck-0.9.0 (which is required by
exe:shellcheck from ShellCheck-0.9.0).
I found no instructions detailing the special case of Template Haskell with the WASM backend and I'm not sure it's even possible at this point.
Proposed improvements or changes
Document how to use Template Haskell with the WASM backend.
Environment
- GHC version used (if appropriate):
│ ~/repos/shellcheck │► wasm32-wasi-ghc --version
The Glorious Glasgow Haskell Compilation System, version 9.7.20230326
│ ~/repos/shellcheck │► uname -a
Linux GLaDOS.fritz.box 5.14.21-150400.19-default #1 SMP PREEMPT_DYNAMIC Wed Apr 20 08:32:52 UTC 2022 (d6fb753) x86_64 x86_64 x86_64 GNU/Linux