asterius
asterius copied to clipboard
--export-function doesn't appear to work
Describe the bug
--export-function
doesn't appear to work.
To Reproduce
- Create
Example.hs
with the following contents:
module Example where
greet :: String -> String
greet x = "Hello, " <> x <> "!"
-
Run
docker run --rm -v $(pwd):/workspace -w /workspace terrorjack/asterius:201203 ahc-link --input-hs Example.hs --no-main --export-function greet
-
See that
exportsStaticOffsets
inExample.req.mjs
is empty. -
I also ran
wasm2wat Example.wasm -o Example.wat
and couldn't find anything that looked like thegreet
function.
Expected behavior
Example.wasm
contains the greet function.
Environment
- OS name + version: macOS Catalina 10.15.7
- Version of the code:
terrorjack/asterius:201203
Additional context I based my expectations on the info here: https://asterius.netlify.app/ahc-link.html
I based my expectations on the info here: https://asterius.netlify.app/ahc-link.html
Perhaps the documentation was changed since this issue was filed, but that URL currently states:
For each
foreign export javascript
functionf
that will be called, a--export-function=f
link-time flag is mandatory.
Let's thus fix the code by adding the missing foreign export javascript
declaration (and fixing the type to one which can be exported):
module Example where
import Asterius.Types
foreign export javascript "js_greet" js_greet :: JSString -> JSString
js_greet :: JSString -> JSString
js_greet = toJSString . greet . fromJSString
greet :: String -> String
greet x = "Hello, " <> x <> "!"
and now running podman run --rm -v $(pwd):/workspace --privileged -w /workspace terrorjack/asterius:210111 ahc-link --input-hs Example.hs --no-main --export-function js_greet
does result in an Example.req.mjs
file whose exportsStaticOffsets
contains js_greet
.
That being said, --export-function
does not work with ahc-dist
. I have filed a separate issue: #902