tweag / asterius

DEPRECATED in favor of ghc wasm backend, see https://www.tweag.io/blog/2022-11-22-wasm-backend-merged-in-ghc
1.98k stars 55 forks source link

--export-function doesn't work with ahc-dist #902

Open gelisam opened 2 years ago

gelisam commented 2 years ago

Describe the bug When using foreign export javascript to export a Haskell function, the function appears in __asterius_jsffi.exports if the code is compiled with ahc-link, but not if it is compiled with ahc-dist.

To Reproduce

I wrote a short program which exports mult_hs and then checks if __asterius_jsffi.exports.mult_hs exists:

$ cat Example.hs
{-# LANGUAGE ForeignFunctionInterface #-}

foreign export javascript "mult_hs" (*) :: Int -> Int -> Int

foreign import javascript "console.log(__asterius_jsffi.exports.mult_hs)" js_print_exports :: IO ()

main :: IO ()
main = js_print_exports

$ cat example.cabal
cabal-version:      2.4
name:               example
version:            0.1.0.0

executable example-exe
    main-is:          Example.hs
    build-depends:    base
    hs-source-dirs:   .

Inside the asterius image, I then compile and run that code using ahc-link and ahc-dist, and get two different results:

# ahc-link --input-hs Example.hs --export-function mult_hs --run
[...]
[AsyncFunction: cb]

# ahc-cabal new-install --installdir=. example-exe
[...]
Symlinking 'example-exe' to './example-exe'
# ahc-dist --input-exe example-exe --export-function js_greet --run
[...]
undefined

Expected behavior

I expected the ahc-dist command to produce [AsyncFunction: cb] as well.

Environment

freedomhero commented 2 years ago

Any updates? Stuck on the same problem here.

xhliu commented 2 years ago

Same here.