asterius icon indicating copy to clipboard operation
asterius copied to clipboard

--export-function doesn't appear to work

Open paulyoung opened this issue 4 years ago • 2 comments

Describe the bug --export-function doesn't appear to work.

To Reproduce

  1. Create Example.hs with the following contents:
module Example where

greet :: String -> String
greet x = "Hello, " <> x <> "!"
  1. Run docker run --rm -v $(pwd):/workspace -w /workspace terrorjack/asterius:201203 ahc-link --input-hs Example.hs --no-main --export-function greet

  2. See that exportsStaticOffsets in Example.req.mjs is empty.

  3. I also ran wasm2wat Example.wasm -o Example.wat and couldn't find anything that looked like the greet 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

paulyoung avatar Dec 15 '20 03:12 paulyoung

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:

--export-function ARG

For each foreign export javascript function f 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.

gelisam avatar May 22 '22 03:05 gelisam

That being said, --export-function does not work with ahc-dist. I have filed a separate issue: #902

gelisam avatar May 23 '22 02:05 gelisam