ahc-dist fails during the wasm verification phase
Describe the bug
I am trying to build the magic-wormhole project to web assembly using Asterius. During the ahc-dist phase, it quits at the wasm-validator phase with errors similar to this:
[wasm-validator error in function cryptonitezm0zi26zmH0gw9uA2NzzCmRLvv1i5sC_CryptoziHash_.Lc1pAI] unexpected false: non-final block elements returning a value must be drop()ed (binaryen's autodrop option might help you),
To Reproduce
mkdir test
cd test
# add a cabal.project file with contents:
cat << EOF >> cabal.project
> packages: */*.cabal
EOF
# clone the project and switch to a specific branch.
git clone -b 44.build-with-new-protolude https://github.com/LeastAuthority/haskell-magic-wormhole.git
# get a dependency which is not in the asterius docker image.
cabal unpack protolude-0.3.0
# edit protolude-0.3.0/src/Protolude/Base.hs
# comment out lines 67, 68, 69, 70
# 67 -- #if MIN_VERSION_base(4,9,0)
# 68 -- , gcdInt'
# 69 -- , gcdWord'
# 70 -- #endif
# install some more missing C and build dependencies.
apt update
apt install libsodium-dev pkg-config
# now we are ready to build
cd haskell-magic-wormhole
mkdir tmp
ahc-cabal new-install --keep-going --installdir ./tmp/ --overwrite-policy=always
# after a while, this should result in a file called ./tmp/hocus-pocus
# now, run ahc-dist on it.
ahc-dist --browser --input-exe ./tmp/hocus-pocus
Expected behavior
Was expecting to see a wasm module generated.
Environment
- OS name + version: Debian GNU/Linux 'testing' distribution on x86-64 running asterius docker image from 23rd nov 2020.
- Version of the code:
# ahc-cabal --version
cabal-install version 3.2.0.0
compiled using version 3.2.0.0 of the Cabal library
## ahc-dist does not seem to have a version flag.
# ahc-dist --version
ahc-dist: ["unrecognized option `--version'\n"]
CallStack (from HasCallStack):
error, called at src/Asterius/Main.hs:61:8 in asterius-0.0.1-3gh8F3pdM9v8r5FsyTA7Q:Asterius.Main
# ahc --version
The Glorious Glasgow Haskell Compilation System, version 8.8.4
**Additional context**
None
I'm getting a similar bunch of errors while trying to build a source file that includes a large library that is pre-built in the asterius docker image. I am building a source file that is available in the hledger source code tree and it utilizes the hledger-lib library which is prebuilt.
I can reproduce this issue, from the asterius docker shell using these two lines:
git clone https://github.com/simonmichael/hledger.git && cd hledger && git checkout 1.18-branch && cd bin
ahc-link --input-hs hledger-check.hs --run
Here is the beginning of the output, although it continues on to give many more of the same error about "unexpected false":
[INFO] Compiling hledger-check.hs to WebAssembly [1 of 1] Compiling Main ( hledger-check.hs, hledger-check.o ) Linking /tmp/hledger-check391-0 ... [INFO] Converting linked IR to binaryen IR [INFO] Running binaryen optimization [INFO] Validating binaryen IR [wasm-validator error in function regexzmtdfazm1zi3zi1zi0zm16m11FfqhKd3wPZZTDHF5Vzz_TextziRegexziTDFAziNewDFAziEngine_.Lc5m7A] unexpected false: non-final block elements returning a value must be drop()ed (binaryen's autodrop option might help you), on ................. [many lines of output]
Any thoughts on anything I could try to further diagnose this? This error definitely comes from the binaryen project (I found it in their source code) but I wouldn't know whether this is a false positive error or whether there is truly an issue with asterius.
EDIT: Sorry for the noise, the error vanished because I passed --no-validation to ahc-dist (I've overseen that flag) and Cloudflare didn't accept the bundle. So the below doesn't hold and you can count me in on this issue. :/
I haven't looked into the provided repositories. I stumbled over this issue as well and it took me a while to find the problem – I forgot to set
ghc-options: -optl--export-function=handleFetch
in the cabal file. You might want to check that.
(I found this here: https://blog.cloudflare.com/cloudflare-worker-with-webassembly-and-haskell/ not sure if it's documented somewhere else.)